From 1c281da95d8257d54d6ae88963f1baae6416d2d4 Mon Sep 17 00:00:00 2001 From: Bartosz Majewski <30874844+majewskibartosz@users.noreply.github.com> Date: Tue, 1 Sep 2026 18:22:19 +0200 Subject: [PATCH] fix(auth): sign-in now says why it failed instead of a generic error (#15161) --- .../core/utils/src/lib/activepieces-error.ts | 9 ++++++ .../authentication/authentication.service.ts | 9 +++++- .../api/src/app/helper/error-handler.ts | 1 + .../ce/authentication/authentication.test.ts | 32 +++++++++++++++++++ .../web/public/locales/en/translation.json | 1 + .../components/sign-in-form.tsx | 8 +++++ 6 files changed, 59 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/src/lib/activepieces-error.ts b/packages/core/utils/src/lib/activepieces-error.ts index 56813bf56f2b..67533a671e98 100644 --- a/packages/core/utils/src/lib/activepieces-error.ts +++ b/packages/core/utils/src/lib/activepieces-error.ts @@ -51,6 +51,7 @@ export type ApErrorParams = | ValidationErrorParams | InvitationOnlySignUpParams | UserIsInActiveErrorParams + | UserNotFoundOnPlatformErrorParams | DomainIsNotAllowedErrorParams | EmailAuthIsDisabledParams | ExistingAlertChannelErrorParams @@ -215,6 +216,13 @@ ErrorCode.USER_IS_INACTIVE, } > +export type UserNotFoundOnPlatformErrorParams = BaseErrorParams< +ErrorCode.USER_NOT_FOUND_ON_PLATFORM, +{ + email: string +} +> + export type ExistingUserErrorParams = BaseErrorParams< ErrorCode.EXISTING_USER, { @@ -557,6 +565,7 @@ export enum ErrorCode { TRIGGER_UPDATE_STATUS = 'TRIGGER_UPDATE_STATUS', TRIGGER_FAILED = 'TRIGGER_FAILED', USER_IS_INACTIVE = 'USER_IS_INACTIVE', + USER_NOT_FOUND_ON_PLATFORM = 'USER_NOT_FOUND_ON_PLATFORM', VALIDATION = 'VALIDATION', INVALID_LICENSE_KEY = 'INVALID_LICENSE_KEY', EMAIL_ALREADY_HAS_ACTIVATION_KEY = 'EMAIL_ALREADY_HAS_ACTIVATION_KEY', diff --git a/packages/server/api/src/app/authentication/authentication.service.ts b/packages/server/api/src/app/authentication/authentication.service.ts index 6cf2060e8b34..f805e1cbdb9b 100644 --- a/packages/server/api/src/app/authentication/authentication.service.ts +++ b/packages/server/api/src/app/authentication/authentication.service.ts @@ -112,7 +112,14 @@ export const authenticationService = (log: FastifyBaseLogger) => ({ identityId: identity.id, platformId, }) - assertNotNullOrUndefined(user, 'User not found') + if (isNil(user)) { + throw new ActivepiecesError({ + code: ErrorCode.USER_NOT_FOUND_ON_PLATFORM, + params: { + email: identity.email, + }, + }) + } log.info({ email: params.email, platform: { id: platformId } }, 'User signed in with password') return authenticationUtils(log).getProjectAndToken({ userId: user.id, diff --git a/packages/server/api/src/app/helper/error-handler.ts b/packages/server/api/src/app/helper/error-handler.ts index 269ee6781f83..fdae2421f59c 100644 --- a/packages/server/api/src/app/helper/error-handler.ts +++ b/packages/server/api/src/app/helper/error-handler.ts @@ -96,6 +96,7 @@ const statusCodeMap: Partial> = { [ErrorCode.SESSION_EXPIRED]: StatusCodes.FORBIDDEN, [ErrorCode.EMAIL_IS_NOT_VERIFIED]: StatusCodes.FORBIDDEN, [ErrorCode.USER_IS_INACTIVE]: StatusCodes.FORBIDDEN, + [ErrorCode.USER_NOT_FOUND_ON_PLATFORM]: StatusCodes.FORBIDDEN, [ErrorCode.DOMAIN_NOT_ALLOWED]: StatusCodes.FORBIDDEN, [ErrorCode.EMAIL_AUTH_DISABLED]: StatusCodes.FORBIDDEN, [ErrorCode.INVALID_SMTP_CREDENTIALS]: StatusCodes.BAD_REQUEST, diff --git a/packages/server/api/test/integration/ce/authentication/authentication.test.ts b/packages/server/api/test/integration/ce/authentication/authentication.test.ts index 772072015310..7e7c293920f0 100644 --- a/packages/server/api/test/integration/ce/authentication/authentication.test.ts +++ b/packages/server/api/test/integration/ce/authentication/authentication.test.ts @@ -174,6 +174,38 @@ describe('Authentication API', () => { expect(await databaseConnection().getRepository('platform').count()).toBe(0) }) + it('Tells an identity with no user on the resolved platform why it cannot sign in', async () => { + // arrange + await app?.inject({ + method: 'POST', + url: '/api/v1/authentication/sign-up', + body: createMockSignUpRequest({ email: 'ahmad.tash@activepieces.com' }), + }) + + const password = 'password-that-verifies' + await userIdentityService(app!.log).create({ + email: 'orphan.identity@activepieces.com', + password, + firstName: 'Orphan', + lastName: 'Identity', + trackEvents: false, + newsLetter: false, + provider: UserIdentityProvider.EMAIL, + verified: true, + }) + + // act + const response = await app?.inject({ + method: 'POST', + url: '/api/v1/authentication/sign-in', + body: createMockSignInRequest({ email: 'orphan.identity@activepieces.com', password }), + }) + + // assert + expect(response?.statusCode).toBe(StatusCodes.FORBIDDEN) + expect(response?.json()?.code).toBe('USER_NOT_FOUND_ON_PLATFORM') + }) + it('Fails if password doesn\'t match', async () => { // arrange const mockSignUpRequest = createMockSignUpRequest() diff --git a/packages/web/public/locales/en/translation.json b/packages/web/public/locales/en/translation.json index 83613f7fde23..4f5465b6bf11 100644 --- a/packages/web/public/locales/en/translation.json +++ b/packages/web/public/locales/en/translation.json @@ -1869,6 +1869,7 @@ "User has been deactivated": "User has been deactivated", "Email domain is disallowed": "Email domain is disallowed", "Email authentication has been disabled": "Email authentication has been disabled", + "Your account is not set up on this platform, please contact your administrator": "Your account is not set up on this platform, please contact your administrator", "Forgot your password?": "Forgot your password?", "Sign up is restricted. You need an invitation to join. Please contact the administrator.": "Sign up is restricted. You need an invitation to join. Please contact the administrator.", "Email is already used": "Email is already used", diff --git a/packages/web/src/features/authentication/components/sign-in-form.tsx b/packages/web/src/features/authentication/components/sign-in-form.tsx index 1c35bf1b105a..f4d856776200 100644 --- a/packages/web/src/features/authentication/components/sign-in-form.tsx +++ b/packages/web/src/features/authentication/components/sign-in-form.tsx @@ -114,6 +114,14 @@ const SignInForm = ({ onForgotPassword }: SignInFormProps) => { }); break; } + case ErrorCode.USER_NOT_FOUND_ON_PLATFORM: { + form.setError('root.serverError', { + message: t( + 'Your account is not set up on this platform, please contact your administrator', + ), + }); + break; + } default: { form.setError('root.serverError', { message: t('Something went wrong, please try again later'),