docs(auth): order key-based modes before 'user' in all examples#76
Draft
tomaspozo wants to merge 2 commits into
Draft
docs(auth): order key-based modes before 'user' in all examples#76tomaspozo wants to merge 2 commits into
tomaspozo wants to merge 2 commits into
Conversation
Behind Supabase's API gateway, an apikey request that omits the Authorization header still reaches the function with a gateway-injected 'Bearer <token>' (anon for a publishable key, service_role for a secret key). A 'user' mode placed before the key-based mode then tries to verify that injected token, fails, and rejects with InvalidCredentialsError before the apikey mode is reached. Document the rule — list 'secret'/'publishable' before 'user', keep 'user' last — across auth-modes, security, api-reference, core-primitives, the adapter guides, the README, and the withSupabase/verifyCredentials JSDoc, and flip every combined-auth example to the safe ordering. Corrects the security.md claim that an absent Authorization header always falls through (true at the SDK level, not behind the gateway).
commit: |
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.
Documents a non-obvious auth-mode ordering rule and flips every combined-auth example to the safe order.
The problem
Behind Supabase's API gateway, an
apikeyrequest that omits theAuthorizationheader does not reach the function header-less — the gateway injects anAuthorization: Bearer <token>derived from the key (ananontoken for a publishable key, aservice_roletoken for a secret key). If a'user'mode is listed before the key-based mode, it tries to verify that injected token, fails, and rejects withInvalidCredentialsError(401) before'secret'/'publishable'is ever reached.Confirmed by capturing the forwarded headers from a live local stack:
apikey=secret+ noAuthorization→ the function receivesAuthorization: Bearer <legacy HS256 service_role JWT>. A dummy non-Bearerheader makes it pass; the absence is what triggers the injection.This is a gateway behavior, not an SDK bug — no code change here. The rule: list key-based modes (
secret/publishable) first, keep'user'last (e.g.['secret', 'user']).What changed (docs + JSDoc only)
docs/auth-modes.md— new[!IMPORTANT]callout explaining the gateway injection + ordering rule; flipped examples.docs/security.md— corrected the claim that an absentAuthorizationheader always falls through (true at the SDK level, not behind the gateway) and added the ordering guidance.docs/api-reference.md,docs/core-primitives.md, and the h3 / hono / nestjs adapter guides — flipped examples + pointers.README.md— flipped the dual-auth example and expanded the ordering note.src/types.ts(WithSupabaseConfig.auth,AuthMode,AuthModeWithKey) andsrc/core/verify-credentials.tsJSDoc — added the rule so it surfaces in IntelliSense.Unit tests are intentionally left on
['user', …]ordering — they exercise SDK-level logic where no gateway is involved. One deliberate❌anti-pattern example remains in the callout.🤖 Generated with Claude Code