From 0b5c1941aa9ffbd90822141f316fcd40baaeee26 Mon Sep 17 00:00:00 2001 From: Bereket Engida Date: Mon, 7 Apr 2025 10:02:02 +0300 Subject: [PATCH] fix(generic-oauth): should check for email after mapProfileToUser --- .../better-auth/src/plugins/generic-oauth/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/better-auth/src/plugins/generic-oauth/index.ts b/packages/better-auth/src/plugins/generic-oauth/index.ts index 7c5c009ffd..26ae09ba96 100644 --- a/packages/better-auth/src/plugins/generic-oauth/index.ts +++ b/packages/better-auth/src/plugins/generic-oauth/index.ts @@ -602,16 +602,16 @@ export const genericOAuth = (options: GenericOAuthOptions) => { ? await provider.getUserInfo(tokens) : await getUserInfo(tokens, finalUserInfoUrl) ) as User | null; - - if (!userInfo?.email) { - ctx.context.logger.error("Unable to get user info", userInfo); - throw redirectOnError("email_is_missing"); + if (!userInfo) { + throw redirectOnError("user_info_is_missing"); } - const mapUser = provider.mapProfileToUser ? await provider.mapProfileToUser(userInfo) : null; - + if (!mapUser?.email) { + ctx.context.logger.error("Unable to get user info", userInfo); + throw redirectOnError("email_is_missing"); + } if (link) { if ( ctx.context.options.account?.accountLinking