问题
I am using react-google-login component to make user login through google account I have an issue in that. If I use uxMode='popup'
onSucess method is triggering but the same method is not triggering if i use uxMode='redirect' `
<GoogleLogin
clientId="*****"
scope= "profile"
buttonText="Login with Google"
uxMode='redirect'
redirectUri="http://localhost:3000"
onSuccess={responseGoogle}
onFailure={responseGoogle}/>`
回答1:
the redirectUri you specify, should be the one you authorized for the OAuth client. means while creating your app id in google developer console you have to whitelist that url
回答2:
then remove redirect here and redirect from your code after saving the details. for your reference am pasting my code below.
<GoogleLogin
clientId="XXXXXXXXXXXXXXX"
buttonText="Login with Google"
uxMode="redirect"
redirectUri="http://localhost:3000"
onSuccess={responseGoogle}
onFailure={responseGoogle}
/>
am calling this from http://localhost:3000/results page and its redirecting to http://localhsot:3000/#id_token=XXXX with appending id_token on my url.
回答3:
This is how I did with redirect mode.. Onsuccess Function will never be called.. instead use query string and get parsed # id_token.. and send it to server for further validation and profile data
回答4:
You missed adding the trailing slash i.e / to
1)redirectUri i.e redirectUri="http://localhost:3000/"
2)Also make sure that you have added trailing slash i.e / in Authorized redirect URIs under https://console.developers.google.com/. It should also be http://localhost:3000/
<GoogleLogin
clientId="*****"
scope= "profile"
buttonText="Login with Google"
uxMode='redirect'
redirectUri="http://localhost:3000/"
onSuccess={responseGoogle}
onFailure={responseGoogle}/>`
Do not miss the trailing slash.
来源:https://stackoverflow.com/questions/50921888/onsuccess-not-triggering-while-using-uxmode-redirect-react-google-login