Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/core/utils/src/lib/activepieces-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type ApErrorParams =
| ValidationErrorParams
| InvitationOnlySignUpParams
| UserIsInActiveErrorParams
| UserNotFoundOnPlatformErrorParams
| DomainIsNotAllowedErrorParams
| EmailAuthIsDisabledParams
| ExistingAlertChannelErrorParams
Expand Down Expand Up @@ -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,
{
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions packages/server/api/src/app/helper/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const statusCodeMap: Partial<Record<ErrorCode, StatusCodes>> = {
[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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions packages/web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
Loading