Skip to content

When using the auth wrapper or session in route handlers, it is returning as undefined #39

Description

@Honey0908

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,
    });
  }); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions