How do I get the current session from a NextJS 13.4 API Handler?
Unanswered
Bighead carp posted this in #help-forum
Bighead carpOP
I have a client-side component (A component using 'use client'), which needs to send a request to /api/projects/create. The project is set up with Prisma and NextAuth.js. How do I get the current user object inside the API handler (server side), when the request is from the client side.
When I use getServerSession, it always returns null.
When I use getServerSession, it always returns null.
2 Replies
@Bighead carp I have a client-side component (A component using 'use client'), which needs to send a request to /api/projects/create. The project is set up with Prisma and NextAuth.js. How do I get the current user object inside the API handler (server side), when the request is from the client side.
When I use getServerSession, it always returns null.
Southern rough shrimp
did u tried using normal useSession
I just let u know how to debug it.
open chrome dev tool > network, locate /api/projects/create.
from the context menu, copy cURL command
open a terminal paste it.
make sure there is an auth.js session cookie.
run it.
plus, use debuger to set a break point in api and authOptions, so you can reveal what values are set there.
open chrome dev tool > network, locate /api/projects/create.
from the context menu, copy cURL command
open a terminal paste it.
make sure there is an auth.js session cookie.
run it.
plus, use debuger to set a break point in api and authOptions, so you can reveal what values are set there.