【问题标题】:Angular Firebase "Error: Reference.update failed: First argument contains undefined in property 'users.UID.email' "Angular Firebase“错误:Reference.update 失败:第一个参数在属性'users.UID.email'中包含未定义”
【发布时间】:2021-02-12 13:08:11
【问题描述】:

我是新的 firebase 数据库,我尝试在注册时将 UID 更新为实时数据库,但出现这样的错误

错误:Reference.update 失败:第一个参数在属性“users.UID.email”中包含未定义

auth.service.ts

import ...
...
export class AuthService { 
...

 async emailSignUp(email: string, password: string) {
    try {
      const user = await this.afAuth.auth.createUserWithEmailAndPassword(email, password);
      console.log('user ', user);
      this.authState = user;
      console.log('authState ', this.authState);
      this.updateUserData();
      this.router.navigate(['/']);
    } catch (error) {
      return console.log(error);
    }
  }

 get currentUserId(): string {
    console.log('currentId ', this.authenticated, ' ', this.authState.user.uid);
    return this.authenticated ? this.authState.user.uid : '';
  }

 private updateUserData(): void {
    const path = `users/${this.currentUserId}`; // Endpoint on firebase
    const userRef: AngularFireObject<any> = this.db.object(path);
    const data = {
      email: this.authState.email,
      name: this.authState.displayName
    };
    userRef.update(data)
      .catch(error => console.log(error));
  }

}

控制台

有人可以帮帮我吗? 如果需要更多的 sn-ps,请告诉我。提前致谢。

【问题讨论】:

    标签: angular typescript firebase firebase-realtime-database


    【解决方案1】:

    错误告诉您this.authState.email 未定义。将未定义的值传递给实时数据库是无效的。在以这种方式使用之前,您应该检查一下。

    我看到您在构造函数中从user 分配了this.authState。您在控制台中记录了user,它没有名为email 的属性,所以这个错误一点也不让我感到惊讶。但它确实有一个也称为user 的属性。所以,也许你的意思是this.authState.user.email

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-03
      • 1970-01-01
      • 2018-08-18
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 2015-11-06
      • 2020-02-27
      相关资源
      最近更新 更多