I want to make secure role based API , but in route.ts file session comes as undefined
import { auth } from '@/auth';
import { currentUser } from '@/lib/auth';
import { db } from '@/lib/db';
import { NextResponse } from 'next/server';
export const POST = auth(async (req) => {
const user = await currentUser();
console.log(user) // undefined
// if user.role is admin then fetch the data
const { shopId } = await req.json();
const products = await db.product.findMany({
where: {
shopId,
},
});
return NextResponse.json({
products,
});
});
I want to make secure role based API , but in route.ts file session comes as undefined