Firebase Angular无法读取属性' uid'对signOut()的null

时间:2018-03-03 00:01:17

标签: angular firebase-authentication

每次用户登录时,他们都会收到控制台错误错误:未捕获(在承诺中):TypeError:无法读取属性' uid'为null TypeError:无法读取属性' uid'为null

每次用户注销时,都会收到错误消息 TypeError:无法读取属性' uid'为null。谁看过这个吗?代码如下:

logout() {
    this.afAuth.auth.signOut().then(() => {
      this.router.navigate(['/']);
    });
  }

  //// Email/Password Auth ////
  emailLogin(email: string, password: string) {
    return this.afAuth.auth.signInWithEmailAndPassword(email, password)
      .then((user) => {
        // alert('Welcome to Firestarter!!!');
      })
      .catch((error) => this.handleError(error));
  }

    ////  Get auth data, then get firestore users data
    this.user$ = this.afAuth.authState
      .do(user => this.userUid = user.uid)
      .switchMap((user) => {
        if (user) {
          return this.afs.doc<User>(`users/${user.uid}`).valueChanges();
        } else {
          return Observable.of(null);
        }
      });

0 个答案:

没有答案