Skip to content

fix(specs): correct third-party auth error propagation behavior - #86

Merged
grdsdev merged 2 commits into
mainfrom
fix/third-party-auth-error-propagation
Aug 18, 2026
Merged

fix(specs): correct third-party auth error propagation behavior#86
grdsdev merged 2 commits into
mainfrom
fix/third-party-auth-error-propagation

Conversation

@grdsdev

@grdsdev grdsdev commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

specs/client/authentication_integration/third_party_auth.md currently says a rejecting/throwing accessToken callback falls back to the anon key, the same as returning null:

If the callback returns null or rejects, the request proceeds unauthenticated (as the project's anon key) rather than failing the call outright...

That doesn't match supabase-js, which I'm treating as the reference implementation here. In fetchWithAuth (packages/core/supabase-js/src/lib/fetch.ts), the token getter is called unguarded:

const realToken = await getAccessToken()

No try/catch — a rejecting callback propagates and fails the request. Only a null return triggers the anon-key Authorization fallback. flutter's AuthHttpClient.send() follows the same pattern (unguarded await _getAccessToken()), and its _getAccessToken() explicitly rethrows session errors with the comment "Throw the error instead of making an API request with an expired token."

This PR:

  • Splits the null case (anon-key fallback, unchanged) from the reject/throw case (must propagate and fail the call) in the spec's Behavior section.
  • Adds a Notes section stating implementations must not catch-and-return-null on the callback, since that silently downgrades an authenticated request to an anonymous one instead of surfacing the failure.

This came up while reviewing supabase-swift#1233, where the Functions client's access-token closure used try?, converting any error (including one from a configured accessToken provider) into nil. Cross-checking JS/Flutter/Python confirmed JS and Flutter both propagate the error; this spec should reflect that as the source of truth so other SDKs (including Swift) can be checked against it going forward.

Test plan

  • npm run validate passes in scripts/capability-matrix
  • No feature ID or schema changes — spec-only correction

The spec claimed a rejecting/throwing accessToken callback falls back
to the anon key, same as returning null. That doesn't match
supabase-js (fetchWithAuth in lib/fetch.ts calls the callback
unguarded — a rejection propagates and fails the request; only a
null return triggers the anon-key fallback). Split the two cases and
add a Notes section stating implementations must not swallow callback
errors into null, since that silently downgrades an authenticated
request to an anonymous one instead of surfacing the failure.
@grdsdev
grdsdev requested a review from a team as a code owner August 17, 2026 18:34
@coderabbitai

coderabbitai Bot commented Aug 17, 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: e1179fed-9840-468a-b703-bd2a9bf37fd7

📥 Commits

Reviewing files that changed from the base of the PR and between d6bb1ab and fd77700.

📒 Files selected for processing (1)
  • specs/client/authentication_integration/third_party_auth.md
💤 Files with no reviewable changes (1)
  • specs/client/authentication_integration/third_party_auth.md

Included review availability: Your plan includes up to 1 review per rolling hour; 0 remain after this review.


📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Third-party authentication requests now proceed unauthenticated only when explicitly allowed by the token callback.
    • Authentication callback errors now correctly fail the triggering request instead of silently falling back to anonymous access.
  • Documentation

    • Clarified that authentication implementations must not suppress callback failures.

Walkthrough

The third-party authentication specification states that a null token sends an unauthenticated request. Rejected or throwing token callbacks propagate their errors and fail the request. Implementations must not catch callback errors and return null.

Merge Risk: ⚪ Minimal · up to fd777

This is a localized specification correction clarifying authentication error propagation, with no production code changes or merge-blocking risk remaining after normal checks and review.


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.

Comment thread specs/client/authentication_integration/third_party_auth.md Outdated
Repeated the point already made in the Behavior paragraph above it.
grdsdev added a commit to supabase/supabase-swift that referenced this pull request Aug 18, 2026
…lowing them (#1236)

* fix(supabase): propagate access-token provider errors instead of swallowing them

`adaptRequest` converted any error from resolving the access token — including
one thrown by a configured `options.auth.accessToken` third-party auth
provider — into `nil` via `try?`, so the request would silently go out under
the anon key instead of failing. Only `AuthError.sessionMissing` (no signed-in
user, the expected case) should fall back to the anon key; every other error
(a network failure refreshing the session, or a throwing custom `accessToken`
provider) must fail the request instead of downgrading it to an anonymous one.

Flagged by CodeRabbit on #1233, and cross-checked against supabase-js and
supabase-flutter, both of which already propagate these errors rather than
swallowing them (flutter's `AuthHttpClient` explicitly documents this: "Throw
the error instead of making an API request with an expired token"). Also see
supabase/sdk#86, which corrects the capability spec to match.

* refactor(supabase): move sessionMissing handling into accessTokenProvider

Per @spydon's review on #1236: `adaptRequest` shouldn't need to know which
auth errors are benign. Move the `catch AuthError.sessionMissing` into
`accessTokenProvider` itself, so every caller — `adaptRequest` and the
Realtime `accessToken` closure via `_getAccessToken()` — gets the same
"no session falls back to nil, everything else propagates" behavior for
free, instead of each caller needing its own catch. The Realtime closure
previously had no such handling at all, so this also fixes it falling
back consistently with REST/Storage/Functions.
@grdsdev
grdsdev merged commit ccc2fbb into main Aug 18, 2026
5 checks passed
@grdsdev
grdsdev deleted the fix/third-party-auth-error-propagation branch August 18, 2026 13:56
grdsdev pushed a commit that referenced this pull request Aug 20, 2026
🤖 I have created a release *beep* *boop*
---


## [1.2.0](v1.1.1...v1.2.0)
(2026-08-20)


### Features

* **auth:** add concurrent PKCE flow id capability
([#91](#91))
([bd6d972](bd6d972))


### Bug Fixes

* **specs:** correct third-party auth error propagation behavior
([#86](#86))
([ccc2fbb](ccc2fbb))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
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.

3 participants