From 97068d5f6d2496f9394e633808be8db6d61c8a87 Mon Sep 17 00:00:00 2001 From: alma Date: Thu, 17 Apr 2025 13:59:39 +0200 Subject: [PATCH] solve mail backend 6 --- app/api/auth/[...nextauth]/route.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 43d9cf19..2b349306 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -195,6 +195,31 @@ export const authOptions: NextAuthOptions = { throw new Error("RefreshAccessTokenError"); } + try { + console.log('Creating/updating user in session callback:', { + id: token.sub, + email: token.email + }); + + // Create or update user in local database + await prisma.user.upsert({ + where: { id: token.sub as string }, + update: { + email: token.email as string, + password: '', // We don't store password for Keycloak users + }, + create: { + id: token.sub as string, + email: token.email as string, + password: '', // We don't store password for Keycloak users + }, + }); + + console.log('User created/updated successfully'); + } catch (error) { + console.error('Error creating/updating user in session callback:', error); + } + session.accessToken = token.accessToken; session.user = { id: token.sub as string,