Skip to content

The open alternative to Salesforce, designed for AI.

Fix: Correct inverted logic in signUpWithoutWorkspace causing 'User already exists' error (#15086)

Félix Malfait9495d07566cb
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 afe4567eebc..0c3847947fb 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 8c31bcd96eb..fff7f4bdef2 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 3ac89baf611..72cced00bc7 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 4fdc35502d4..b74ed7c5fce 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: