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
+8 -3
View File
@@ -1,5 +1,6 @@
import { prisma } from "@/lib/api/db";
import updateCustomerEmail from "@/lib/api/updateCustomerEmail";
import { VerifyEmailSchema } from "@/lib/shared/schemaValidation";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function verifyEmail(
@@ -13,14 +14,18 @@ export default async function verifyEmail(
"This action is disabled because this is a read-only demo of Linkwarden.",
});
const token = req.query.token;
const dataValidation = VerifyEmailSchema.safeParse(req.query);
if (!token || typeof token !== "string") {
if (!dataValidation.success) {
return res.status(400).json({
response: "Invalid token.",
response: `Error: ${
dataValidation.error.issues[0].message
} [${dataValidation.error.issues[0].path.join(", ")}]`,
});
}
const { token } = dataValidation.data;
// Check token in db
const verifyToken = await prisma.verificationToken.findFirst({
where: {