Next.js Discord

Discord Forum

NextAuth v5-beta in App Router API, not being able to get session with auth()

Unanswered
Long-horned bees posted this in #help-forum
Open in Discord
Avatar
Long-horned beesOP
I am testing the new next 14 with app router and react 18 and nextauth v5-beta.

I want to do an aditional check inside middleware that sets up a azure TableClient and fetches some data inside azure table to verify agains some claims.

Now because of edge runtime i cant run that function with TableClient directly in middleware. So i am creating an api route to run that check instead, and calling that API from the middleware. Now, i would like to get the session inside the API. but i cant seem to get the desired information from auth(req,res).

Its the new named exports with GET, POST etc and not the regular handler like in the examples online. Does that matter?

Looks something like this inside app/api/auth/authorize/route.ts :

export async function GET(req: NextApiRequest, res: NextApiResponse) {
const session = await auth(req, res)
console.log(session, 'session?')
}

0 Replies