Skip to content

Where does googleUser come from? #256

New issue

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

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

Already on GitHub? # to your account

Open
csdal opened this issue Nov 9, 2021 · 3 comments
Open

Where does googleUser come from? #256

csdal opened this issue Nov 9, 2021 · 3 comments

Comments

@csdal
Copy link

csdal commented Nov 9, 2021

providerData[i].uid === googleUser.getBasicProfile().getId()) {

I know that firebaseUser comes from this ( result.user):

signInWithPopup(auth, provider)
      .then((result) => {
        // This gives you a Google Access Token. You can use it to access the Google API.
        const credential = GoogleAuthProvider.credentialFromResult(result);
        const token: string | undefined = credential?.accessToken;
        // The signed-in user info.
        const user = result.user;
.....

But where does googleUser come from?

@heloineto
Copy link

I'm having the same issue. I've looked for hours on the docs and on the internet and had no luck :(

@Temidayo32
Copy link

I think the documentation should be updated. The googleUser come from using the gapi client. Here is a code snippet on how to do that.

export const handleGoogleSignIn = async (): Promise<any> => {
  return new Promise<any>((resolve, reject) => {
    const script = document.createElement('script');
    script.src = 'https://apis.google.com/js/api.js';
    script.onload = () => {
      console.log('Google API script loaded.');
      (window as any).gapi.load('client:auth2', {
        callback: () => {
          (window as any).gapi.auth2.init({
            clientId: authClientId,
          }).then(() => {
            (window as any).gapi.auth2.getAuthInstance().signIn().then((googleUser: any) => {
              resolve(googleUser); // Resolve with googleUser
            }).catch((error: Error) => {
              reject(error);
            });
          }).catch((error: Error) => {
            reject(error);
          });
        },
        onerror: (error: Error) => {
          reject(error);
        }
      });
    };
    script.onerror = (error: Event | string) => {
      console.error('Error loading Google API script:', error);
      reject(error instanceof Error ? error : new Error('Unknown error loading Google API'));
    };
    document.body.appendChild(script);
  });
};

Once, you get the googleUser, you can then, do this:

providerData[i].uid === googleUser.getBasicProfile().getId()

@leoffx
Copy link

leoffx commented Jan 31, 2025

I can't believe this issue is still open for so long. I found an alternative solution in another page, use linkWithPopup
https://firebase.google.com/docs/auth/web/account-linking#link-federated-auth-provider-credentials-to-a-user-account

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

No branches or pull requests

4 participants