使用Angularfire2更新用户个人资料

时间:2018-08-31 20:39:58

标签: angular firebase-authentication angularfire2

我是Angular和学习的新手:)

更新用户个人资料时,它会保存个人资料更改,然后我在signOut上收到错误消息,想知道是否有人知道什么可能触发此操作,请参见下面的代码...

ERROR TypeError: Cannot read property 'updateProfile' of null
    at SafeSubscriber._next (auth.service.ts:66)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:207)
    at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:145)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:80)
    at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:55)
    at angularfire2.js:49
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388)
    at Object.onInvoke (core.js:3824)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:387)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:138)

我要更新的代码...

updateUserProfile() {
  this.store.dispatch(new AuthActions.SetIsPending(true));

  this.store
    .pipe(select(fromRoot.getAuthenticatedUserInformation))
.pipe(take(1)) <-- added this
    .subscribe(user => {
      this.fireauth.authState
.pipe(take(1)) <-- added this
      .subscribe(profile => {
        profile
          .updateProfile({
            displayName: user.displayName,
            photoURL: user.photoURL
          })
          .then(() => {
            this.store.dispatch(new AuthActions.SetIsPending(false));
          })
          .catch(error => {
            this.store.dispatch(new AuthActions.SetIsPending(false));
            console.log(error.message);
          });
      });
    });
}

0 个答案:

没有答案