feature/refactor-login #19
|
@ -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(
|
||||||
|
|
Loading…
Reference in New Issue