Description
Bug report
Description
Using a custom JWT was a feature in v1 :
https://supabase.com/docs/reference/javascript/auth-setauth
Per comment:
supabase/auth-js#340 (comment)
what we did was establish the custom header and it works for creating the client.
However, it's not working with realtime channels. Upon inspection, the problem is that the internal initialization isn't setting up RealtimeClient's setAuth method:
https://github.com/supabase/realtime#realtime-rls
which in turn causes the web socket to not send the JWT on the messages and heartbeats..
The result is that channels fail the RLS.
A second problem is with setting up a new valid JWT when the previous one expired: there's no way to do it. Not in the supabase client and much less in the realtime client.
To Reproduce
- Create a database with a restrictive policy based on a custom JWT
- Create a JWT with a 1 minute expiration time
- Create a client using the method explained in
feat: remove deprecated session methods auth-js#340 (comment)
4.a. Let 2 minutes go by and try to make any call to supabase using supabaseClient. Access is denied because the JWT has expired. Try to update the JWT -> there's no way to do it. Would have to create a new client but that defeats the whole thing.
4.b. Create a channel subscription -> 'fails' by not providing access to rows to which the user has access acording to the policy)
Upon inspection of the websocket, as it was expected, the messages and heartbeats don't include the custom JWT.. Why whould they? We've only set the header /directly/ and that's it..
Workaround
What we've done is changing from protected to public the supabase client's class elements:
"headers" in SupabaseClient
"realtime" in GoTrueClient
and we're calling
a) supabaseClient.realtime.setAuth(JWT)
b) supabase.auth.headers.Authorization = Bearer ${JWT}
;
with the customToken..
That keeps everything working..
Tried forking and creating an updateJWT method, but realized we're not very familiar with the modularization philosophy of the project and was most likely being both overkill about it. Also, were falling short because an alternate method is quite likely required for the initialization, since using the headers option in the createClient doesn't impact the realtime client.