英文:
How to auto login in react using @react-oauth/google
问题
I'm trying to implement a google SSO login in my react.js application. Signing in part is working as expected and I'm getting a JWT in the response callback, but as soon as I refresh the page I have to login again to get the JWT. I was previously using react-google-login npm package that used to sign in the user automatically and return the user object on page refresh, but that isn't happening with the new @react-oauth/google package.
This is how the button element looks like:
<GoogleLogin
theme="filled_blue"
text="continue_with"
auto_select={true}
useOneTap={true}
state_cookie_domain='single_host_origin'
onSuccess={(credentialResponse) => {
console.log(credentialResponse);
}}
onError={() => {
console.log("Login Failed");
}}
/>
Please help me out, how can I persist a user login automatically?
英文:
I'm trying to implement a google SSO login in my react.js application. Signing in part is working as expected and I'm getting a JWT in the response callback, but as soon as I refresh the page I have to login again to get the JWT. I was previously using react-google-login npm package that used to sign in the user automatically and return the user object on page refresh, but that isn't happening with the new @react-oauth/google package.
This is how the button element looks like
<GoogleLogin
theme="filled_blue"
text="continue_with"
auto_select={true}
useOneTap={true}
state_cookie_domain='single_host_origin'
onSuccess={(credentialResponse) => {
console.log(credentialResponse);
}}
onError={() => {
console.log("Login Failed");
}}
/>
Please help me out, how can I persist a user login automatically?
答案1
得分: 1
You have to store the login token in a cookie or on the local storage.
Cookies
英文:
You have to store the login token in a cookie or on the local storage.
Cookies
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论