|
1 | 1 | import NHSLoginAuthProvider from "@src/app/api/auth/[...nextauth]/provider"; |
2 | 2 | import { SESSION_LOGOUT_ROUTE } from "@src/app/session-logout/constants"; |
3 | 3 | import { SSO_FAILURE_ROUTE } from "@src/app/sso-failure/constants"; |
| 4 | +import type { DecodedToken } from "@src/utils/auth/types"; |
4 | 5 | import { AppConfig, configProvider } from "@src/utils/config"; |
5 | 6 | import { logger } from "@src/utils/logger"; |
6 | | -import NextAuth, { type DefaultSession } from "next-auth"; |
| 7 | +import NextAuth from "next-auth"; |
7 | 8 | import "next-auth/jwt"; |
8 | 9 | import { jwtDecode } from "jwt-decode"; |
9 | 10 | import { Logger } from "pino"; |
10 | 11 | import { generateClientAssertion } from "@src/utils/auth/generate-refresh-client-assertion"; |
11 | 12 |
|
12 | | -export interface DecodedToken { |
13 | | - iss: string; |
14 | | - aud: string; |
15 | | - identity_proofing_level: string; |
16 | | -} |
17 | | - |
18 | | -// Augmenting types. Ref https://authjs.dev/getting-started/typescript#module-augmentation |
19 | | -declare module "next-auth" { |
20 | | - interface Session { |
21 | | - user: { |
22 | | - nhs_number: string, |
23 | | - birthdate: string, |
24 | | - access_token: string, |
25 | | - } & DefaultSession["user"], |
26 | | - } |
27 | | - |
28 | | - interface Profile { |
29 | | - nhs_number: string, |
30 | | - } |
31 | | -} |
32 | | - |
33 | | -declare module "next-auth/jwt" { |
34 | | - interface JWT { |
35 | | - user: { |
36 | | - nhs_number: string, |
37 | | - birthdate: string, |
38 | | - }, |
39 | | - expires_at: number, |
40 | | - refresh_token: string, |
41 | | - access_token: string, |
42 | | - fixedExpiry: number; |
43 | | - } |
44 | | -} |
45 | | - |
46 | 13 | const log: Logger = logger.child({ module: "auth" }); |
47 | 14 |
|
48 | 15 | const MAX_SESSION_AGE_SECONDS: number = 12 * 60 * 60; // 12 hours of continuous usage |
@@ -85,6 +52,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth(async () => { |
85 | 52 | } |
86 | 53 | return isValidToken; |
87 | 54 | }, |
| 55 | + |
88 | 56 | async jwt({ token, account, profile}) { |
89 | 57 | if (!token) { |
90 | 58 | log.error("No token available in jwt callback."); |
|
0 commit comments