要通过电子邮件和密码将匿名用户链接到新创建的用户,请使用以下功能linkAndRetrieveDataWithCredential
由于某种原因,我收到以下错误:
__WEBPACK_IMPORTED_MODULE_12_firebase_app___default.a.auth(...).currentUser.linkAndRetrieveDataWithCredential is not a function
此功能已在Firebase官方文档中介绍了有关如何链接匿名用户的信息。 https://firebase.google.com/docs/auth/web/anonymous-auth
背景:我使用React.js,因此通过NPM安装Firebase。
我在做什么错了?
我的代码:
//if the user is anonymous, then upgrade the anonymous user to be the email&pass user.
//get the Credential object
var credential = firebase.auth.EmailAuthProvider.credential(this.state.email, this.state.password);
//get the Credential object
firebase.auth().currentUser.linkAndRetrieveDataWithCredential(credential).then(function(usercred) {
var user = usercred.user;
console.log("Anonymous account successfully upgraded", user);
//the user was created. redirect to Home page
window.location.assign("/");
答案 0 :(得分:1)
显然,该功能已被弃用。
正确的解决方案在此处记录: Firebase Convert Anonymous User Account to Permanent Account Error
// (Anonymous user is signed in at that point.)
// 1. Create the email and password credential, to upgrade the
// anonymous user.
var credential = firebase.auth.EmailAuthProvider.credential(email, password);
// 2. Links the credential to the currently signed in user
// (the anonymous user).
firebase.auth().currentUser.linkWithCredential(credential).then(function(user) {
console.log("Anonymous account successfully upgraded", user);
}, function(error) {
console.log("Error upgrading anonymous account", error);
});