Angular Auth0 - 如果经过身份验证,则获取电子邮件声明

时间:2021-03-28 18:01:06

标签: angular auth0

如果用户已经登录,我想收到电子邮件声明。

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

正在打印电子邮件

我想写这样的东西(因为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 '));
   }

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

它说总是评估为假,因为

<块引用>

此条件将始终返回 'false',因为类型 'number' 和 'boolean' 没有重叠。ts(2367)

<块引用>

算术运算的左侧必须是“any”类型, 'number'、'bigint' 或枚举类型.ts(2362)

这些方面的东西

请谁能帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

如果 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()

我的主要观点是,如果您可以给出每个有问题的变量的类型,那么末尾的 $ 符号主要代表 SubjectObservable 所以我不真的不明白 forEach 在没有订阅的情况下必须做什么