Skip to content

Commit 540df2b

Browse files
VIA-172 AJ/AS InactivityDialog now handles logged-out user to redirect to session logout page
1 parent d759864 commit 540df2b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/app/_components/inactivity/InactivityDialog.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
"use client";
22

3+
import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants";
34
import { userExtendSession } from "@src/utils/auth/user-extend-session";
45
import { createRef, JSX, useEffect } from "react";
56
import styles from "./styles.module.css";
67
import { userLogout } from "@src/utils/auth/user-logout";
78
import useInactivityTimer from "@src/utils/auth/inactivity-timer";
89
import { useSession } from "next-auth/react";
10+
import { useRouter } from "next/navigation";
911

1012
const InactivityDialog = (): JSX.Element => {
13+
const router = useRouter();
1114
const { status } = useSession();
1215
const { isIdle, isTimedOut } = useInactivityTimer();
1316
const dialogRef = createRef<HTMLDialogElement>();
1417

1518
useEffect(() => {
1619
const isAuthenticated = status === "authenticated";
1720

21+
if (status === "unauthenticated") {
22+
dialogRef.current?.close();
23+
router.push(SESSION_LOGOUT_ROUTE);
24+
return;
25+
}
26+
1827
if (isAuthenticated && isTimedOut) {
1928
dialogRef.current?.close();
2029
userLogout();
2130
} else if (isAuthenticated && isIdle) {
2231
dialogRef.current?.showModal();
2332
}
24-
}, [dialogRef, isIdle, isTimedOut, status]);
33+
}, [dialogRef, isIdle, isTimedOut, router, status]);
2534

2635
return (
2736
<dialog ref={dialogRef} className={styles.warningDialog}>

src/utils/auth/inactivity-timer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useEffect, useRef, useState } from "react";
44

5-
const WARNING_TIME_MS: number = 9 * 60 * 1000;
5+
export const WARNING_TIME_MS: number = 9 * 60 * 1000;
66
const LOGOUT_TIME_MS: number = 10 * 60 * 1000;
77
export const ACTIVITY_EVENTS: string[] = [
88
"keydown",

0 commit comments

Comments
 (0)