Skip to content

Commit

Permalink
Fix redirect loop when token is already expired #63
Browse files Browse the repository at this point in the history
  • Loading branch information
hupf committed Dec 20, 2023
1 parent ccaba14 commit 69a2753
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/token-renewal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,17 @@ function onExpiration(
clearTimeout(expirationTimers[type]);
}

if (token) {
expirationTimers[type] = setTimeout(callback, getTokenExpireIn(token));
const expireIn = token && getTokenExpireIn(token);
// Don't set timer for already expired token since it will be
// handled by the auth.ts logic and would cause a redirection loop
if (expireIn && expireIn > 0) {
expirationTimers[type] = setTimeout(callback, expireIn);
logLazy(() => {
const { expirationTime } = token;
const expirationDate = new Date();
expirationDate.setTime(expirationTime * 1000);
return `Scheduled ${type} token expiration timeout in ${Math.floor(
getTokenExpireIn(token) / 1000 / 60,
expireIn / 1000 / 60,
)} minutes (at ${expirationDate})`;
});
}
Expand Down

0 comments on commit 69a2753

Please sign in to comment.