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