After update package, realtime subscription not work.
I updated package @supabase/ssr": "^0.6.1", "@supabase/supabase-js": "^2.50.3", -> "@supabase/ssr": "^0.7.0","@supabase/supabase-js": "^2.57.4",
And then, realtime subscription not work some times when i reload pages.
But after i changed to use new 'publishable key' system from legacy anon key system. The friquency of error reduced dramatically. Why this happen?
I'm using supabase SSR.
Does it related to supabase.realtime.setAuth? Should i setAuth again while getting supabase object from +layout.ts?
21 Replies
I think there are two things going on here. For the second one make sure that the PUBLISHABLED_KEY is being used correctly like this guide states https://supabase.com/docs/guides/auth/server-side/nextjs
It may be the case that your environment variables are out of alignment in your deployment
Another user raised the first issue as a bug here https://github.com/supabase/ssr/issues/122. There is a solution suggested further down. Might be worth seeing if it helps?
So several users are having issues with supabase-js 2.54 and later.
What is fixing it is to add supabase.realtime.setAuth(user.session.access_token) before subscribing.
Not clear if the access_token is required or just setAuth() is sufficient.
https://discord.com/channels/839993398554656828/1414876335662301194/1414964273284780133
Same here just confirming this happens for broadcast.
Realtime was working fine for me but after updating to the new asym keys suddenly it stops working. You can see in the websocket it's trying to use the publishable_key
The fix unfortunately didn't work for me š
// Get the user's session token
const {
data: { session },
} = await supabase.auth.getSession();
if (!session?.access_token) {
console.error('No access token available for realtime auth');
return;
}
// Set auth with the access token
await supabase.realtime.setAuth(session.access_token);
Also try with just setAuth(). Some have had that work.
Otherwise an issue in github supabase/supabase-js or realtime-js... or support.
Oh I had await supabase.realtime.setAuth(); before lol, thanks for trying to help though. Yea will create an issue.
No use await. Just don't put the session token in.
Also log out your session token to make sure it is a real JWT. It should be of course.
Oh you mean do both, like await setAuth(), and then set session.access_token?
Tried that too, did't work. Created issue here: https://github.com/supabase/realtime/issues/1561
GitHub
Subscribing to broadcasts does not work with the new non-JWT publis...
Only tested in local. Previously I used setAuth() before subscribing and it was working await supabase.realtime.setAuth(); Now, this is what I get in console when I try to subscribe to a channel: W...
await supabase.realtime.setAuth()
Exactly that but with session.access_token not part of setAuth() Just
setAuth()
. I doubt it matters but several users did it that way to fix the issue.Sorry mate I don't really follow lol. What am I missing here
As I said I don't think it will matter, but that is the I've seen others doing it.
Oh yea I have it here: await supabase.realtime.setAuth();
I am probably not explaining myself correctly but I think I did in the bug report. So before I had "await supabase.realtime.setAuth(); " and nothing else, and it was working fine.
Then after publishable_keys, this stopped working, so I tried to add your fix of set token. Then I tried doing 2 together lol. Yea it looks like the container in Docker is expecting JWT.
So this is local... Could very well be an issue with that.
I tested publishable keys and they work on hosted.
Ah well that's good to know. I'll wait for the fix before I push to prod then. Interesting!! Although local did get publishable keys recently. I believe hosted gets stuff first and had new asym keys for a while.
Could be only part of the local version got fixed. Even on hosted right after launch there were issues with storage and the publishable keys that had to get fixed.
Thanks again for being super helpful mate. I'll keep a watch here and on my bug report to see if I can help devs debug
I have a similar issue and I've added my comment here - https://github.com/supabase/ssr/issues/122
GitHub
Title: Realtime updates not received on first page load when using ...
Iām experiencing an issue where realtime updates are not received on the first page load when using createBrowserClient (e.g. from @supabase/ssr or @supabase/auth-helpers-nextjs) in Next.js. The co...