skip to Main Content

I am having some problems. I am using React Native with Firebase and the getRedirectResult(auth) is consistently returning null even though I have already signed in with the google provider. I think it is because the page is doing a full reload?

 const provider = new GoogleAuthProvider();
    try {
      await signInWithRedirect(auth, provider)
      const result = await getRedirectResult(auth);
      if (result) {
        router.push('/HomeScreen');
      }
    } catch (error: any) {
        console.error(error);
    }

This is my code which doesnt work. Please help!

2

Answers


  1. Chosen as BEST ANSWER

    I just want to update that I fixed the problem. It was a terribly dumb mistake. I was debugging and testing this locally (localhost), but my redirect_uri in GCP was pointing to my production domain, and that was why the flow broke and I was getting null.

    Thanks Doug Stevenson for helping bring some clarity to my thought process too. Appreciate it!


  2. I think it is because the page is doing a full reload?

    Yes. When a page reloads, all of its memory and context is lost. The old page does not execute any code or receive any results.

    You should follow the documentation for handling Google signin. It suggests using getRedirectResult to get the result of the sign-in. This means that your app should use getRedirectResult at the time the page is loaded to determine what to do next when a user is newly signed in. You can’t simply await signInWithRedirect, since the reload wipes out memory an context of the current page. (Also signInWithRedirect doesn’t return a promise, so it’s non await-able.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search