From 09434a68afab3340c09f9f486215899ac9dc5e07 Mon Sep 17 00:00:00 2001 From: Alexander Petkov Date: Sat, 8 Jun 2024 15:05:29 +0300 Subject: [PATCH] [2/2]fix: Link existing users to identity providers on user exists error --- src/pages/api/auth/[...nextauth].ts | 3 +++ src/service/auth.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts index 5a81ad4f7..61700dad5 100644 --- a/src/pages/api/auth/[...nextauth].ts +++ b/src/pages/api/auth/[...nextauth].ts @@ -104,6 +104,9 @@ export const authOptions: NextAuthOptions = { account.access_token, account.provider, token.picture ?? '', + token.sub ?? '', + token.email ?? '', + token.name ?? '', ) return { accessToken: keycloakToken.accessToken, diff --git a/src/service/auth.ts b/src/service/auth.ts index 88135d086..932ac8080 100644 --- a/src/service/auth.ts +++ b/src/service/auth.ts @@ -135,11 +135,14 @@ export async function getAccessTokenFromProvider( token: string | undefined, provider: string, picture: string, + userId: string, + email: string, + name: string, ): Promise { try { const response = await apiClient.post( endpoints.auth.providerLogin.url, - { providerToken: token, provider, picture }, + { providerToken: token, provider, picture, userId, email, name }, { headers: { 'Content-Type': 'application/json' }, method: 'POST',