feat(nestjs): resend the auth confirmation message

This commit is contained in:
Ahmed Bouhuolia
2025-05-08 19:01:43 +02:00
parent f78d6efe27
commit 3c8b7c92fe
10 changed files with 149 additions and 20 deletions

View File

@@ -41,11 +41,6 @@ export class AuthSigninService {
`Wrong password for user with email: ${email}`,
);
}
if (!user.verified) {
throw new UnauthorizedException(
`The user is not verified yet, check out your mail inbox.`,
);
}
return user;
}

View File

@@ -1,5 +1,42 @@
import { EventEmitter2 } from '@nestjs/event-emitter';
import { Inject, Injectable } from '@nestjs/common';
import { SystemUser } from '@/modules/System/models/SystemUser';
import { ServiceError } from '@/modules/Items/ServiceError';
import { ERRORS } from '../Auth.constants';
import { events } from '@/common/events/events';
import { ModelObject } from 'objection';
import { ISignUpConfigmResendedEventPayload } from '../Auth.interfaces';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
@Injectable()
export class AuthSignupConfirmResendService {
signUpConfirmResend(userId: number) {
return;
constructor(
private readonly eventPublisher: EventEmitter2,
private readonly tenancyContext: TenancyContext,
@Inject(SystemUser.name)
private readonly systemUserModel: typeof SystemUser,
) {}
/**
* Resends the email confirmation of the given user.
* @param {number} userId - System User ID.
* @returns {Promise<void>}
*/
public async signUpConfirmResend() {
const user = await this.tenancyContext.getSystemUser();
// Throw error if the user is already verified.
if (user.verified) {
throw new ServiceError(ERRORS.USER_ALREADY_VERIFIED);
}
// Throw error if the verification token is not exist.
if (!user.verifyToken) {
throw new ServiceError(ERRORS.USER_ALREADY_VERIFIED);
}
// Triggers `signUpConfirmResended` event.
await this.eventPublisher.emitAsync(events.auth.signUpConfirmResended, {
user,
} as ISignUpConfigmResendedEventPayload);
}
}