App router and trouble getting session in API route with named exports (GET,POST..etc) NextAuth v5
Unanswered
Long-horned bees posted this in #help-forum
Long-horned beesOP
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?')
}
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?')
}