auth-helpers icon indicating copy to clipboard operation
auth-helpers copied to clipboard

User is null in nextjs api route handler

Open muezz opened this issue 8 months ago • 5 comments

Bug report

  • [ ] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I have set up auth with google in my project and it is working fine. I have set up the middleware and all the createClient functions for server and client. I have the correct auth state in both the server and the client.

But in API route handlers, I get user as null even though I am logged in.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Start a new Nextjs project.
  2. Follow the docs to implement auth with the ssr package.
  3. Sign in
  4. Call an API endpoint where you call getSession()

Expected behavior

I should get the session info of the current user.

System information

  • OS: macOS
  • Browser: Arc
  • Version of supabase-js: 2.43.5
  • Version of supabase/ssr: 0.3.0
  • Version of Node.js: 20.12.2

Additional context

I think the problem is happening because cookies are not being passed to the route handler. But I think they should be passed automatically through the middleware. Why is that not happening?

muezz avatar Jun 20 '24 11:06 muezz