Please help me to configure my Postgresql policies so that insert events and update events from my todos table can be broadcasted to authenticated users. #38978
-
I have the following code on my client: supabase.channel("custom-all-channel").on(
"postgres_changes", {
event: "*",
schema: "public",
table: "todos",
},
(payload) => {
console.log("The event is ", payload.eventType);
).subscribe((status, error) => {
console.log("The status is", status);
console.log("Error is ", error);
}); These are the policies that I have on my todos table. [
{
"schemaname": "public",
"tablename": "todos",
"policyname": "Enable users to view their own data only",
"permissive": "PERMISSIVE",
"roles": "{authenticated}",
"cmd": "SELECT",
"qual": "(( SELECT auth.uid() AS uid) = user_id)",
"with_check": null
},
{
"schemaname": "public",
"tablename": "todos",
"policyname": "Enable users to update their own data only",
"permissive": "PERMISSIVE",
"roles": "{authenticated}",
"cmd": "UPDATE",
"qual": "(( SELECT auth.uid() AS uid) = user_id)",
"with_check": null
},
{
"schemaname": "public",
"tablename": "todos",
"policyname": "Enable delete for users based on user_id",
"permissive": "PERMISSIVE",
"roles": "{authenticated}",
"cmd": "DELETE",
"qual": "(( SELECT auth.uid() AS uid) = user_id)",
"with_check": null
},
{
"schemaname": "public",
"tablename": "todos",
"policyname": "Enable insert for authenticated users only",
"permissive": "PERMISSIVE",
"roles": "{authenticated}",
"cmd": "INSERT",
"qual": null,
"with_check": "(( SELECT auth.uid() AS uid) = user_id)"
}
]
My client can only recieve DELETE events when row level security is enabled. However, it can recieve INSERT events and UPDATE events as well when row level security is disabled. So, I'm sure there is something wrong with my row level security policies that doesn't allow authenticated users to listen to INSERT events or UPDATE events. Please give me the code for the row level security policies so that authenticated users can listen to INSERT events and UPDATE events as well. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Try adding realtime.setAuth() before your .on() call and after your set up the client with channel. ![]() If this solves it please report back. |
Beta Was this translation helpful? Give feedback.
Try adding realtime.setAuth() before your .on() call and after your set up the client with channel.
There have been reports of issues since supabase-js 2.54.
If this solves it please report back.