javascript - Firebase 身份验证 - 链接其他身份验证提供程序
问题描述
我正在使用 web 中的 firebase 身份验证并遇到问题。我使用谷歌登录了一个用户,现在我还希望用户创建一个密码,以便他可以使用电子邮件和密码登录。所以基本上我想把他们两个联系起来。
我尝试了 firebase.auth.createUserWithEmailAndPassword(userEmail, newpassword) 但它抛出一个错误“email-already-in-use”这是正确的,因为我先用谷歌登录。
有什么办法可以链接这些吗?
解决方案
这是一个如何将电子邮件/密码凭据链接到现有用户的示例(请注意,您也可以只是 user updatePassword
)
// Email/Password credential. Similar logic can be used for linking
// other credentials.
var cred = firebase.auth.EmailAuthProvider.credential(
firebase.auth().currentUser.email, 'password');
firebase.auth().currentUser.linkWithCredential(cred)
.then(function() {
// Credential successfully linked.
})
.catch(function(error) {
// Some error occurred.
});
推荐阅读
- python - 好奇 numpy.linspace 的形状
- javascript - 带有全局变量后备的 Typescript UMD
- reactjs - google firebase cli 列出现有项目失败
- java - RecyclerView 水平项目没有对齐
- javascript - d3.timeWeek ,一周的第一天
- multilingual - Angular-Nodejs 中的多语言
- powerbi - 如何查看 PBIX 文件的内容
- javascript - 引诱报告:index.html 在 Firefox 和 chrome 中均未显示任何内容
- html - 悬停效果在 PC 上运行代码时有效,但在将其上传到服务器并查看网站悬停效果后不起作用
- javascript - 下一个 js:TypeError:无法读取未定义的属性“地图”