supabase: Realtime Subscriptions No Longer Working Locally With Custom JWT
Bug report
Describe the bug
Local subscriptions are not working with the provided “self-hosted” docker-compose.yml
, even though replication is enabled on all tables.
To Reproduce
- Clone this repo
- Run the local docker-compose setup as is described in the documentation, including ENV var setup
- Realtime subscriptions (from js client) succeed – but are not broadcasted.
Expected behavior
Realtime subscriptions should broadcast correctly.
Screenshots
If applicable, add screenshots to help explain your problem.
System information
- OS: macOS
- Browser: chrome
- Version of supabase-js: “@supabase/supabase-js”: “^1.33.3”,
- Version of Node.js: 16.7.0
Additional context
- I dug through the logs for realtime, and was able to confirm that it was trying to subscribe to the things I was asking it for from the frontend.
- I couldn’t see any evidence of failures in the Realtime logs. However, I also wasn’t able to see any evidence of successful subscriptions at the postgres-level when I audited the postgres database using techniques here: https://dba.stackexchange.com/questions/224490/using-postgresql-logical-replication-how-do-you-know-that-the-subscriber-is-cau
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 32 (23 by maintainers)
Okay, this solved it!
Users from the future;
role: "anon"
field to it at leastThanks!
@w3b6x9 no problem! Nice work on Realtime btw, been digging through the elixir and enjoying it.
As an aside, I added this tiny PR to the Realtime repo which was helpful when I was debugging my local build. Not sure how interested in it you’d be: https://github.com/supabase/realtime/pull/248
From this context I was able to cobble together a bash script which seems to fix the issue for me, even if it’s an extremely ghetto hack.
I am running this after the local supabase environment is created.
It looks like the realtime container attempts to create the schema, its tables, its functions, types etc. on start up (if they don’t exist?), so remaking the realtime schema in the database and then restarting the realtime container seems to fix the issue.
I know this is not the exact same issue as described by OP, but I just wanted to document it here just in case anyone stumbles across the similar issue described, but the solutions don’t work:
I was on all of the latest versions of the CLI, javascript client, etc., with replications and realtime enabled on all tables (including ones without any RLS, just for debugging this) and realtime was only failing locally (my cloud Supabase project, which is an exact replica schema-wise, worked perfectly). Based on @tg44 's advice (“check the realtime schema subscription table”), I went to locate this table, and for some reason, my local supabase
realtime
schema had no tables. Runningsupabase db reset
did nothing to solve the issue; stopping (supabase stop
) and then re-starting (supabase start
) the local instance did not help either.Ultimately, I stopped the running local supabase in the project that I was in (
supabase stop
) and moved to a completely empty directory, fired offsupabase init
and thensupabase start
. I noticed that after doing this, now with a completely blank project, therealtime
schema was no longer empty and had thesubscription
table (as it should). The really odd thing is that I returned to the old project where this bug was occurring, and everything works like normal again, including realtime.In case anyone stumbles across this thread while chasing down the rabbit hole, ^ helped me to solve the issue. I think the hard reset must have fixed things.
@tg44 you saved our day 🥳
Ah, your checklist did the trick!!! I did not realize the importance of the role field. Makes perfect sense in retrospect.
Thanks so much for your help / patience.
@Marviel Thanks for reporting this issue! I’ll investigate shortly and post here with my findings.