简体   繁体   English

Angular Auth0 - 如果经过身份验证,则获取 email 声明

[英]Angular Auth0 - get email claim if authenticated

I want to get email claim, if user is already logged in.如果用户已经登录,我想获得 email 声明。

this.auth.idTokenClaims$.forEach(e => console.log(">>>>>>>>>>>>>"+e.email));

is printing email正在打印 email

I want to write something like this ( because e can be null)我想写这样的东西(因为 e 可以为空)

if((this.auth.isAuthenticated$ | async) === false){
      this.auth.idTokenClaims$.forEach(e => {
      this.cService.dash(e.email).subscribe(
        data => { this.yeah = data},
        err => console.error(err),
        () => console.log('Main Content ')

      )}
      );
   } else {

    this.cService.dash(null).subscribe(
      data => { this.yeah = data},
      err => console.error(err),
      () => console.log('Main Content from else '));
   }

Problem: if((this.auth.isAuthenticated$ | async) === false){问题:if((this.auth.isAuthenticated$ | async) === false){

It says always evaluates to false, because它说总是评估为假,因为

This condition will always return 'false' since the types 'number' and 'boolean' have no overlap.ts(2367)此条件将始终返回 'false',因为类型 'number' 和 'boolean' 没有重叠。ts(2367)

or或者

The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362)算术运算的左侧必须是“any”、“number”、“bigint”或枚举类型。ts(2362)

something on these lines这些线上的东西

Please can anyone help me resolve this请问谁能帮我解决这个问题

if isAuthenticated$ is an Observable or any kind of Subject I would try to structure the 2 streams into a pipe and do something like如果isAuthenticated$Observable或任何类型的Subject ,我会尝试将 2 个流结构化为pipe并执行类似的操作

this.auth.isAuthenticated$.pipe(
  skipWhile( isAuthenticated => isAuthenticated),
  switchMap( () => this.auth.idTokenClaims$ ),
  ...
).subscribe()

this.auth.isAuthenticated$.pipe(
  skipWhile( isAuthenticated => !isAuthenticated),
  switchMap( () => this.cService.dash(null) ),
  ...
).subscribe()

my main point here is that if you could give the types of each of the problematic variables, also $ sign at the end mostly stands for a Subject or Observable so I don't really understand what forEach has to do without subscription我的主要观点是,如果您可以给出每个有问题的变量的类型,那么最后的$符号也主要代表SubjectObservable所以我真的不明白如果没有订阅,forEach 必须做什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM