mirror of
https://github.com/shadcn-ui/taxonomy
synced 2026-05-24 01:38:28 +00:00
14 lines
398 B
TypeScript
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)
|
|
}
|
|
}
|