is it bad pattern to create two supabase clients on serverside ? #21027
-
Hello, I make some network calls to my serverside and I use the supabase client on serverside. Now I have seen I can create admin account and saw this tutorial snippet:
So when a user makes a network call and the token is expired do I got an error ? Should I create two supabase client ? supabaseUserClient and supabaseAdminClient
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
Not really clear what you are seeking to do. It is normal to have a client on the server for user calls (normally using something like ssr/auth-helpers). You can also have a client for service_role like your first image. If you want your user client and not using ssr/auth-helpers then you would have a client with anon key and have to set the authorization header in create client with a user jwt. If the token expires for a user jwt then you will get an error. |
Beta Was this translation helpful? Give feedback.
Seems like you want to look at ssr/auth-helpers. https://supabase.com/docs/guides/auth/server-side/overview
If you have browser/app and server code then it is complicated to keep all clients in sync as far as expiring jwt's and logging in.
You can't pass a session to server side code and refresh it there if you don't then pass the session back to the client. Two clients cannot refresh the same jwt.