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 reset tokens

Kiran Ka50dbdf5bced
diff --git a/apps/web/lib/actions/request-password-reset.ts b/apps/web/lib/actions/request-password-reset.ts
index f05eda4455..f52fb73410 100644
--- a/apps/web/lib/actions/request-password-reset.ts
+++ b/apps/web/lib/actions/request-password-reset.ts
@@ -40,13 +40,23 @@ export const requestPasswordResetAction = actionClient
throw new Error("An user with this email does not exist.");
}
- const { token } = await prisma.passwordResetToken.create({
- data: {
- identifier: email,
- token: randomBytes(32).toString("hex"),
- expires: new Date(Date.now() + PASSWORD_RESET_TOKEN_EXPIRY * 1000),
- },
- });
+ const token = randomBytes(32).toString("hex");
+
+ await Promise.all([
+ prisma.passwordResetToken.deleteMany({
+ where: {
+ identifier: email,
+ },
+ }),
+
+ prisma.passwordResetToken.create({
+ data: {
+ identifier: email,
+ token,
+ expires: new Date(Date.now() + PASSWORD_RESET_TOKEN_EXPIRY * 1000),
+ },
+ }),
+ ]);
await sendEmail({
subject: `${process.env.NEXT_PUBLIC_APP_NAME}: Password reset instructions`,