Repository navigation
fix(realtime): update channel join payloads in set_auth - #1656
Merged
Merged
Conversation
o-santi
approved these changes
Oct 15, 2026
set_auth pushed access_token to joined channels but left each channel's join payload holding the token captured at subscribe() time. Rejoins resend that payload, so after a dropped connection a channel rejoined with the original, possibly expired, JWT and the server rejected it. Channels that were still joining or errored never got the new token. Store the token in every channel's join payload, as realtime-js does in setAuth, while keeping the access_token push for joined channels. Fixes supabase#1655
o-santi
force-pushed
the
fix/realtime-set-auth-join-payload
branch
from
October 15, 2026 17:52
c02fdf7 to
f45693d
Compare
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
Fixes #1655
AsyncRealtimeClient.set_auth(token)pushesaccess_tokento joined channels but leaves each channel's join payload alone:The join payload keeps the token captured in
subscribe(). When a channel rejoins (_reconnect()→channel._rejoin()→join_push.resend()), it sends that original token.supabasecallsrealtime.set_auth(...)on everyTOKEN_REFRESHED, and user JWTs expire after an hour by default. Once a connection drops after that, the rejoin carries an expired JWT. The realtime server rejects the join (InvalidJWTToken: Token has expired), and the channel keeps retrying with the same stale token, so private channels and RLS-filteredpostgres_changesstop delivering events. Channels that are still joining or errored whenset_authruns never get the new token at all.What is the new behavior?
set_authalso stores the token in every channel's join payload (join_push.update_payload({"access_token": token})), so rejoins use the current token. Joined channels still get theaccess_tokenpush, as before.This matches realtime-js, which calls
channel.updateJoinPayload({ access_token })for every channel insetAuthin addition to the push. ANonetoken is stored as-is, like realtime-js does; the server treats a missing join token as the tenant key.The sync realtime client is a
NotImplementedErrorstub, so there's no sync counterpart.Tests
test_set_auth_updates_join_payload_used_on_rejoininsrc/realtime/tests/test_connection.pyfollows the existing mocked-WebSocket tests in that file. It:set_auth("refreshed-token")and checks theaccess_tokenpush (existing behavior);channel._rejoin()the way_reconnect()does, and asserts thephx_joinpayload carriesrefreshed-token.It fails on
main(the rejoin sends the original key) and passes here. It doesn't need the realtime server.Validation
client.py).uv run --package realtime mypy src/realtime/src/realtime src/realtime/tests: no issues in 21 source files.uv run ruff check --fix/uv run ruff format: clean.git diff --check: clean.The rest of
src/realtime/testsneeds the local Supabase stack (make realtime.start-infra: Docker + Supabase CLI), which wasn't running. With this change the full suite gives 26 passed and 6 failed. The 6 failures aretest_broadcast_events,test_postgrest_changes,test_postgrest_changes_on_different_tables,test_multiple_connect_attempts,test_send_message_reconnectionandtest_presence, and all of them are connection-refused errors. Without the fix, those same 6 fail plus the new test.