Not reciveing any results from firebase using `signInWithRedirect()` and `getRedirectResult()`

Viewed 135

Trying to set up user authentication with firebase for my react project and I don't get any results using signInWithRedirect() and getRedirectResult().

So basically upon clicking a button, I am redirected to the google auth site but then after I am sent back to my homepage I receive no data but I can see in the firebase authentication menu that a new user is added. And when I use signInWithPopup() everything works fine and I get user data the way I want but since this app is mostly for mobile users I need to use signInWithRedirect(). Pls, can anyone help?

//Exported from another component
    export const app = initializeApp(firebaseConfig);
    export const provider = new GoogleAuthProvider();

//Sign in
     const signInWithGoogle = () => {
    signInWithRedirect(auth, provider);
  };

and in other threads, I have seen that you should get the data upon the page initial loading, so i thought using useEffect would solve my problem but it does not

//Get results
    useEffect(() => {
        getRedirectResult(auth, provider)
          .then((result) => {
            // This gives you a Google Access Token. You can use it to access Google APIs.
            const credential = GoogleAuthProvider.credentialFromResult(result);
            const token = credential.accessToken;
    
            // The signed-in user info.
            const user = result.user;
            console.log(user);
          })
          .catch((error) => {
            // Handle Errors here.
            const errorCode = error.code;
            const errorMessage = error.message;
            // The email of the user's account used.
            const email = error.email;
            // The AuthCredential type that was used.
            const credential = GoogleAuthProvider.credentialFromError(error);
            // ...
          });

  }, []);
0 Answers
Related