firebase-authentication - 我的 firebase 用户对象似乎不正确
问题描述
我是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() 方法返回的用户对象内还有另一个用户对象。
提前致谢。
解决方案
createUserWithEmailAndPassword
返回一个用 aUserCredential
而不是 User 解析的 Promise。
此更改是在v5.0.0中进行的
推荐阅读
- android - 如何在支持 unicode 的 Android 中创建 PDF
- asp.net - 从另一个动作重定向到一个动作
- php - 请任何人都可以解释这个代码,我正在处理发送 php 代码的电子邮件,我在 GitHub 上找到了这个代码?
- mysql - MySQL服务器的一般日志在插入表后显示一条记录“查询回滚”,但记录仍在表中
- php - 未定义的偏移量:1 使用复选框
- spring - 在 Spring Boot 中为 REST API 使用 Jersey 而不是 Spring MVC 有什么好处?
- linux - 如何在 Redhat 上根据磁盘名称区分闪存盘
- ubuntu - snap-installed slack 在 xfce 面板中不显示图标
- javascript - 如何在javascript中将元素从一个数组复制到另一个数组?
- swift4 - 如何在swift 4中用所有大写字母分隔单词