有人可以帮助我如何将匿名帐户(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);
});
但是我得到
无法读取null的属性“ linkAndRetrieveDataWithCredential”
错误。
答案 0 :(得分:1)
firebase.auth().currentUser
将为空。
请确保您的匿名用户仍处于登录状态,然后如上例所示,然后可以使用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);
});
}
参考文献: