VIA-942: Enforce Session Expiry Reliably After 10 Minutes of Inactivity#708
VIA-942: Enforce Session Expiry Reliably After 10 Minutes of Inactivity#708liming-cheung-nhs wants to merge 11 commits intomainfrom
Conversation
… recently called Precommit hooks bypassed; this is a work in progress commit WIP commit: contains * A Server Action to set the flag cookie * Calling the server action from the user-logout method * cherck the flag in getToken Issue under investigation 1. getToken will return null, but the MyVaccines app then currently tries to redirect the user to NHS App because they are not authenticated, meaning the user will never see the logout / session timeout screens. (at present this throws a cors error in the browser and the user never actually gets to NHS app but this is a quirk and the underlying issue still needs fixing; the user shouldnt be redirected at all for this part of the journey. The network tab shows the cors error and an error would be logged in our service logs).
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
There was a problem hiding this comment.
Pull request overview
Implements a short-lived “signout flag” cookie to prevent session refresh logic from re-authenticating a user immediately after logout/inactivity timeout, improving enforcement of 10-minute inactivity expiry.
Changes:
- Add
__Secure-signoutcookie constant and document it in the cookies policy table. - Set the signout-flag cookie during logout and check it in the NextAuth
jwt/getTokencallback to returnnullfor recently-signed-out sessions. - Add/extend unit tests for the new logout flow, cookie setting, and token callback behavior.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/constants.ts | Adds constant for the new signout-flag cookie name. |
| src/utils/auth/user-logout.ts | Converts logout to a server action, wraps in request-scoped storage, and sets signout-flag cookie before signing out. |
| src/utils/auth/user-logout.test.ts | Updates mocks and adds assertions for flag cookie + request-scoped wrapper usage. |
| src/utils/auth/setSignOutFlagCookie.ts | New server action to set a short-lived signout-flag cookie tied to the session id. |
| src/utils/auth/setSignOutFlagCookie.test.ts | New unit test validating the signout cookie is set as expected. |
| src/utils/auth/callbacks/get-token.ts | Reads signout-flag + session-id cookies to short-circuit and return null after recent signout. |
| src/utils/auth/callbacks/get-token.test.ts | Adds tests ensuring getToken returns null when signout flag matches current session. |
| src/app/our-policies/cookies-policy/CookiesTable.tsx | Documents the new __Secure-signout cookie and its purpose/expiry. |
| src/app/our-policies/cookies-policy/CookiesTable.test.tsx | Updates expectations to include the new cookie row and timing. |
| src/app/_components/inactivity/InactivityDialog.test.tsx | Adjusts mocking for updated logout module usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
413fe4b
| void userLogout().catch((error: unknown) => { | ||
| if (!isRedirectError(error)) { | ||
| throw error; | ||
| } | ||
| isLoggingOut.current = false; | ||
| }); |
There was a problem hiding this comment.
NextJS seem to suggest it is bau to return from redirect as exception to stop rendering - this redirect being triggered by nextjs signOut. Catching this error seem to get rid of the client side error consistently that I was seeing locally and in deployed workspace. See PR description for details.
| const triggerLogout = (reasonTimeout?: boolean) => { | ||
| void (reasonTimeout === undefined ? userLogout() : userLogout(reasonTimeout)).catch((error: unknown) => { | ||
| if (!isRedirectError(error)) { | ||
| throw error; | ||
| } | ||
| }); | ||
| }; | ||
|
|
There was a problem hiding this comment.
Added to fix the client side error - see PR description and AppHeader comment.
Description
Testing on deployed to sandpit personal workspace
30/04/2026
I was getting this error on logout
It would seem
signoutcauses redirect - Nextjs Docs suggest redirects return as exception from next so the commit handles that on client. So added commit that seem to fix it.Note: Existing issue under investigation:
getTokenwill return null, but the MyVaccines app then currently tries to redirect the user to NHS App because they are not authenticated, meaning the user will never see the logout / session timeout screens. (at present this throws a cors error in the browser and the user never actually gets to NHS app but this is a quirk and the underlying issue still needs fixing; the user shouldnt be redirected at all for this part of the journey. The network tab shows the cors error and an error would be logged in our service logs).Context
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.