#App router and trouble getting session in API route with named exports (GET,POST..etc) NextAuth v5

2 messages · Page 1 of 1 (latest)

spring kayak
#

I am using the new app router, next 14 and react 18 and nextauth-v5 beta.

In the new way to setup api endpoints is with named exports like GET and POST.
Now trying to get the user session inside here is not working. The session object is not containing the expected values. I can find cookie in there but its not what i was hoping for. Am i doing something wrong or any other solutions?

I am calling from the middleware because i want to do a authorization check agains azure table storage, which require TableClient from azure. Now i cant run this function directly in the middleware because of edge runtime, so i thought i work around that and do it in the api instead. Now i can get the desired info from req.user inside the middleware and pass it in the body of the request. I was just really hoping not to do it that way, and get it on the server instead

I am trying something like this:

import { auth } from '@/auth'
import { NextApiRequest, NextApiResponse } from 'next'

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

somber tigerBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)