gpt4 book ai didi

javascript - 如何将匿名帐户转换为永久帐户

转载 作者:行者123 更新时间:2023-12-03 01:20:30 25 4
gpt4 key购买 nike

有人可以帮助我如何将匿名帐户 (signInAnonymouslyAndRetrieveData) 转换为永久帐户吗?我已经尝试过:

firebase.auth().currentUser.linkAndRetrieveDataWithCredential(credential).then(function(usercred) {
var user = usercred.user;
console.log("Anonymous account successfully upgraded", user);
}, function(error) {
console.log("Error upgrading anonymous account", error);
});

但我得到了

cannot read property "linkAndRetrieveDataWithCredential" of null

错误。

最佳答案

如果当前没有登录用户,

firebase.auth().currentUser 将为 null。

确保您的匿名用户仍处于登录状态,如上面的示例所示,然后您可以使用 linkAndRetrieveDataWithCredential 升级您的用户

const credential = firebase.auth.EmailAuthProvider.credential(email, password);
const currentUser = firebase.auth().currentUser;

if (currentUser) {
currentUser.linkAndRetrieveDataWithCredential(credential).then((userCredential) => {
const user = userCredential.user;
console.log("Account linking success", user);
}, (error) => {
console.log("Account linking error", error);
});
}

引用文献:

关于javascript - 如何将匿名帐户转换为永久帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51785422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com