onSuccess not triggering while using uxMode='redirect' ->react-google-login?

二次信任 提交于 2020-06-01 05:40:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!