MomenSherif / react-oauth

Google OAuth2 using the new Google Identity Services SDK for React 🚀
https://www.npmjs.com/package/@react-oauth/google
MIT License
1.13k stars 141 forks source link

GoogleLogin refresh jwt after expiration #321

Open Devin-Holland opened 11 months ago

Devin-Holland commented 11 months ago

Hi

I'm using the <GoogleLogin> component to get a JWT. I store that JWT in my sate and then with each request to my backend i send the JWT along. My backend then validates the JWT using the OAuth2Client from 'google-auth-library' before performing any other actions:

async function verify() {
  const ticket = await client.verifyIdToken({
    idToken: jwt,
    audience: CLIENT_ID,
  });
  const payload = ticket.getPayload();
  userEmail = payload['email'];
}
await verify().catch(console.error("Token Validation Failed"));

After the expiration of the initial JWT from clicking the button from the GoogleLogin component, all my future requests to my backend are invalidated (as the token is expired).

Is there a way for me to prompt the user for another sign-in automatically for a new JWT? Or some other way while using the <GoogleLogin> component to prevent getting stuck in this situation where the user has to manually click the GoogleLogin button again?