react-google-login icon indicating copy to clipboard operation
react-google-login copied to clipboard

Is there way to refresh token without reload with isSignedIn field?

Open intelcoder opened this issue 5 years ago • 2 comments

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="/"
   />

intelcoder avatar Mar 15 '21 02:03 intelcoder

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).

BanzaiTokyo avatar Apr 29 '21 12:04 BanzaiTokyo

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);
}

gigcasters-dev avatar Jul 22 '21 19:07 gigcasters-dev