Skip to content

Commit 237c7c4

Browse files
VIA-172 AJ Added functionality to distinguish timeout vs logout
1 parent faca345 commit 237c7c4

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/app/_components/inactivity/InactivityDialog.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe("InactivityDialog", () => {
8787

8888
render(<InactivityDialog />);
8989

90-
expect(userLogout).toHaveBeenCalledTimes(1);
90+
expect(userLogout).toHaveBeenCalledWith(true);
9191
});
9292

9393
it("should not show warning when user activity has timed out after warning", async () => {
@@ -101,7 +101,7 @@ describe("InactivityDialog", () => {
101101
hidden: true,
102102
});
103103
expect(inactivityWarningModal).not.toBeVisible();
104-
expect(userLogout).toHaveBeenCalledTimes(1);
104+
expect(userLogout).toHaveBeenCalledWith(true);
105105
});
106106

107107
it("should close the dialog when user clicks the stay logged in button", async () => {
@@ -122,7 +122,7 @@ describe("InactivityDialog", () => {
122122
render(<InactivityDialog />);
123123
screen.getByRole("button", { name: "Log out" }).click();
124124

125-
expect(userLogout).toHaveBeenCalledTimes(1);
125+
expect(userLogout).toHaveBeenCalledWith();
126126
});
127127
});
128128

src/app/_components/inactivity/InactivityDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const InactivityDialog = (): JSX.Element => {
1818
if (status === "authenticated") {
1919
if (isTimedOut) {
2020
dialogRef.current?.close();
21-
userLogout();
21+
userLogout(true);
2222
} else if (isIdle) {
2323
dialogRef.current?.showModal();
2424
}

src/utils/auth/user-logout.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants";
2+
import { SESSION_TIMEOUT_ROUTE } from "@src/app/session-timeout/constants";
23
import { userLogout } from "@src/utils/auth/user-logout";
34
import { signOut } from "next-auth/react";
45

@@ -7,12 +8,21 @@ jest.mock("next-auth/react", () => ({
78
}));
89

910
describe("user-logout", () => {
10-
it("should call signOut with correct parameters", async () => {
11+
it("should call signOut to be redirected to logout page by default", async () => {
1112
userLogout();
1213

1314
expect(signOut).toHaveBeenCalledWith({
1415
redirect: true,
1516
redirectTo: SESSION_LOGOUT_ROUTE,
1617
});
1718
});
19+
20+
it("should call signOut to be redirected to timeout page given reason", async () => {
21+
userLogout(true);
22+
23+
expect(signOut).toHaveBeenCalledWith({
24+
redirect: true,
25+
redirectTo: SESSION_TIMEOUT_ROUTE,
26+
});
27+
});
1828
});

src/utils/auth/user-logout.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"use client";
22

33
import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants";
4+
import { SESSION_TIMEOUT_ROUTE } from "@src/app/session-timeout/constants";
45
import { signOut } from "next-auth/react";
56

6-
const userLogout = () => {
7+
const userLogout = (reasonTimeout: boolean = false) => {
78
signOut({
89
redirect: true,
9-
redirectTo: SESSION_LOGOUT_ROUTE,
10+
redirectTo: reasonTimeout ? SESSION_TIMEOUT_ROUTE : SESSION_LOGOUT_ROUTE,
1011
});
1112
};
1213

0 commit comments

Comments
 (0)