newsiberian / apollo-link-token-refresh

Apollo Link that performs access tokens (JWT) renew
MIT License
337 stars 45 forks source link

Prevent forward if error #55

Open TheNerdGuyLulu opened 2 years ago

TheNerdGuyLulu commented 2 years ago

Context: If the refresh token has expired, it will trigger handleError. Inside, this condition confirms that the refresh token has expired and calls logout, clearing sessions local cache.

// If the refresh token expired, log the user out 
if (err.message === 'Unknown or invalid refresh token.') {
  await logout();
}

// Links
link: from([errorLink, refreshLink, authLink, httpLink]),

This will trigger a new request, which will fail since the token couldn't be refreshed. If we could manually call forward, or just return a boolean (true forward, false terminate), it would give the developer more power to control the error handle.

If there's another way to accomplish this, please let me know. Thank you