firebase createUserWitheMailandPassword displayName返回null

发布于 2025-02-13 22:18:08 字数 950 浏览 0 评论 0原文

我正在尝试使用Firebase Auth创建一个新用户和密码。但是,当我尝试访问displayName并从返回的async调用中,我将获得一个空值(在更新Profile函数之前)。为了解决它,我正在以displayName功能中传递用户名。我还试图在集合用户中创建一个新文档。为了访问我必须拥有的所有字段。这是我的代码,我在做什么错?

async signUp(email: string, password: string, username: string, phoneNumber: string){
    await this.afAuth.createUserWithEmailAndPassword(email, password)
      .then((result) => {
        this.router.navigate(['/home'])
        return result.user?.updateProfile({
          displayName: username
        })
          .then( () => {
            this.afs.collection("users").doc(result.user?.uid).set({
              uid: result.user?.uid,
              displayName: result.user?.displayName,
              phoneNumber: phoneNumber,
              photoURL: result.user?.photoURL,
              providerId: result.user?.providerId,
            })
        })
      })
      .catch((error) => {
        window.alert(error.message);
      })
  }

I am trying to create a new user with email and password using firebase auth. However, when I try to access the displayName and from the returned async call I get a null value (before updateProfile function). To get a way around it, I am passing in the username in the function which is the displayName. I am also trying to create a new document inside the collection users. In order to have access to all the fields I had to have .then after the updateProfile function which I feel is not the right way of doing. Here is my code, what am I doing wrong?

async signUp(email: string, password: string, username: string, phoneNumber: string){
    await this.afAuth.createUserWithEmailAndPassword(email, password)
      .then((result) => {
        this.router.navigate(['/home'])
        return result.user?.updateProfile({
          displayName: username
        })
          .then( () => {
            this.afs.collection("users").doc(result.user?.uid).set({
              uid: result.user?.uid,
              displayName: result.user?.displayName,
              phoneNumber: phoneNumber,
              photoURL: result.user?.photoURL,
              providerId: result.user?.providerId,
            })
        })
      })
      .catch((error) => {
        window.alert(error.message);
      })
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这样的小城市 2025-02-20 22:18:09

更新用户配置文件是一个异步操作,并且不会自动刷新应用程序中的firebase身份验证用户配置文件。 displayName用户配置文件的属性将在您要么迫使它刷新,直到最多一个小时过去,或直到用户再次签名为止。

Updating the user profile is an asynchronous operation and does not automatically refresh the Firebase Authentication user profile in your app. The displayName property of the user profile won't be set until you either force it to refresh, until up to an hour has passed, or until the user signs in again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文