react-google-login
react-google-login copied to clipboard
Is there way to refresh token without reload with isSignedIn field?
I believe it will be pretty annoying user to sign in again every hour so I am looking for the way to refresh token without showing popup. I saw some issues from 2018 and it used to return some function for refreshing token.
Is there any recommended way to do it or it has built in feature that I didnt fine?
Here is my setup
<_GoogleLogin
isSignedIn
className="border border-solid border-current mb-4"
clientId={process.env.REACT_APP_GOOGLE_OAUTH_ID}
buttonText={`Sign ${forLogin ? 'in' : 'up'} with Google`}
onSuccess={onSuccess}
onFailure={onFailure}
style={{ marginTop: '100px' }}
redirectUri="/"
/>
I have just posted a similar question before noticing yours. I would also like very much to know if there is a solution to refresh an expired token (for example when the page is left open for a long period of time).
export const refreshTokenSetup = (result) => {
let refreshTiming = (result.tokenObj.expires_in || 3600 - 5 * 60) * 1000;
const refreshToken = async () => {
const newAuthRes = await result.reloadAuthResponse();
refreshTiming = (newAuthRes.expires_in || 3600 - 5 * 60) * 1000;
// Save new Token --> newAuthRes.access_token
console.log(`New Authentication Result: ${newAuthRes}`);
console.log(`New Authentication Token: ${newAuthRes.idToken}`);
setTimeout(refreshToken, refreshTiming);
}
setTimeout(refreshToken, refreshTiming);
}