Skip to content

New: [AEA-6292] - Authentication redirect & blocking render improvements#1865

Merged
connoravo-nhs merged 105 commits intomainfrom
AEA-6292
Mar 31, 2026
Merged

New: [AEA-6292] - Authentication redirect & blocking render improvements#1865
connoravo-nhs merged 105 commits intomainfrom
AEA-6292

Conversation

@connoravo-nhs
Copy link
Copy Markdown
Contributor

@connoravo-nhs connoravo-nhs commented Mar 5, 2026

Summary

  • ✨ New Feature
  • ⚠️ Potential issues that might be caused by this change

Details

Aims to resolve the bugs identified in:

  • AEA-6292
  • AEA-6310
  • AEA-5831
  • AEA-6326

Changes made:
The ensureRoleSelected function has been somewhat re-written to ensure hierarchical order is correct & that if statements are "looser" fitting to negative scenarios. Public paths shouldn't be affected by redirections apart from root and login.

The shouldBlockChildren function has also had additional conditions added, that will ensure a render block occurs, so that on-page useEffects don't run.

The shouldBlockChildren now dictates within AccessContext.Provider return, whether the children or loading page should be shown. This is believed to resolve an issue where re-rendering wasn't occurring in the event of a state change if a user was on the loading page in an auth transition state.

Token lambdas now check for a 'complete' token information in the DynamoDb table, to prevent the cause of eventual consistency of a session logout, where a dynamoDb row remains with skeleton information and no actual credentials.

connoravo-nhs and others added 27 commits February 24, 2026 14:18
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
…en blocking conditions

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
… concurrent on primary session on select role page

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
…on, as blocked rn

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
…s have a test

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
tokenMapping.cis2IdToken !== undefined &&
tokenMapping.cis2ExpiresIn !== undefined &&
tokenMapping.lastActivityTime !== undefined &&
tokenMapping.lastActivityTime > Date.now() - fifteenMinutes
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A strange case where a token wasn't fully "cleaned" from the database, it existed as a user entry but no further information. This was presenting as a concurrent session to users who weren't logged in elsewhere.

function checkIfValidTokenMapping(tokenMapping: TokenMappingItem | undefined): boolean {
const fifteenMinutes = 15 * 60 * 1000

return tokenMapping !== undefined &&
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A strange case where a token wasn't fully "cleaned" from the database, it existed as a user entry but no further information. This was presenting as a concurrent session to users who weren't logged in elsewhere.

return (
<AccessContext.Provider value={{}}>
{children}
{shouldBlockChildren() ? <Layout><LoadingPage /></Layout> : children}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Children shown should always satisfy shouldBlockChildren within the Access Provider. Having it seperately could lead to potential race conditions.

const isAmplifyHostRequest = config.url?.includes("/api/cis2-signout") ?? false
if (idToken === undefined && !isAmplifyHostRequest) {
controller.abort()
throw new Error("Could not get a cognito token")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To discuss impact on AEA-5838

}, [auth.rolesWithAccess, auth.rolesWithoutAccess])

// Handle auto-redirect for single role
useEffect(() => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shifted to AccessProvider

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
…ion. Resolve rum log sent state

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>

if (remainingSeconds !== undefined) {
const twoMinutes = 2 * 60 // Minutes into seconds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the timeout modal is appearing on the /select-your-role page which causes an error when you choose 'stay logged in' as handlestayloggedin works by re-selecting your role.

const currentPath = normalizePath(location.pathname)
              if (currentPath === FRONTEND_PATHS.SELECT_YOUR_ROLE) {
                return
              }

there might be a more elegant solution but just adding the code above worked for me

Signed-off-by: Connor Avery <214469360+connoravo-nhs@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

@connoravo-nhs connoravo-nhs merged commit 352787d into main Mar 31, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants