Home » vue » Convert anonymous user with Firebase: Cannot read property 'getAuthResponse' of undefined

Convert anonymous user with Firebase: Cannot read property 'getAuthResponse' of undefined

Posted by: admin November 26, 2021 Leave a comment

Questions:

I’m using VueJS and Firebase Auth (NPM – Version 5.6.0). I need to convert an anonymous user into an registered user with Google as a provider. I tried the recently updated sample from the Firebase docs:

        anonymousToGoogle: function () {
      var googleUser
      var provider
      var credential = firebase.auth.GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token)
      firebase.auth.currentUser.linkWithRedirect(provider)
      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)
      })
    }
  }

Button (uses the VuetifyJS framework):

<v-btn block @click="anonymousToGoogle()">CONVERT - Login with Google</v-btn>

The console shows this error after clicking the button:

[Vue warn]: Error in event handler for “click”: “TypeError: Cannot
read property ‘getAuthResponse’ of undefined”

Answers: