firebase createUserWitheMailandPassword displayName返回null
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新用户配置文件是一个异步操作,并且不会自动刷新应用程序中的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.