Skip to content

Commit cf9d80d

Browse files
VIA-183 AS/DB Extract session max age as an environment variable
1 parent a39e698 commit cf9d80d

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

.env.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ NHS_LOGIN_CLIENT_ID=vita-app-sandpit
1515
NHS_LOGIN_SCOPE='openid profile'
1616
NHS_LOGIN_PRIVATE_KEY=
1717

18+
# Active Session Expiry
19+
MAX_SESSION_AGE_MINUTES=59
20+
1821
# NBS
1922
NBS_URL=https://<nbs-link>
2023
NBS_BOOKING_PATH=/nhs-app

auth.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import { isValidSignIn } from "@src/utils/auth/callbacks/is-valid-signin";
88
import { getToken } from "@src/utils/auth/callbacks/get-token";
99
import { getUpdatedSession } from "@src/utils/auth/callbacks/get-updated-session";
1010

11-
const MAX_SESSION_AGE_SECONDS: number = 12 * 60 * 60; // 12 hours of continuous usage
12-
1311
export const { handlers, signIn, signOut, auth } = NextAuth(async () => {
1412
const config: AppConfig = await configProvider();
13+
const MAX_SESSION_AGE_SECONDS: number = config.MAX_SESSION_AGE_MINUTES * 60;
1514

1615
return {
1716
providers: [await NHSLoginAuthProvider()],
@@ -24,7 +23,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth(async () => {
2423
},
2524
session: {
2625
strategy: "jwt",
27-
maxAge: MAX_SESSION_AGE_SECONDS, // 12 hours of continuous usage
26+
maxAge: MAX_SESSION_AGE_SECONDS,
2827
},
2928
trustHost: true,
3029
callbacks: {

infrastructure/environments/dev/locals.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ locals {
2828
NHS_LOGIN_URL = "https://auth.sandpit.signin.nhs.uk"
2929
NHS_LOGIN_SCOPE = "openid profile"
3030

31+
MAX_SESSION_AGE_MINUTES = 59
32+
3133
AUTH_TRUST_HOST = "true"
3234
AUTH_SECRET = random_password.auth_secret.result
3335
APP_VERSION = local.app_version

infrastructure/environments/preprod/locals.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ locals {
2828
NHS_LOGIN_URL = "https://auth.sandpit.signin.nhs.uk"
2929
NHS_LOGIN_SCOPE = "openid profile"
3030

31+
MAX_SESSION_AGE_MINUTES = 59
32+
3133
AUTH_TRUST_HOST = "true"
3234
AUTH_SECRET = random_password.auth_secret.result
3335
APP_VERSION = local.app_version

src/utils/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type AppConfig = {
1212
NHS_LOGIN_PRIVATE_KEY: string;
1313
NBS_URL: string;
1414
NBS_BOOKING_PATH: string;
15+
MAX_SESSION_AGE_MINUTES: number;
1516
};
1617

1718
const configProvider = async (): Promise<AppConfig> => {
@@ -55,6 +56,9 @@ const configProvider = async (): Promise<AppConfig> => {
5556
SSM_PREFIX,
5657
"NBS_BOOKING_PATH",
5758
),
59+
MAX_SESSION_AGE_MINUTES: Number(
60+
await getFromEnvironmentOrSSM(SSM_PREFIX, "MAX_SESSION_AGE_MINUTES"),
61+
),
5862
};
5963
};
6064

0 commit comments

Comments
 (0)