Search code examples
firebasepolymerfirebase-authentication

Merge anonymous account to email and password account in firebase with polymer


I am creating a web app with polymer and firebase, and I want be able to merge anonymously logged in accounts to be able to merge to an email and password account.

I found the official documentation on how to achieve this https://firebase.google.com/docs/auth/web/anonymous-auth , but when I try it out, it does not work.

Documentation provides the code sample

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

I am confused at this point since this "auth" variable popped out of no where.

I have tried substituting the user property of my element

<firebase-auth 
  id="auth"
  user="{{user}}"
  on-error="handleError">
</firebase-auth>

, but it gave me the following error:

Uncaught TypeError: this.user.link is not a function

What variable am I supposed to have for the "auth" in this example? Or, how can I merge anonymous account to an email and password account using polymerfire?


Solution

  • Okay, I figured it out.

    Turns out that the "link" method is deprecated and instead, we have to use "linkWithCredential", so the code would be

    this.$.auth.auth.currentUser.linkWithCredential(credential).then(function(user) {
      console.log("Anonymous account successfully upgraded", user);
    }, function(error) {
      console.log("Error upgrading anonymous account", error);
    });