0

I am working on a react application using redux and React-Google-login to authenticate the user. I noticed that upon login, I am able to access the sign in tokens and other user information but when I refresh the page, all information about the user is lost and the app is brought back to its original state.

Please, how do I resolve this?

//login function
    const login = (response) => {
        console.log(response);
        dispatch(setSignedIn(true));
        dispatch(setUserData(response.profileObj));
    }



<GoogleLogin
                        clientId='*******************'
                        render={(renderProps) => (
                            <button
                                onClick={renderProps.onClick}
                                disabled={renderProps.disabled}
                                className='login-button'
                            >
                                Login with Google
                            </button>
                        )}
                        
                        onSuccess={login}
                        onFailure={login}
                        isSignedIn={true} 
                        cookiePolicy={'single_host_origin'}
                    />

  • You can use `localStorage` or cookies to retain values beyond page reloads. –  Sep 29 '21 at 20:01
  • @ChrisG if you dont mind helping me refactoring my code to include the code that uses localStorage to retain the values. I am pretty new to React. – denscholar2020 Sep 29 '21 at 20:08
  • Sorry, I don't do free tutoring. Here's the [reference answer](https://stackoverflow.com/questions/29986657/persist-variables-between-page-loads/30070207#30070207) for persisting JS variables. Store the JWT, and when the app mounts, check for its existence and validity. Check the onSuccess part of the [module docs](https://www.npmjs.com/package/react-google-login) for the request you need to send to reestablish the logged in status. –  Sep 29 '21 at 21:26

0 Answers0