question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to execute the onSuccess callback when using "redirect" in "uxMode"

See original GitHub issue

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'
    />

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:9

github_iconTop GitHub Comments

5reactions
ArrayKnightcommented, Aug 22, 2019

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

2reactions
mactannercommented, Apr 20, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

onSuccess not triggering while using uxMode='redirect'
am calling this from http://localhost:3000/results page and its redirecting to http://localhsot:3000/#id_token=XXXX with appending id_token on ...
Read more >
How to execute the onSuccess callback when using "redirect" in ...
Hi, how do I make the onSuccess callback execute if I'm using "redirect" in "uxMode" ? I'm trying to put user info in...
Read more >
react-google-login - npm Package Health Analysis - Snyk
A Google Login Component for React For more information about how to use this ... isSignedIn={true} attribute will call onSuccess callback on load...
Read more >
A Quick Guide to React Login Options - Okta Developer
I will start with a login redirect. ... onSuccess() and onError() are callbacks that will be called when the login has been successful...
Read more >
API with NestJS #42. Authenticating users with Google
To implement authentication with Google in our application, ... When the user successfully authenticates, the onSuccess callback is invoked.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found