React-google-login: How to execute the onSuccess callback when using "redirect" in "uxMode"

Created on 29 Mar 2018  路  5Comments  路  Source: anthonyjgrove/react-google-login

Hi, how do I make the onSuccess callback execute if I'm using "redirect" in "uxMode" ?
I'm trying to put user info in sessionStorage and it works fine if I use the popup version but it returns null when I use redirect.

Please help. I'm still new to ReactJS.

    const responseOk = (response) => {
            var profile = response.getBasicProfile();
            console.log(profile);
            sessionStorage.setItem('profile', profile);
            this.props.history.push('/');
    }

    const responseFailed = (response) => {
            console.log('Sign-in Failed');
            console.log(response);
    }

    <GoogleLogin
                clientId="key"
                buttonText="Sign in with Google"
                onSuccess={responseOk}
                onFailure={responseFailed}
                uxMode='redirect'
                redirectUri='http://localhost:3000'
    />

Most helpful comment

If you add isSignedIn or isSignedIn={true} then the onSuccess/onFailure callbacks are called on load which is helpful for redirect and for when a user is already signed in

All 5 comments

I think the onSuccess callback won't work in redirect mode. As you navigate away from the page, the callback won't be invoked when you get back to the page.

Maybe you can solve this, if you register a listener for the users sign-in state:
https://developers.google.com/identity/sign-in/web/reference
Once the user is signed in you can get more information about the user / profile directly from the gapi.

Got the same issue but it does make sense. As on the redirect my component is being unmounted so there is no way to get a hold the response. It would be good if there was a way to make it wait for the response and pass it to the next view.

If you add isSignedIn or isSignedIn={true} then the onSuccess/onFailure callbacks are called on load which is helpful for redirect and for when a user is already signed in

If you add isSignedIn or isSignedIn={true} then the onSuccess/onFailure callbacks are called on load which is helpful for redirect and for when a user is already signed in

Hello I am currently fighting this, I have tried even this and the callback wont ever trigger.... Well no, it does trigger once, then you logout, and no matter what you do, it wont trigger ever again

If you add isSignedIn or isSignedIn={true} then the onSuccess/onFailure callbacks are called on load which is helpful for redirect and for when a user is already signed in

This worked for me one time, then when I logged out, it never triggered again

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eap picture eap  路  7Comments

Praneetha-CK picture Praneetha-CK  路  3Comments

bradeac picture bradeac  路  4Comments

pulkit-max picture pulkit-max  路  8Comments

anthonyjgrove picture anthonyjgrove  路  8Comments