diff --git a/packages/twenty-server/src/engine/core-modules/auth/auth.exception.ts b/packages/twenty-server/src/engine/core-modules/auth/auth.exception.ts index afe4567eeb..0c3847947f 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/auth.exception.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/auth.exception.ts @@ -30,5 +30,5 @@ export const AuthExceptionCode = appendCommonExceptionCode({ 'TWO_FACTOR_AUTHENTICATION_PROVISION_REQUIRED', TWO_FACTOR_AUTHENTICATION_VERIFICATION_REQUIRED: 'TWO_FACTOR_AUTHENTICATION_VERIFICATION_REQUIRED', - USER_ALREADY_EXIST: 'USER_ALREADY_EXIST', + USER_ALREADY_EXISTS: 'USER_ALREADY_EXISTS', } as const); diff --git a/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts b/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts index 8c31bcd96e..fff7f4bdef 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/services/sign-in-up.service.ts @@ -465,15 +465,18 @@ export class SignInUpService { newUserParams: SignInUpNewUserPayload, authParams: AuthProviderWithPasswordType['authParams'], ) { - await this.userService.findUserByEmailOrThrow( + const userExists = await this.userService.findUserByEmail( newUserParams.email, - new AuthException( - 'User already exist', - AuthExceptionCode.USER_ALREADY_EXIST, - { userFriendlyMessage: msg`User already exists` }, - ), ); + if (userExists) { + throw new AuthException( + 'User already exists', + AuthExceptionCode.USER_ALREADY_EXISTS, + { userFriendlyMessage: msg`User already exists` }, + ); + } + return this.saveNewUser( await this.computePartialUserFromUserPayload(newUserParams, authParams), await this.setDefaultImpersonateAndAccessFullAdminPanel(), diff --git a/packages/twenty-server/src/engine/core-modules/auth/utils/auth-graphql-api-exception-handler.util.ts b/packages/twenty-server/src/engine/core-modules/auth/utils/auth-graphql-api-exception-handler.util.ts index 3ac89baf61..72cced00bc 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/utils/auth-graphql-api-exception-handler.util.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/utils/auth-graphql-api-exception-handler.util.ts @@ -26,7 +26,7 @@ export const authGraphqlApiExceptionHandler = (exception: AuthException) => { case AuthExceptionCode.SIGNUP_DISABLED: case AuthExceptionCode.MISSING_ENVIRONMENT_VARIABLE: case AuthExceptionCode.INVALID_JWT_TOKEN_TYPE: - case AuthExceptionCode.USER_ALREADY_EXIST: + case AuthExceptionCode.USER_ALREADY_EXISTS: throw new ForbiddenError(exception); case AuthExceptionCode.GOOGLE_API_AUTH_DISABLED: case AuthExceptionCode.MICROSOFT_API_AUTH_DISABLED: diff --git a/packages/twenty-server/src/engine/core-modules/auth/utils/get-auth-exception-rest-status.util.ts b/packages/twenty-server/src/engine/core-modules/auth/utils/get-auth-exception-rest-status.util.ts index 4fdc35502d..b74ed7c5fc 100644 --- a/packages/twenty-server/src/engine/core-modules/auth/utils/get-auth-exception-rest-status.util.ts +++ b/packages/twenty-server/src/engine/core-modules/auth/utils/get-auth-exception-rest-status.util.ts @@ -22,7 +22,7 @@ export const getAuthExceptionRestStatus = (exception: AuthException) => { case AuthExceptionCode.MISSING_ENVIRONMENT_VARIABLE: case AuthExceptionCode.EMAIL_NOT_VERIFIED: case AuthExceptionCode.INVALID_JWT_TOKEN_TYPE: - case AuthExceptionCode.USER_ALREADY_EXIST: + case AuthExceptionCode.USER_ALREADY_EXISTS: return 403; case AuthExceptionCode.TWO_FACTOR_AUTHENTICATION_PROVISION_REQUIRED: case AuthExceptionCode.TWO_FACTOR_AUTHENTICATION_VERIFICATION_REQUIRED: