fix token issue

This commit is contained in:
Igor Hrenowitsch Propisnov 2024-09-09 09:32:43 +02:00
parent 8a1089ce9d
commit c9a8e9967a
1 changed files with 10 additions and 15 deletions

View File

@ -88,24 +88,19 @@ export class EmailVerificationService {
emailToVerify: string emailToVerify: string
): Promise<SuccessDto> { ): Promise<SuccessDto> {
try { try {
const findTokenAndEmail: EmailVerification | null = const token = await this.emailVerifyRepository.findByTokenAndEmail(
await this.emailVerifyRepository.findValidVerification(
tokenToVerify, tokenToVerify,
emailToVerify emailToVerify
); );
if (!findTokenAndEmail) { if (!token) {
const expiredToken =
await this.emailVerifyRepository.findByTokenAndEmail(
tokenToVerify,
emailToVerify
);
if (expiredToken) {
throw new TokenExpiredException(); throw new TokenExpiredException();
} }
return { success: false }; const currentDate = new Date();
if (token.expiresAt.getTime() < currentDate.getTime()) {
throw new TokenExpiredException();
} }
await this.emailVerifyRepository.removeEmailVerificationByTokenAndEmail( await this.emailVerifyRepository.removeEmailVerificationByTokenAndEmail(