DEV Community

Discussion on: Protected Routes with Supabase and Next.js

Collapse
 
fb profile image
Franz Bewerunge • Edited

Excellent Article!

However, are you sure this is still up to date? I always receive an empty user object when I call this on server side in getServerSideProps:

const { user } = await supabase.auth.api.getUserByCookie(req);

Looking into the supabase discussions forum this seems to be a known issue:

github.com/supabase/supabase/issue...

Any ideas what I might be doing wrong?

Thanks!

Collapse
 
sruhleder profile image
Sebastian Ruhleder

Hi Franz 👋

That's strange indeed! For me, this still works flawlessly...

Here are some things you can check:

  • Is the supabase client you use in supabase.auth.api.getUserByCookie the one using the anon key? I'm not sure if this also works with the service key, but I'm using the "regular" Supabase client that I also use in frontend calls.
  • Is the frontend calling the updateSupabaseCookie method defined in the post? This is necessary to set the cookie and if it's never set, getUserByCookie will indeed return null.

But as the issue suggests, there might still be something wrong on Supabase's side...

Thanks for reading, and hopefully this will resolve your problem!

Best,
Sebastian