18

I'm putting a react web app together with firebase.

I have a sign in screen for users to signin with Google using firebase's signInWithRedirect.

It all works fine, except that the auth returns to the signin screen which shows again for a couple of seconds before my react router picks up that they've authenticated and sends them to the app home.

Refreshing the app home is nice and fast.

Signin is on / The app home is on /app

Is there a way to specify that the Google auth for firebase's signInWithRedirect redirects back to the app home rather than to the original signin page?

user2248331
  • 517
  • 1
  • 4
  • 9

2 Answers2

12

signInWithRedirect always redirects to the same page. You have to call getRedirectResult and then redirect to your app on login. We will relay you request for the custom redirect url to the relevant parties.

bojeil
  • 29,642
  • 4
  • 69
  • 76
  • 3
    Thank you for that. Loving firebase, by the way. I eventually made a Splash component that the signin function routes to which then goes the google auth. In that Splash I detect if this has loaded from the signin or is a fresh load (ie, it came from the redirect) and handle the flow as appropriate. A specific redirect url would be nice though. – user2248331 Jun 17 '16 at 08:21
  • 7
    I also want my app to redirect to a splash screen indicating it's waiting for the google authentication to finish. – mesqueeb Oct 20 '17 at 00:29
  • 6
    @bojeil - it's been 4 years. Has this feature been implemented? – DFB May 16 '20 at 12:17
  • 1
    calling getRedirectResult() when firebase redirects back to the same URL might take some time. The page seems like nothing going on until users wait for a few seconds. I would like to be able to show the loading right after the page is redirected from Firebase. Seem like I have to handle this on my own. – channa ly Sep 29 '20 at 04:05
  • 1
    I had the same problem, so I decided to use reauthenticateWithPopup instead of reauthenticateWithRedirect. –  Nov 02 '20 at 10:16
  • 2
    The firebase docs say that they recommend using signInWithRedirect vs signInWithPopup for mobile devices. Is this still relevant? – redshift Feb 09 '21 at 21:24
  • Maybe this will help on this 2021 https://firebase.google.com/docs/reference/js/v8/firebase.auth.OAuthProvider#setcustomparameters – Fernando Torres Dec 04 '21 at 21:38
2

One hack that you can use:

window.history.replaceState({}, '', '<Your Url>');

After this call signInWithRedirect.

Note that you will still have to call getRedirectResult on <Your Url> page.

Sagar Jain
  • 51
  • 3