using @supabase/ssr clients with nextjs #21303
|
I'm currently going through the server-side auth guide for Next.js, and was hoping someone could help me understand something. When mutating data from a client component, what is the difference between using the ssr package's createBrowserClient and calling a server action that uses createServerClient? When should I be using each? |
Replies: 1 comment 3 replies
|
Depends on whether you want to run the code on the client or server! (Pretty much the same question you have with any event handler in Next.js App Router.) If you're doing something like a realtime subscription to track cursor positions on some kind of collaboration app, that's a pretty clear use case for running the code on the client. If you're making a request for data and you need to do a lot of data manipulation to get it in a renderable form, that's possibly an argument for running the code on the server. Then there are a lot of in-between cases, it depends on exactly what you're trying to do and what performance trade-offs you need to make. (Client code runs on the user's browser and can lead to janky interactions if it hogs the main thread, but there's no network time, aside from the time needed to call Supabase. Server code runs on the server so less JS shipped to the client and less work in the browser, but you have to account for the extra network hop to the server.) |
Depends on whether you want to run the code on the client or server! (Pretty much the same question you have with any event handler in Next.js App Router.)
If you're doing something like a realtime subscription to track cursor positions on some kind of collaboration app, that's a pretty clear use case for running the code on the client.
If you're making a request for data and you need to do a lot of data manipulation to get it in a renderable form, that's possibly an argument for running the code on the server.
Then there are a lot of in-between cases, it depends on exactly what you're trying to do and what performance trade-offs you need to make. (Client code runs on the user's browser a…