Unable to resubscribe to a channel after unsubscribe
When using private broadcast channels, resubscribing to the same channel topic after calling removeChannel() fails with an authorization error, even though the user's session and permissions remain unchanged.
Here is a minimal reproduction code :
Logs observed
Any idea why I get this behavior? I can share my RLS if it can help.
Here is a minimal reproduction code :
if (supabase == null) return;
console.log("sub to conversation");
// Step 1: Initial subscription - SUCCESS
const channel1 = supabase
.channel("conversation:dc3fb8c1-ceef-4c00-9f92-e496acd03593", {
config: { private: true },
})
.on("broadcast", { event: "INSERT" }, (payload) => {
console.log("Message received:", payload);
})
.subscribe((status, error) => {
console.log("Status:", status); // â
"SUBSCRIBED"
});
// Step 2: Wait and cleanup
await new Promise((resolve) => setTimeout(resolve, 5000));
console.log("unsub to conversation");
await supabase.removeChannel(channel1);
// Step 3: Wait for cleanup
await new Promise((resolve) => setTimeout(resolve, 5000));
// Step 4: Resubscribe to same topic - FAILS
console.log("resub to conversation");
const channel2 = supabase
.channel("conversation:dc3fb8c1-ceef-4c00-9f92-e496acd03593", {
config: { private: true },
})
.on("broadcast", { event: "INSERT" }, (payload) => {
console.log("Message received:", payload);
})
.subscribe((status, error) => {
console.log("Status:", status); // â "CHANNEL_ERROR"
console.log("Error:", error); // â "Unauthorized: You do not have permissions..."
}); if (supabase == null) return;
console.log("sub to conversation");
// Step 1: Initial subscription - SUCCESS
const channel1 = supabase
.channel("conversation:dc3fb8c1-ceef-4c00-9f92-e496acd03593", {
config: { private: true },
})
.on("broadcast", { event: "INSERT" }, (payload) => {
console.log("Message received:", payload);
})
.subscribe((status, error) => {
console.log("Status:", status); // â
"SUBSCRIBED"
});
// Step 2: Wait and cleanup
await new Promise((resolve) => setTimeout(resolve, 5000));
console.log("unsub to conversation");
await supabase.removeChannel(channel1);
// Step 3: Wait for cleanup
await new Promise((resolve) => setTimeout(resolve, 5000));
// Step 4: Resubscribe to same topic - FAILS
console.log("resub to conversation");
const channel2 = supabase
.channel("conversation:dc3fb8c1-ceef-4c00-9f92-e496acd03593", {
config: { private: true },
})
.on("broadcast", { event: "INSERT" }, (payload) => {
console.log("Message received:", payload);
})
.subscribe((status, error) => {
console.log("Status:", status); // â "CHANNEL_ERROR"
console.log("Error:", error); // â "Unauthorized: You do not have permissions..."
});Logs observed
LOG sub to conversation
LOG Status: SUBSCRIBED
LOG unsub to conversation
LOG Status: CLOSED
LOG resub to conversation
LOG Status: CHANNEL_ERROR
LOG Error: [Error: "Unauthorized: You do not have permissions to read from this Channel topic: conversation:dc3fb8c1-ceef-4c00-9f92-e496acd03593"] LOG sub to conversation
LOG Status: SUBSCRIBED
LOG unsub to conversation
LOG Status: CLOSED
LOG resub to conversation
LOG Status: CHANNEL_ERROR
LOG Error: [Error: "Unauthorized: You do not have permissions to read from this Channel topic: conversation:dc3fb8c1-ceef-4c00-9f92-e496acd03593"]Any idea why I get this behavior? I can share my RLS if it can help.