Compare commits

...
Author SHA1 Message Date
Sonarly Claude CodeandClaude Opus 4.6 9746b66c48 fix: replace generic assertIsDefinedOrThrow with proper EmailVerificationException for missing user
When resending email verification tokens, if the email doesn't match any
user, assertIsDefinedOrThrow threw a generic "Value not defined" error.
This unhandled error was not caught by EmailVerificationExceptionFilter,
causing it to bubble up to Sentry. Replace with an explicit check that
throws EmailVerificationException with INVALID_EMAIL code, which is
properly handled by the exception filter and returns a user-friendly error.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-02-18 19:42:59 +00:00
@@ -8,7 +8,7 @@ import ms from 'ms';
import { SendEmailVerificationLinkEmail } from 'twenty-emails';
import { type APP_LOCALES } from 'twenty-shared/translations';
import { AppPath } from 'twenty-shared/types';
import { assertIsDefinedOrThrow, isDefined } from 'twenty-shared/utils';
import { isDefined } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import {
@@ -138,7 +138,12 @@ export class EmailVerificationService {
},
});
assertIsDefinedOrThrow(user);
if (!isDefined(user)) {
throw new EmailVerificationException(
'User not found for the given email',
EmailVerificationExceptionCode.INVALID_EMAIL,
);
}
if (user.isEmailVerified) {
throw new EmailVerificationException(