Open
Description
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
I'm building an in-app chat for my application. Chat works fine when the channel is public. But, I can't seem to get it working when I tried making the channels private.
Here's my frontend code:
// utils/supabase/client.ts
import { createBrowserClient } from "@supabase/ssr";
export const createClient = () =>
createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
);
// chat.tsx
"use client";
import { createClient } from "@/utils/supabase/client";
// truncated
export default function Chat(/* truncated */) {
// truncated
const supabase = createClient();
React.useEffect(() => {
supabase.auth.getSession().then((resp) => {
supabase.realtime.setAuth(resp?.data?.session?.access_token || null);
const ws = supabase.channel(chatRoomUuid, { config: { private: true } });
ws.on("broadcast", { event: "message" }, ({ event, type, payload }) => {
if (payload.userId !== user.id) {
setMessages((messages) => [...messages, payload as Message]);
}
}).subscribe((state, err) => console.log("Sub ", state, err));
return () => {
ws.unsubscribe().then((resp) => console.log("Unsub ", resp));
};
});
}, []);
// truncated
I got the following log in the console:
Sub CHANNEL_ERROR Error: "You do not have permissions to read from this Topic"
at Object.eval [as callback] (RealtimeChannel.js:168:47)
<truncated>
As you can see, it's a simple RLS. Even then, I'm getting a CHANNEL_ERROR
. The connection would succeed if I remove FROM chat_room_members
in the RLS policy. For some unknown reason, querying from any table in the policy fails the connection. What's happening?
I combed over docs, github discussions, github issues, and now Discord and I couldn't find anything. Am I missing something obvious here?
Expected behavior
SUBSCRIBED
instead of CHANNEL_ERROR
System information
- OS: Ubuntu 22.04
- Browser: Chrome
- Version of supabase/ssr: 0.4.0
- Version of realtime-js: 2.10.2