mirror of
https://github.com/shadcn-ui/taxonomy
synced 2026-05-24 09:48:32 +00:00
refactor: prevent double session call in api route
This commit is contained in:
parent
cef699ab70
commit
eeb2699fea
1 changed files with 7 additions and 3 deletions
|
|
@ -4,7 +4,6 @@ import { unstable_getServerSession } from "next-auth/next"
|
|||
|
||||
import { db } from "@/lib/db"
|
||||
import { withMethods } from "@/lib/api-middlewares/with-methods"
|
||||
import { withAuthentication } from "@/lib/api-middlewares/with-authentication"
|
||||
import { getUserSubscriptionPlan } from "@/lib/subscription"
|
||||
import { RequiresProPlanError } from "@/lib/exceptions"
|
||||
import { authOptions } from "@/lib/auth"
|
||||
|
|
@ -16,7 +15,12 @@ const postCreateSchema = z.object({
|
|||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const session = await unstable_getServerSession(req, res, authOptions)
|
||||
const user = session?.user
|
||||
|
||||
if (!session) {
|
||||
return res.status(403).end()
|
||||
}
|
||||
|
||||
const { user } = session
|
||||
|
||||
if (req.method === "GET") {
|
||||
try {
|
||||
|
|
@ -84,4 +88,4 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||
}
|
||||
}
|
||||
|
||||
export default withMethods(["GET", "POST"], withAuthentication(handler))
|
||||
export default withMethods(["GET", "POST"], handler)
|
||||
|
|
|
|||
Loading…
Reference in a new issue