Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Grunnleggende håndtering av feilet refresh av token
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeofnorway committed Sep 26, 2023
1 parent b0c6e70 commit 1021e41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/tekster/ledetekster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const ledetekster = {
'logg-inn-knapp': 'Logg inn',
'logg-inn-knapp-en': 'Log in',
'logg-inn-knapp-se': 'Sisačáliheapmi',
'logg-inn-pa-nytt-knapp': 'Logg inn på nytt',
'logg-inn-pa-nytt-knapp-en': 'Log in again',
'logg-inn-pa-nytt-knapp-se': 'Logg inn på nytt',
'logg-ut-knapp': 'Logg ut',
'logg-ut-knapp-en': 'Log out',
'logg-ut-knapp-se': 'Olggosčáliheapmi',
Expand All @@ -59,6 +62,15 @@ export const ledetekster = {
'snart-session-logget-ut-body': 'Avslutt det du jobber med og logg inn igjen.',
'snart-session-logget-ut-body-en': 'Please wrap up what you are doing and log in again.',
'snart-session-logget-ut-body-se': 'Avslutt det du jobber med og logg inn igjen.',
'token-feilet-tittel': 'Det har skjedd en feil',
'token-feilet-tittel-en': 'An error has happened',
'token-feilet-tittel-se': 'Det har skjedd en feil',
'token-feilet-body': 'Forsøket på å forlenge innloggingen din feilet, vi beklager.',
'token-feilet-body-en': 'An attempt to extend your login period failed, we apologize.',
'token-feilet-body-se': 'Forsøket på å forlenge innloggingen din feilet, vi beklager.',
'token-feilet-avbryt': `Avbryt`,
'token-feilet-avbryt-en': `Cancel`,
'token-feilet-avbryt-se': `Avbryt`,
ok: 'OK',
'ok-en': 'OK',
'ok-se': 'OK',
Expand Down
16 changes: 15 additions & 1 deletion src/utils/hooks/useLoginStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const useLoginStatus = () => {
const { innloggetStatus, environment } = useSelector(stateSelector);
const [isTokenExpiring, setIsTokenExpiring] = useState<boolean | null>(null);
const [isSessionExpiring, setIsSessionExpiring] = useState<boolean | null>(null);
const [hasAuthError, setHasAuthError] = useState<boolean>(false);
const [secondsToSessionExpires, setSecondsToSessionExpires] = useState<number>(0);
useLoginDebug();

Expand All @@ -25,6 +26,12 @@ export const useLoginStatus = () => {
const innloggetStatusRef = useRef(innloggetStatus);
innloggetStatusRef.current = innloggetStatus;

useEffect(() => {
window.addEventListener('INVALID-SESSION', () => {
setHasAuthError(true);
});
}, []);

const getExpirationInSeconds = ({ session, token }: { session: string | null; token: string | null }) => {
if (!session || !token) return { secondsToTokenExpires: null, secondsToSessionExpires: null };

Expand Down Expand Up @@ -87,5 +94,12 @@ export const useLoginStatus = () => {
window.addEventListener('visibilitychange', onVisibilityChange);
}, []);

return { isTokenExpiring, isSessionExpiring, refreshTokenHandler, logoutHandler, secondsToSessionExpires };
return {
isTokenExpiring,
isSessionExpiring,
refreshTokenHandler,
logoutHandler,
secondsToSessionExpires,
hasAuthError,
};
};

0 comments on commit 1021e41

Please sign in to comment.