taxonomy/lib/api-middlewares/with-authentication.ts
2022-10-26 17:18:06 +04:00

14 lines
398 B
TypeScript

import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next"
import { getSession } from "next-auth/react"
export function withAuthentication(handler: NextApiHandler) {
return async function (req: NextApiRequest, res: NextApiResponse) {
const session = await getSession({ req })
if (!session) {
return res.status(403).end()
}
return handler(req, res)
}
}