Skip to content

Instantly share code, notes, and snippets.

@KolbySisk
Created August 29, 2022 15:18
Show Gist options
  • Save KolbySisk/31742dac3c951db62a31e0bcef7c6815 to your computer and use it in GitHub Desktop.
Save KolbySisk/31742dac3c951db62a31e0bcef7c6815 to your computer and use it in GitHub Desktop.
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