From 9fe05dc12ea1b309d63875478284c06c04a76cd7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gautier Date: Tue, 3 Sep 2024 11:38:43 +0200 Subject: [PATCH] fix: get user id from id_token --- examples/nextjs-app/auth.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/nextjs-app/auth.ts b/examples/nextjs-app/auth.ts index 3536ab9..b1533fd 100644 --- a/examples/nextjs-app/auth.ts +++ b/examples/nextjs-app/auth.ts @@ -8,13 +8,26 @@ export const { handlers, signIn, signOut, auth } = NextAuth({ type: 'oidc', clientId: process.env.AUTH_CLIENT_ID, clientSecret: process.env.AUTH_CLIENT_SECRET, - checks: ['pkce', 'state'], + checks: ['pkce', 'state', 'nonce'], authorization: { params: { scope: 'openid profile email' } }, + idToken: true, }], session: { strategy: 'jwt' }, callbacks: { + jwt: ({ token, profile }) => { + if (profile?.sub && profile?.email) { + return { + sub: profile.sub, + name: profile.name, + email: profile.email, + picture: profile.picture, + } + } + + return token + }, session: async ({ session }) => { return session },