Last active
June 9, 2021 23:46
-
-
Save diasjuniorr/1b6707ed2fff505a68af784749d18560 to your computer and use it in GitHub Desktop.
Next.js middleware implementation
This file contains hidden or 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
// pages/api/endpointGet.ts | |
import { auth } from "../util/middleware/auth" | |
// so we can add the user info to the req object | |
type NextApiRequestWithUser = NextApiRequest & { | |
user: string | |
} | |
const handler = async (req: NextApiRequestWithUser, res: NextApiResponse) => { | |
const { method, headers, query, user } = req | |
if (method === 'GET') { | |
console.log("inside the handler") | |
return res.status(200).json({ok: true}) | |
} | |
res.setHeader('Allow', ['GET']) | |
return res.status(405).end(`Method ${method} Not Allowed`) | |
} | |
export default auth(handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment