Skip to content

fix: refresh token updates auth headers and sets realtime auth #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Kabya002
Copy link

@Kabya002 Kabya002 commented Jul 9, 2025

This PR fixes an issue where Supabase Auth Admin API calls (and other client services) fail after the access token is refreshed via on_auth_state_change. The Authorization header was not being updated correctly, and Realtime auth was not being re-synced post-refresh.

Changes Made:

  1. Implemented _listen_to_auth_events() method in both SyncClient and AsyncClient.
  2. Subscribed to auth state changes with auth.on_auth_state_change(...) inside client constructors.
  3. Updated Authorization headers when auth events like SIGNED_IN, TOKEN_REFRESHED, or SIGNED_OUT are triggered.
  4. For AsyncClient, also called await self.realtime.set_auth(...) with the new access token.

Test Coverage:
Manually verified that:

  1. Auth header updates after refresh.
  2. Auth Admin API works post-refresh.
  3. Realtime connections continue to work with the refreshed token.

Related Issue: Fixes #1143
(#1143)

@silentworks
Copy link
Contributor

Hi @Kabya002 thanks for your first contribution. Can you provide some unit tests around the issue that this is fixing please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: client access token for auth admin API is not properly refreshed
2 participants