Skip to content

Commit 070d0d4

Browse files
VIA-172 AJ Added session timeout page
1 parent 40f255a commit 070d0d4

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const SESSION_TIMEOUT_ROUTE = "/session-timeout";
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import SessionTimeout from "@src/app/session-timeout/page";
2+
import { mockNHSAppJSFunctions } from "@src/utils/nhsapp-js.test";
3+
import { render, screen } from "@testing-library/react";
4+
5+
describe("SessionTimeout", () => {
6+
const mockIsOpenInNHSApp = jest.fn();
7+
const mockGoToHomePage = jest.fn();
8+
9+
beforeEach(() => {
10+
mockNHSAppJSFunctions(mockIsOpenInNHSApp, mockGoToHomePage);
11+
});
12+
13+
it("should show NHS App home page inside NHS App", () => {
14+
mockIsOpenInNHSApp.mockReturnValue(true);
15+
render(<SessionTimeout />);
16+
expect(mockGoToHomePage).toHaveBeenCalledTimes(1);
17+
});
18+
19+
it("should show timeout out page outside NHS App", () => {
20+
mockIsOpenInNHSApp.mockReturnValue(false);
21+
render(<SessionTimeout />);
22+
const heading = screen.getByRole("heading", {
23+
level: 1,
24+
name: "You have been logged out",
25+
});
26+
expect(heading).toBeInTheDocument();
27+
});
28+
});

src/app/session-timeout/page.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"use client";
2+
3+
import MainContent from "@src/app/_components/nhs-frontend/MainContent";
4+
import { useEffect } from "react";
5+
6+
const SessionTimeout = () => {
7+
useEffect(() => {
8+
if (window.nhsapp.tools.isOpenInNHSApp()) {
9+
window.nhsapp.navigation.goToHomePage();
10+
}
11+
}, []);
12+
13+
return (
14+
<MainContent>
15+
<title>You have been logged out</title>
16+
<h1>You have been logged out</h1>
17+
<p>
18+
For security reasons, you&#39;re automatically logged out if you have not used the service for 10 minutes.
19+
</p>
20+
<p>
21+
If you were entering information, it has not been saved and you will need to re-enter it.
22+
</p>
23+
<p>
24+
To continue, close the tab which has the service open and login again.
25+
</p>
26+
</MainContent>
27+
);
28+
};
29+
30+
export default SessionTimeout;

src/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export const config = {
2828
* 5. /favicon.ico (exclude the favicon path)
2929
* 6. /nhsuk-frontend-9.1.0 (exclude nhsuk js)
3030
*/
31-
"/((?!api/auth|api/sso|session-logout|sso-failure|favicon.ico|nhsuk-frontend-9.1.0|_next/static|_next/image).*)",
31+
"/((?!api/auth|api/sso|session-logout|session-timeout|sso-failure|favicon.ico|nhsuk-frontend-9.1.0|_next/static|_next/image).*)",
3232
],
3333
};

0 commit comments

Comments
 (0)