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.

Update route.ts

Kiran Ka17b14d36263
diff --git a/apps/web/app/api/auth/reset-password/route.ts b/apps/web/app/api/auth/reset-password/route.ts
index fa7603cc32..f0a588e5d1 100644
--- a/apps/web/app/api/auth/reset-password/route.ts
+++ b/apps/web/app/api/auth/reset-password/route.ts
@@ -1,6 +1,6 @@
import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
import { parseRequestBody, ratelimitOrThrow } from "@/lib/api/utils";
-import { hashPassword } from "@/lib/auth/password";
+import { hashPassword, validatePassword } from "@/lib/auth/password";
import { resetPasswordSchema } from "@/lib/zod/schemas/auth";
import { sendEmail } from "@dub/email";
import PasswordUpdated from "@dub/email/templates/password-updated";
@@ -46,9 +46,25 @@ export async function POST(req: NextRequest) {
},
select: {
emailVerified: true,
+ passwordHash: true,
},
});
+ // Check if the new password is the same as the current password
+ if (user.passwordHash) {
+ const isSamePassword = await validatePassword({
+ password,
+ passwordHash: user.passwordHash,
+ });
+
+ if (isSamePassword) {
+ throw new DubApiError({
+ code: "unprocessable_entity",
+ message: "New password must be different from your current password.",
+ });
+ }
+ }
+
await prisma.$transaction([
// Delete the token
prisma.passwordResetToken.deleteMany({