Supabase SSR / Right way to implement Server Component client
Hey folks,
I'm working on setting up Supabase clients in my NextJS 14 project using Supabase SSR for auth. I'm using middleware to refresh sessions as recommended. I've encountered confusion with different recommendations for server and server component client implementations:
1) Official example for creating a server component, it drops every exception during set and remove, only uses get. (https://github.com/vercel/next.js/blob/canary/examples/with-supabase/utils/supabase/server.ts)
2) Supabase ssr docs, server component client only implements get method, doesn't implement anything else. Server actions client, on the other hand, has all the cookie related methods implemented. (https://supabase.com/docs/guides/auth/server-side/creating-a-client?environment=server-component)
I initially used #1, and it worked fine. However, as I explore #2, it seems like it should work, but it doesn't. #2 throws exceptions saying server components cant set cookies.
Dropping the errors is concerning to me in case I do something wrong without even realizing.
Can someone help me understand what's going on?
-Who is trying to set cookies for server component clients? (I tried to debug but it only goes up to SupabaseAuthClient)
-Why is supabase server client example dropping exceptions ok for middleware refresh case?
GitHub
next.js/examples/with-supabase/utils/supabase/server.ts at canary ·...
The React Framework. Contribute to vercel/next.js development by creating an account on GitHub.
Creating a Supabase client for SSR | Supabase Docs
Configure Supabase client to use Cookies
3 Replies
Sorry to not have an answer, I'm just as confused as you. The docs and examples are a mess right now. I'm trying to build a new next 14 app too and I'm on the verge of giving up and moving to something else for auth/data
Same here - considering giving up on Supabase. The documentation is pretty lacking or confusing...
hey, a bit late since I've joined the discord today, but check out this video: https://youtu.be/XIj7nmIYtbo?si=Bwx8Th5MR9i5IaD3. I think it will help you a lot, like it helped me 😄
activenode
YouTube
Understand the Supabase SSR Package easily
Sure, you can read the docs - but aren't you confused about it? Get a full-fledged, detailed explanation which removes all future barriers.
About the info Box in the video:
I use the same Client for Server Components, Route Handlers and Server Actions with NextJS App Router without the differentiating in set/remove;
Because: I want to make sur...