Postgres Realtime when using third party auth JWT tokens #28483
Replies: 2 comments 1 reply
-
Maybe this required extra call when using a custom token with realtime. |
Beta Was this translation helpful? Give feedback.
-
I have managed to solve my issue. The solution for me was to use The missing
|
Beta Was this translation helpful? Give feedback.
-
Hello all,
The problem
I want to use the Realtime feature of Postgres with a third party auth token so I can use RLS without
anon
, but this does not appear to be working. The websocket is being generated okay, when using the client generated above. I can see system messages coming through okay but I don't get any events when I subscribe topostgres_changes
. Well, actually I just receive DELETE events, but nothing else.If I change the RLS for my Select policy to the
anon
role then come through, suggesting the realtime component is not passing my custom JWT (see below).If I inspect the websocket, I do see a message for a
access_token
event for my custom channel. The contents for this appear to contain my anon api key and not the custom JWT. But I do not know the exact nature or meaning of this event.Background
I am building a NextJs app that is making use of the Supabase client's ability to use third party auth via a generated JWT. In my case I am using PropelAuth for user management/authentication. I have got this working across all the operations I need to make in my app (select, insert, etc). Initially I used the custom header option when creating my client. For example,
More recently the feat: add third-party auth support #1004 allows me to simplify the
options
to this,Both approaches work when combined with RLS policies that target the
authenticated
role.I understand that Realtime uses the SELECT RLS policy to determine its right to transmit events. It clearly is not passing this when the role is
authenticated
but only when set toanon
which is not suitable in this case.Questions
Has anyone else got this working in the same or a similar way?
Does anyone know if I am missing something to enable the realtime component to use a third party auth JWT?
Any help or insights would be gratefully welcome.
Oh and I've I have been a complete idiot and missed the obvious, then please forgive me.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions