简体   繁体   中英

How to convert an anonymous account to a permanent account

can someone help me how to convert an anonymous account (signInAnonymouslyAndRetrieveData) to a permanent account ? I have tried this:

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);
});

but i'm getting an

cannot read property "linkAndRetrieveDataWithCredential" of null

error.

firebase.auth().currentUser will be null if there's no currently signed in user.

Ensure your anonymous user is still signed in then as in your example above you can then upgrade your user using 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); }); } 

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM