Created
August 29, 2022 15:18
-
-
Save KolbySisk/31742dac3c951db62a31e0bcef7c6815 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiResponse } from 'next'; | |
import * as z from 'zod'; | |
import { addUser, allowMethods, captureErrors, NextApiRequestWithUser, validateBody } from '../../middleware'; | |
import { use } from 'next-api-route-middleware'; | |
const formSchema = z | |
.object({ | |
email: z.string().email(), | |
password: z.string().min(4), | |
passwordConfirm: z.string().min(4), | |
}) | |
.refine((data) => data.password === data.passwordConfirm, { | |
message: "Passwords don't match", | |
}); | |
const handler = async (req: NextApiRequestWithUser, res: NextApiResponse<{ message: string }>) => { | |
res.status(200).json({ message: 'request was good!' }); | |
}; | |
export default use(captureErrors, allowMethods(['POST']), validateBody(formSchema), handler); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment