javascript - DId firebase createUserWithEmailAndPassword() 是否更改了返回值?
问题描述
我已经使用这个代码一年了:
firebase.auth().createUserWithEmailAndPassword(textUser, textPassword)
.then(function(user){
console.log('uid',user.uid)
//Here if you want you can sign in the user
}).catch(function(error) {
//Handle error
});
但是,过去 2 天我抱怨新用户在创建新登录时遇到问题。我检查了这段代码中的“用户”变量,它看起来像这样:
{
additionalUserInfo: {
providerId: "password",
isNewUser: true
},
credential: null,
operationalType:"signIn"
user: {
(bunch of fields...)
uid: "xxxxx123456789",
(bunch of fileds...)
}
}
这意味着我现在必须使用 user.user.uid 而不是 user.uid 来引用 uid。我做了这个更改并且代码可以工作,但是我还有这个函数的其他几个用途,我想知道这是否是一个实际的更改,或者我是否看到了一些不寻常的东西。我已经很久没有更改过这段代码了,所以无论如何我都很惊讶。欣赏任何见解。
解决方案
是的,它改变了许多方法,在我身边也崩溃了。但我必须重构所有这些。它返回一个UserCredential
包含user
和其他对象的类型。
UserCredential: {
additionalUserInfo: { isNewUser: boolean, profile: Object, providerId: string, username: string },
credential: {accessToken: string, idToken: string, providerId: string, signInMethod: string},
operationType: string,
user: Object
}
这是我重构的示例代码,它也崩溃了signInWithPopup()
方法。
firebase
.auth()
.signInWithPopup(provider)
.then(authResult => {
console.log({ authResult });
if (authResult.user) {
this.doLogin(authResult.user);
}
});
不幸的是,重构代码只是问题的解决方案。另请查看此链接以获取 about createUserWithEmailAndPassword()
。
推荐阅读
- python - 使用 python (pandas?) 对新数据进行重复排序
- php - 喜欢和不喜欢系统数据库和查询问题?
- javascript - 在我的网页上在小屏幕上运行另一个 .html 页面
- python - 更改 Pandas 中列的值
- php - Imagemagick 从 6.9 升级到 7 后反转颜色
- hive - 如何向这个 hive 命令添加一个表?
- module - 有没有办法获取包含在 fortran .mod 文件中的符号?
- python - 如果/那么熊猫条件
- javascript - LWC 中未定义的变量值 - JavaScript
- javascript - 如何在功能组件中使用 React Typescript 键入任何参数