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

Commit 6ff4865

Browse files
committed
Logger session timeout med amplitude istedenfor console
1 parent ce13623 commit 6ff4865

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/utils/hooks/useLoginStatus.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { AppState } from 'store/reducers';
44
import { hentInnloggingsstatus, fornyInnlogging } from 'store/reducers/innloggingsstatus-duck';
55
import { getLogOutUrl, getLoginUrl } from 'utils/login';
66
import { useLoginDebug } from './useLoginDebug';
7+
import { logAmplitudeEvent } from '../analytics/amplitude';
78

89
const stateSelector = (state: AppState) => ({
910
innloggetStatus: state.innloggingsstatus.data,
@@ -13,7 +14,8 @@ const stateSelector = (state: AppState) => ({
1314

1415
let timeoutId: NodeJS.Timeout | null = null;
1516

16-
let didLogExpiry = false;
17+
const logPeriodMs = 60000;
18+
let lastExpireLog = 0;
1719

1820
export const useLoginStatus = () => {
1921
const dispatch = useDispatch();
@@ -72,14 +74,19 @@ export const useLoginStatus = () => {
7274

7375
const _isTokenExpiring = _innloggetStatus.authenticated && secondsToTokenExpires < 60 * 5;
7476
const _isSessionExpiring = secondsToSessionExpires < 60 * 10;
77+
const now = new Date();
7578

76-
if ((_isTokenExpiring || _isSessionExpiring) && !didLogExpiry) {
77-
console.error(
78-
`Session is timing out - Now: ${new Date().toISOString()} - Session: ${secondsToSessionExpires} / ${
79-
_innloggetStatus.session.endsAt
80-
} - Token: ${secondsToTokenExpires} / ${_innloggetStatus.token.endsAt}`
81-
);
82-
didLogExpiry = true;
79+
if ((_isTokenExpiring || _isSessionExpiring) && now.getTime() > lastExpireLog + logPeriodMs) {
80+
logAmplitudeEvent('session-timeout', {
81+
now: now.toISOString(),
82+
session: _innloggetStatus.session,
83+
token: _innloggetStatus.token,
84+
secondsToSessionExpires,
85+
secondsToTokenExpires,
86+
securityLevel: _innloggetStatus.securityLevel,
87+
});
88+
89+
lastExpireLog = now.getTime();
8390
}
8491

8592
setIsTokenExpiring(_isTokenExpiring);

0 commit comments

Comments
 (0)