third commit
This commit is contained in:
@@ -19,6 +19,11 @@ export class VerificationService {
|
||||
}
|
||||
|
||||
async sendEmailCode(email: string): Promise<void> {
|
||||
await this.prisma.verificationCode.updateMany({
|
||||
where: { target: email, usedAt: null, expiresAt: { gt: new Date() } },
|
||||
data: { usedAt: new Date() },
|
||||
});
|
||||
|
||||
const code = this.generateCode();
|
||||
await this.prisma.verificationCode.create({
|
||||
data: {
|
||||
@@ -30,10 +35,18 @@ export class VerificationService {
|
||||
},
|
||||
});
|
||||
await this.mailService.sendCode(email, code, 'AUTH');
|
||||
this.logger.info({ email }, 'Email verification code sent');
|
||||
this.logger.info(
|
||||
{ target: email, channel: 'email' },
|
||||
'Verification code sent',
|
||||
);
|
||||
}
|
||||
|
||||
async sendPhoneCode(phone: string): Promise<void> {
|
||||
await this.prisma.verificationCode.updateMany({
|
||||
where: { target: phone, usedAt: null, expiresAt: { gt: new Date() } },
|
||||
data: { usedAt: new Date() },
|
||||
});
|
||||
|
||||
const code = this.generateCode();
|
||||
await this.prisma.verificationCode.create({
|
||||
data: {
|
||||
@@ -44,7 +57,10 @@ export class VerificationService {
|
||||
expiresAt: new Date(Date.now() + 5 * 60 * 1000),
|
||||
},
|
||||
});
|
||||
this.logger.info({ phone }, 'SMS verification code would be sent (mock)');
|
||||
this.logger.info(
|
||||
{ target: phone, channel: 'sms' },
|
||||
'Verification code would be sent (mock)',
|
||||
);
|
||||
}
|
||||
|
||||
async verifyCode(target: string, code: string): Promise<boolean> {
|
||||
@@ -59,6 +75,10 @@ export class VerificationService {
|
||||
});
|
||||
|
||||
if (!record) {
|
||||
await this.prisma.verificationCode.updateMany({
|
||||
where: { target, usedAt: null, expiresAt: { gt: new Date() } },
|
||||
data: { usedAt: new Date() },
|
||||
});
|
||||
throw new BadRequestException('Invalid or expired code');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user