Skip to content

fix(realtime): ensure setAuth doesn't disable token refresh - #2592

Merged
mandarini merged 1 commit into
masterfrom
fix/realtime-set-auth
Aug 5, 2026
Merged

fix(realtime): ensure setAuth doesn't disable token refresh#2592
mandarini merged 1 commit into
masterfrom
fix/realtime-set-auth

Conversation

@edgurgel

@edgurgel edgurgel commented Aug 4, 2026

Copy link
Copy Markdown
Member

🔍 Description

Ensure realtime.setAuth doesn't disable token refresh. This happens only on 3rd party tokens.

What changed?

Change RealtimeClient's setAuth to only consider that tokens will be manually set if there is no accessToken promise to resolve.

Why was this change needed?

Because the SupabaseClient bootstraps the token calling setAuth which disables the token refresh:

if (this.accessToken) {
// Start auth immediately to avoid race condition with channel subscriptions
// Wrap Promise to avoid Firefox extension cross-context Promise access errors
Promise.resolve(this.accessToken())
.then((token) => this.realtime.setAuth(token))
.catch((e) => console.warn('Failed to set initial Realtime auth token:', e))
}

🔄 Breaking changes

  • This PR contains no breaking changes

📋 Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run pnpm nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

📝 Additional notes

@edgurgel
edgurgel requested review from a team as code owners August 4, 2026 03:29
@github-actions github-actions Bot added the realtime-js Related to the realtime-js library. label Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d3998e8b-2057-4355-b8ac-af02c9a6d29d

📥 Commits

Reviewing files that changed from the base of the PR and between fd3148a and f25187d.

📒 Files selected for processing (2)
  • packages/core/realtime-js/src/RealtimeClient.ts
  • packages/core/supabase-js/test/unit/SupabaseClient.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/core/realtime-js/src/RealtimeClient.ts
  • packages/core/supabase-js/test/unit/SupabaseClient.test.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved Realtime authentication handling when using access-token callbacks.
    • Ensured automatic token refresh remains enabled after initial authentication, even if a token is manually provided.

Walkthrough

RealtimeClient.setAuth keeps callback authentication active when an accessToken callback is configured. Manual-token mode is used only when no callback exists. Callback mode clears manual-token state and supports automatic token refresh. SupabaseClient test coverage verifies this behavior after asynchronous authentication initialization.

Sequence Diagram(s)

sequenceDiagram
  participant SupabaseClient
  participant RealtimeClient
  participant accessToken_callback
  participant Heartbeat
  SupabaseClient->>RealtimeClient: setAuth(token)
  RealtimeClient->>accessToken_callback: Keep callback mode active
  Heartbeat->>accessToken_callback: Request refreshed token
  accessToken_callback-->>RealtimeClient: Return refreshed token
Loading

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2592

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2592

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2592

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2592

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2592

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2592

commit: f25187d

@coveralls

coveralls commented Aug 4, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 81.41%. remained the same — fix/realtime-set-auth into master

@edgurgel
edgurgel force-pushed the fix/realtime-set-auth branch from 9e6141c to fd3148a Compare August 4, 2026 03:35
filipecabaco
filipecabaco previously approved these changes Aug 4, 2026
@mandarini
mandarini merged commit 1831402 into master Aug 5, 2026
32 checks passed
@mandarini
mandarini deleted the fix/realtime-set-auth branch August 5, 2026 10:16
mandarini pushed a commit to supabase/ssr that referenced this pull request Aug 11, 2026
This PR updates `@supabase/supabase-js` to v2.112.3.

**Source**: manual

---

## Release Notes

## v2.112.3

## 2.112.3 (2026-08-11)

### 🩹 Fixes

- **supabase:** add trace context headers to canonical CORS allow-list
([#2603](supabase/supabase-js#2603))
- **supabase:** improve trace propagation sampling and diagnostics
([#2604](supabase/supabase-js#2604))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
## v2.112.2

## 2.112.2 (2026-08-06)

### 🩹 Fixes

- **realtime:** prevent duplicate on bindings
([#2594](supabase/supabase-js#2594))
- **realtime:** clear stale join payload on sign-out
([#2597](supabase/supabase-js#2597))

### ❤️ Thank You

- Filipe Cabaço @filipecabaco
- Vaibhav @7ttp
## v2.112.1

## 2.112.1 (2026-08-05)

### 🩹 Fixes

- **auth:** preserve 5xx error message
([#2587](supabase/supabase-js#2587))
- **realtime:** ensure setAuth doesn't disable token refresh
([#2592](supabase/supabase-js#2592))

### ❤️ Thank You

- Eduardo Gurgel
- Vaibhav @7ttp
## v2.112.0

## 2.112.0 (2026-08-03)

### 🚀 Features

- **supabase:** move OpenTelemetry tracing to opt-in /tracing subpath
([#2583](supabase/supabase-js#2583))

### 🩹 Fixes

- **auth:** accept uppercase UUIDs in validateUUID
([#2467](supabase/supabase-js#2467))
- **postgrest:** honour throwOnError when maybeSingle finds multiple
rows ([#2580](supabase/supabase-js#2580))
- **storage:** resolve createSignedUrls return type mismatch
([#2474](supabase/supabase-js#2474))
- **storage:** expose service error code on StorageApiError
([#2537](supabase/supabase-js#2537))
- **supabase:** forward db retry option
([#2571](supabase/supabase-js#2571))

### ❤️ Thank You

- Anubhav Anand @i-anubhav-anand
- Gourab Singha @gourabsingha1
- Juhef @juheff
- Katerina Skroumpelou @mandarini
- Thribhuvan
- Vaibhav @7ttp
- Zuhef Ahmed @Zuhef

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
mandarini pushed a commit to supabase/supabase that referenced this pull request Aug 11, 2026
This PR updates @supabase/*-js libraries to version 2.112.3.

**Source**: manual

**Changes**:
- Updated @supabase/supabase-js to 2.112.3
- Updated @supabase/auth-js to 2.112.3
- Updated @supabase/realtime-js to 2.112.3
- Updated @supabase/postgest-js to 2.112.3
- Refreshed pnpm-lock.yaml

---

## Release Notes

## v2.112.3

## 2.112.3 (2026-08-11)

### 🩹 Fixes

- **supabase:** add trace context headers to canonical CORS allow-list
([#2603](supabase/supabase-js#2603))
- **supabase:** improve trace propagation sampling and diagnostics
([#2604](supabase/supabase-js#2604))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
## v2.112.2

## 2.112.2 (2026-08-06)

### 🩹 Fixes

- **realtime:** prevent duplicate on bindings
([#2594](supabase/supabase-js#2594))
- **realtime:** clear stale join payload on sign-out
([#2597](supabase/supabase-js#2597))

### ❤️ Thank You

- Filipe Cabaço @filipecabaco
- Vaibhav @7ttp
## v2.112.1

## 2.112.1 (2026-08-05)

### 🩹 Fixes

- **auth:** preserve 5xx error message
([#2587](supabase/supabase-js#2587))
- **realtime:** ensure setAuth doesn't disable token refresh
([#2592](supabase/supabase-js#2592))

### ❤️ Thank You

- Eduardo Gurgel
- Vaibhav @7ttp
## v2.112.0

## 2.112.0 (2026-08-03)

### 🚀 Features

- **supabase:** move OpenTelemetry tracing to opt-in /tracing subpath
([#2583](supabase/supabase-js#2583))

### 🩹 Fixes

- **auth:** accept uppercase UUIDs in validateUUID
([#2467](supabase/supabase-js#2467))
- **postgrest:** honour throwOnError when maybeSingle finds multiple
rows ([#2580](supabase/supabase-js#2580))
- **storage:** resolve createSignedUrls return type mismatch
([#2474](supabase/supabase-js#2474))
- **storage:** expose service error code on StorageApiError
([#2537](supabase/supabase-js#2537))
- **supabase:** forward db retry option
([#2571](supabase/supabase-js#2571))

### ❤️ Thank You

- Anubhav Anand @i-anubhav-anand
- Gourab Singha @gourabsingha1
- Juhef @juheff
- Katerina Skroumpelou @mandarini
- Thribhuvan
- Vaibhav @7ttp
- Zuhef Ahmed @Zuhef
## v2.111.0

## 2.111.0 (2026-07-28)

### 🚀 Features

- **auth:** store PKCE verifiers in per-flow slots to survive
overlapping flows
([#2569](supabase/supabase-js#2569))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

realtime-js Related to the realtime-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants