Skip to content

Instantly share code, notes, and snippets.

@KolbySisk
Created August 29, 2022 14:48
Show Gist options
  • Save KolbySisk/5223aff65f4936e9aba3e34752478fb6 to your computer and use it in GitHub Desktop.
Save KolbySisk/5223aff65f4936e9aba3e34752478fb6 to your computer and use it in GitHub Desktop.
import type { NextApiRequest, NextApiResponse } from 'next';
type User = { userId: string };
const allowedMethods = ['GET'];
const handler = (req: NextApiRequest, res: NextApiResponse<User>) => {
// If the req.method isn't included in the list of allowed methods we return a 405
if (!allowedMethods.includes(req.method!) || req.method == 'OPTIONS') {
return res.status(405).send({ message: 'Method not allowed.' });
}
return res.status(200).json({ userId: 'abc123' });
};
export default handler;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment