我正尝试在firebase中注册用户,一旦注册该用户,我想将其添加到firestore数据库中,但无法访问刚刚注册的用户的uid。
registerUser(name: string, email: string, password: string): Promise<any> {
return this.afAuth.auth.createUserWithEmailAndPassword(email, password).then((newUser:any) => {
console.log(newUser.uid)
});
}
newUser.uid未定义,如何访问此值?
谢谢
答案 0 :(得分:2)
根据此处的文档-https://firebase.google.com/docs/reference/js/firebase.auth.Auth#createUserWithEmailAndPassword
该函数返回“返回firebase。包含非空firebase.auth.UserCredential的承诺”
console.log(newUser.user.uid)