snippets-web icon indicating copy to clipboard operation
snippets-web copied to clipboard

Where does the "googleUser" variable come from? How do i get it?

Open heloineto opened this issue 2 years ago • 9 comments

Where does the "googleUser" variable come from? How do i get it?

https://github.com/firebase/snippets-web/blob/509769a817d7437616bcfcb816f783b29aaca843/snippets/auth-next/index/auth_make_google_credential.js#L8-L11

The snippet of code mentions a variable called "googleUser" which has 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.

This is my first issue on GitHub, I'm sorry if I'm doing it wrong.

heloineto avatar Mar 10 '22 20:03 heloineto

Any updates?

cesarhilario avatar Jun 28 '22 05:06 cesarhilario

Hey! I found that snippet on "Convert an anonymous account to a permanent account". I don't know why, but the snippets on that specific page are not that great.

If you are looking into linking an anonymous account to a permanent account, it's a lot easier than you might expect. Remember that login anonymously is an Auth Provider, so you can just follow the guides located in "Link Multiple Auth Providers to an Account Using JavaScript". In my testing, you can use linkWithPopup and linkWithRedirect without any problem.

Now, speaking of the actual question: "Where does the "googleUser" variable come from?", I have no idea. But this issue can guide you: https://stackoverflow.com/questions/34804016/googleuser-getauthresponse-doesnt-contain-access-token As far as I saw, apparently, the googleUser variable is not related to the Firebase SDK at all.

Hope this helps.

itaquito avatar Jul 27 '22 19:07 itaquito

Just realised this is a duplicate of #256

itaquito avatar Jul 27 '22 19:07 itaquito

In my testing, you can use linkWithPopup and linkWithRedirect without any problem.

I'm currently using them on my app.

However, there's a bug on my app and I need the variable to be able to solve it.

The bug happens when:

  1. A person has a Google account, "[email protected]"

  2. For some reason they log out (cache is deleted, another machine, etc...), a new anonymous account is created

  3. They proceed to use the app and make changes.

  4. Then they try to log back on with their "[email protected]" account.

Right now in my app, the person will be "stuck" on the anonymous account, since I can't link an anonymous account to the existing "[email protected]" account.

I believe I need to be able to determine if their Google account already exists to be able to handle this situation. Either merge or delete the anonymous account.

heloineto avatar Jul 30 '22 15:07 heloineto

I'm not sure about the app version of Firebase. But in Javascript, you can just catch the error and sign in the user normally. Just as the docs suggest: image

itaquito avatar Jul 30 '22 16:07 itaquito

I'm not sure about the app version of Firebase. But in Javascript, you can just catch the error and sign in the user normally. Just as the docs suggest

Oh, I see.

I'm not sure what past me was thinking, I guess I didn't want to prompt the user again.

It seems that's the way I'm supposed to do it. Thanks for being so helpful!

heloineto avatar Jul 31 '22 13:07 heloineto

I'm not sure about the app version of Firebase. But in Javascript, you can just catch the error and sign in the user normally. Just as the docs suggest:

Hero. the docs are awful, this should be part of the linkWithX (linkWithPopup etc) doc instead of hidden like this

pmcanneny avatar May 19 '23 01:05 pmcanneny

welp i got too excited too soon, error.credential comes back undefined for me RIP

pmcanneny avatar May 19 '23 01:05 pmcanneny

I want Convert an anonymous account to a permanent account. I have read https://firebase.google.com/docs/auth/web/anonymous-auth#convert-an-anonymous-account-to-a-permanent-account. But I can't find how to create googleUser. Can you help me?

iamtun avatar Oct 21 '23 05:10 iamtun