Created
August 29, 2022 14:48
-
-
Save KolbySisk/5223aff65f4936e9aba3e34752478fb6 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 { 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