我的Firebase用户对象似乎不正确

时间:2019-06-24 16:22:11

标签: firebase-authentication

我是Firebase的新手。

我正在尝试使用Firebase身份验证创建注册组件,但是从firebase.auth()。createUserWithEmailAndPassword返回的用户对象似乎不正确。

官方文档说我可以通过调用user.uid来获取uid,但在我的情况下,它返回null。相反,我可以通过调用user.user.uid来获取uid。 我很困惑。

我看到的文档是否过时?还是我做错了什么?

详细代码如下。请看看并给我一些建议。

const promise=firebase.auth.createUserWithEmailAndPassword(email, password);
promise
.then((user) => {
 console.log(user);
 console.log(user.id); //returns null
 console.log(user.user.uid); //returns O6hLcfJL5NT4fV2S7JprQ3MhjCK2, which I assumes to be uid.
})
.catch((e) => {
 console.log(e.message);
})

以下是console.log(user)的结果。

{user: P, credential: null, additionalUserInfo: Wf, operationType: "signIn"}
 additionalUserInfo: Wf {providerId: "password", isNewUser: true}
 credential: null
 operationType: "signIn"
 user: P {G: Array(0), l: "AIzaSyDIj8N9kONUkpOdMGuApNcKkaeFYYEzfyk", o: "[DEFAULT]", u: "bluegenie-2ba45.firebaseapp.com", c: bi, …}
 __proto__: Object

如您所见,用户对象中还有另一个用户对象,该对象是我从createUserWithEmailAndPassword()方法返回的。

谢谢。

1 个答案:

答案 0 :(得分:0)

createUserWithEmailAndPassword返回一个以UserCredential而不是用户来解决的承诺。

此更改是在v5.0.0

中进行的