Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

remove existing otps while creating new one

Kiran K3d42c6a6f34e
diff --git a/apps/web/lib/actions/resend-otp.ts b/apps/web/lib/actions/resend-otp.ts
index 2a51b1fbe1..a6c5f6c042 100644
--- a/apps/web/lib/actions/resend-otp.ts
+++ b/apps/web/lib/actions/resend-otp.ts
@@ -41,16 +41,23 @@ export const resendOtpAction = actionClient
throw new Error("An user with this email does not exist.");
}
- // Generate the OTP
const code = generateOTP();
- await prisma.emailVerificationToken.create({
- data: {
- identifier: email,
- token: code,
- expires: new Date(Date.now() + EMAIL_OTP_EXPIRY_IN * 1000),
- },
- });
+ await Promise.all([
+ prisma.emailVerificationToken.deleteMany({
+ where: {
+ identifier: email,
+ },
+ }),
+
+ prisma.emailVerificationToken.create({
+ data: {
+ identifier: email,
+ token: code,
+ expires: new Date(Date.now() + EMAIL_OTP_EXPIRY_IN * 1000),
+ },
+ }),
+ ]);
// Send email with generated OTP
await sendEmail({