Skip to content

Commit

Permalink
nit: eslint
Browse files Browse the repository at this point in the history
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
  • Loading branch information
TheMaskedTurtle committed Dec 19, 2023
1 parent 5fbb28f commit a433a1a
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/utils/AuthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ function handleSigninSilent(dispatch, userManager, navigate) {
if (
!sessionStorage.getItem(oidcHackReloaded) &&
error.message ===
'authority mismatch on settings vs. signin state'
'authority mismatch on settings vs. signin state'
) {
sessionStorage.setItem(oidcHackReloaded, true);
console.log('Hack oidc, reload page to make login work');
console.log(
'Hack oidc, reload page to make login work'
);
window.location.reload();
}
}
Expand Down Expand Up @@ -193,7 +195,8 @@ function initializeAuthenticationProd(
};
let userManager = new UserManager(settings);
userManager.idpSettings = idpSettings; //store our settings in there as well to use it later
userManager.authorizationCodeFlowEnabled = authorizationCodeFlowEnabled;
userManager.authorizationCodeFlowEnabled =
authorizationCodeFlowEnabled;
if (!isSilentRenew) {
handleUser(dispatch, userManager, validateUser);
if (!isSigninCallback) {
Expand Down Expand Up @@ -252,16 +255,18 @@ function getIdTokenExpiresIn(user) {

function tokenRenewal(dispatch, userManagerInstance, validateUser, id_token) {
clearTimeout(tokenRenewalTimeout);
const timeMs = getExpiresIn(id_token, parseInt(userManagerInstance.idpSettings.maxExpiresIn)) * 1000;
const timeMs =
getExpiresIn(
id_token,
parseInt(userManagerInstance.idpSettings.maxExpiresIn)
) * 1000;
console.debug(`setting timeoutMs ${timeMs}`);
tokenRenewalTimeout = setTimeout(async () => {
console.debug('renewing tokens...');
userManagerInstance
.signinSilent()
.catch((error) => {
console.error(`token renewal failed ${error.message}`);
logout(dispatch, userManagerInstance);
});
userManagerInstance.signinSilent().catch((error) => {
console.error(`token renewal failed ${error.message}`);
logout(dispatch, userManagerInstance);
});
}, timeMs);
}

Expand Down Expand Up @@ -294,7 +299,12 @@ function dispatchUser(dispatch, userManagerInstance, validateUser) {
'User has been successfully loaded from store.'
);
if (userManagerInstance.authorizationCodeFlowEnabled) {
tokenRenewal(dispatch, userManagerInstance, validateUser, user.id_token);
tokenRenewal(
dispatch,
userManagerInstance,
validateUser,
user.id_token
);
}
return dispatch(setLoggedUser(user));
})
Expand Down

0 comments on commit a433a1a

Please sign in to comment.