Hello guys. I don't know if this is the right chan...
# javascript
m
Hello guys. I don't know if this is the right channel but, i was searching a lot of how to make requests on the server as a particular user, and found a way so you can use the RLS errors.
Copy code
js
const supabase = createClient(supabaseurl, anon)
const jwt = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNjI4MDA0MTczLCJzdWIiOiI5ZmNkN2VmYi1lOTBmLTRlYWUtYmJhNS0zYzAxMDMwMDg5ZGMiLCJlbWFpbCI6Im1paGFpLmFuZHJlaSsyQG1vZGV4LnRlY2giLCJwaG9uZSI6IiIsImFwcF9tZXRhZGF0YSI6eyJwcm92aWRlciI6ImVtYWlsIn0sInVzZXJfbWV0YWRhdGEiOnt9LCJyb2xlIjoiYXV0aGVudGljYXRlZCJ9.OTJ89KjBMcbVI5d-ll4YZl7pyUr8tkUdwQkEht-clnc"
supabase.auth.setAuth(jwt);
You just need to call supabase.auth.setAuth(jwt).
b
This is cool! So how are you getting the
jwt
in this case?
m
I’m using the supabase also on the client. Get the session there and send the token to the server, and query on the server
b
ah, got it. cool
s
Note that the token will probably expire after 1 hour, so you will need to get a new token at that point, the client does this automatically because there is a refresh token
m
Good observation. I think if you use the client on the frontend, and on each request you get the session with: const session = supabase.auth.session() and Take the token from there before sending it to your custom server, it will still autorefresh for you
Didnt test it yet, But i need to try it