I've been trying to convert an anonymous account to a permanent google account following the instructions on the firebase docs (https://firebase.google.com/docs/auth/web/anonymous-auth#google-sign-in)
It shows the following snippet of code:
import { GoogleAuthProvider } from "firebase/auth";
const credential = GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
However, the snippet of code provided displays a variable called "googleUser" which has the method googleUser.getAuthResponse().id_token
I do not know where this variable comes from and how to get it. I've looked around the docs and internet for hours and had no luck.
I'm currently using linkWithPopup
to do the job, however, if the google user that I'm trying to link the anonymous account to already exists on the app it just fails.
you should use the method linkWithPopup for that. here is an example:
import {
getAuth,
linkWithPopup,
GoogleAuthProvider,
} from 'firebase/auth'
export function linkWithGoogleAccount() {
var anonymousUser = getAuth().currentUser
// Authenticate with a second method and get a credential
var provider = new GoogleAuthProvider()
if (anonUser)
return linkWithPopup(anonymousUser, provider)
else return null
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With