Skip to content

Commit

Permalink
fix(oidc): session lost to quickly (alpha) (#1381)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet committed Jun 7, 2024
1 parent 630b4fa commit 0bfabd4
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions packages/oidc-client/src/renewTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,8 @@ export const syncTokensInfoAsync = (oidc: Oidc) => async (configuration:OidcConf

const synchroniseTokensAsync = (oidc:Oidc) => async (index = 0, forceRefresh = false, extras:StringMap = null, updateTokens) =>{

while (!navigator.onLine && document.hidden) {
await sleepAsync({milliseconds: 1000});
oidc.publishEvent(eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
if (!navigator.onLine && document.hidden) {
return { tokens: oidc.tokens, status: 'GIVE_UP' };
}
let numberTryOnline = 6;
while (!navigator.onLine && numberTryOnline > 0) {
Expand Down Expand Up @@ -206,16 +205,6 @@ const synchroniseTokensAsync = (oidc:Oidc) => async (index = 0, forceRefresh = f
return await synchroniseTokensAsync(oidc)(nextIndex, forceRefresh, extras, updateTokens);
}
};

if (index > 4) {
if(isDocumentHidden){
return { tokens: oidc.tokens, status: 'GIVE_UP' };
} else{
updateTokens(null);
oidc.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token' });
return { tokens: null, status: 'SESSION_LOST' };
}
}

try {
const { status, tokens, nonce } = await syncTokensInfoAsync(oidc)(configuration, oidc.configurationName, oidc.tokens, forceRefresh);
Expand Down

0 comments on commit 0bfabd4

Please sign in to comment.