邮箱验证码校验失败时,抛出403错误
This commit is contained in:
parent
7e5a1c589d
commit
faf34c241b
@ -68,11 +68,16 @@ export class EmailService {
|
|||||||
return { token, userId: user?.id }
|
return { token, userId: user?.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: 邮箱使用缓存而不是jwt来验证正确性和时效性,校验成功后要让验证码失效。set-cookie而不是在body返回?
|
||||||
async verifyEmailCode(data: EmailVerifycationDto) {
|
async verifyEmailCode(data: EmailVerifycationDto) {
|
||||||
const { token, verifyCode, email, scene } = data
|
const { token, verifyCode, email, scene } = data
|
||||||
const payload = this.jwtService.verify<EmailSendDto>(token, {
|
const payload = await this.jwtService
|
||||||
secret: this.getEmailJwtSecret(verifyCode, scene),
|
.verifyAsync<EmailSendDto>(token, {
|
||||||
})
|
secret: this.getEmailJwtSecret(verifyCode, scene),
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
throw new ForbiddenException(err.message)
|
||||||
|
})
|
||||||
if (payload.email !== email || payload.scene !== scene) {
|
if (payload.email !== email || payload.scene !== scene) {
|
||||||
throw new ForbiddenException('邮箱验证码验证失败')
|
throw new ForbiddenException('邮箱验证码验证失败')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user