Skip to content

Commit

Permalink
compact useVerificationToken
Browse files Browse the repository at this point in the history
  • Loading branch information
Soxasora committed Jan 20, 2025
1 parent 93fd630 commit f727693
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions pages/api/auth/[...nextauth].js
Original file line number Diff line number Diff line change
Expand Up @@ -336,27 +336,27 @@ export const getAuthOptions = (req, res) => ({
}
})

if (verificationRequest) {
if (verificationRequest.token === token) { // if correct delete the token and continue
await prisma.verificationToken.delete({
where: { id: verificationRequest.id }
})
return verificationRequest
} else { // increment attempts if incorrect
const newAttempts = verificationRequest.attempts + 1

if (newAttempts > 3) { // the moment the user has tried 3 times, delete the token
await prisma.verificationToken.delete({
where: { id: verificationRequest.id }
})
} else { // otherwise, just increment the failed attempts
await prisma.verificationToken.update({
where: { id: verificationRequest.id },
data: { attempts: newAttempts }
})
}
}
if (!verificationRequest) return null

if (verificationRequest.token === token) { // if correct delete the token and continue
await prisma.verificationToken.delete({
where: { id: verificationRequest.id }
})
return verificationRequest
}

const newAttempts = verificationRequest.attempts + 1
if (newAttempts > 3) { // the moment the user has tried 3 times, delete the token
await prisma.verificationToken.delete({
where: { id: verificationRequest.id }
})
} else { // otherwise, just increment the failed attempts
await prisma.verificationToken.update({
where: { id: verificationRequest.id },
data: { attempts: newAttempts }
})
}

return null
}
},
Expand Down

0 comments on commit f727693

Please sign in to comment.