mirror of
https://github.com/shadcn-ui/taxonomy
synced 2026-05-24 09:48:32 +00:00
16 lines
483 B
TypeScript
16 lines
483 B
TypeScript
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next"
|
|
import { unstable_getServerSession } from "next-auth/next"
|
|
|
|
import { authOptions } from "@/lib/auth"
|
|
|
|
export function withAuthentication(handler: NextApiHandler) {
|
|
return async function (req: NextApiRequest, res: NextApiResponse) {
|
|
const session = await unstable_getServerSession(req, res, authOptions)
|
|
|
|
if (!session) {
|
|
return res.status(403).end()
|
|
}
|
|
|
|
return handler(req, res)
|
|
}
|
|
}
|