I’m encountering an issue with authentication in Next.js API routes when using NextAuth.I’m trying to secure my API routes so that only authenticated users can access them. However, it’s return undefined with auth wrapper or session

`import { auth } from “../../auth”

export const POST = auth((req) => {
// req.auth — undefined


`export const POST = async (req) => {
const user = await session();
console.log(user) // undefined


I also tried getting token inside routes but it is also not working
so I want better way how can I make secure API routes for role based scenarios using token or session.

New contributor

Honey Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.