Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
heloineto opened this issue Mar 10, 2022 · 9 comments
Open

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

heloineto opened this issue Mar 10, 2022 · 9 comments

Comments

@heloineto
Copy link

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

import { GoogleAuthProvider } from "firebase/auth";
const credential = GoogleAuthProvider.credential(
googleUser.getAuthResponse().id_token);

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.

@cesarhilario
Copy link

Any updates?

@itaquito
Copy link

itaquito commented Jul 27, 2022

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
Copy link

Just realised this is a duplicate of #256

@heloineto
Copy link
Author

heloineto commented Jul 30, 2022

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, "user@gmail.com"

  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 "user@gmail.com" 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 "user@gmail.com" 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.

@itaquito
Copy link

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

@heloineto
Copy link
Author

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!

@pmcanneny
Copy link

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
Copy link

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

@iamtun
Copy link

iamtun commented Oct 21, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants