added zod for post requests

This commit is contained in:
daniel31x13
2024-09-14 16:00:19 -04:00
parent a5b1952e0d
commit 1cf7421b76
24 changed files with 350 additions and 180 deletions
+7 -9
View File
@@ -1,6 +1,7 @@
import { prisma } from "@/lib/api/db";
import type { NextApiRequest, NextApiResponse } from "next";
import bcrypt from "bcrypt";
import { ResetPasswordSchema } from "@/lib/shared/schemaValidation";
export default async function resetPassword(
req: NextApiRequest,
@@ -13,20 +14,17 @@ export default async function resetPassword(
"This action is disabled because this is a read-only demo of Linkwarden.",
});
const token = req.body.token;
const password = req.body.password;
const dataValidation = ResetPasswordSchema.safeParse(req.body);
if (!password || password.length < 8) {
if (!dataValidation.success) {
return res.status(400).json({
response: "Password must be at least 8 characters.",
response: `Error: ${
dataValidation.error.issues[0].message
} [${dataValidation.error.issues[0].path.join(", ")}]`,
});
}
if (!token || typeof token !== "string") {
return res.status(400).json({
response: "Invalid token.",
});
}
const { token, password } = dataValidation.data;
// Hashed password
const saltRounds = 10;