feat: add withRequiredClaims user-mode auth gate - #127
Merged
Conversation
commit: |
mandarini
force-pushed
the
feat/required-claims-gate
branch
from
August 27, 2026 12:28
e632950 to
825e79a
Compare
spydon
approved these changes
Aug 27, 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.
Adds
withRequiredClaims, the user-mode auth gate. Implements SDK-1614.What
defineMiddlewareentry at@supabase/server/middleware/required-claims. It verifies the Bearer token against the project JWKS (the same core aswithSupabase'susermode) and contributes non-nulljwtClaims: JWTClaims.sb_*API key in the Authorization slot: 401INVALID_CREDENTIALS, handler never runs. Invalid token: the same 401. Token present but no JWKS: 500ENV_ERROR. The token check runs before JWKS resolution, so a token-less request 401s even on a misconfigured project.jwtClaims, so composing it withwithClaims, or insidewithSupabase'smiddleware:array, is a compile-time conflict. Type tests pin both, pluspipeline([withRequiredClaims(), withPostgresClient()], h)compiling with non-nullctx.jwtClaims.withClaimsdocstring, api-reference, postgres.md) now point at this entry instead of the hand-wrappedwithSupabaseworkaround.Why
withClaimsis not a gate: token-less requests proceed as anonymous (SDK-1604). Migrating an auth-gated endpoint to[withClaims(), withSupabaseClient()]compiles, passes a logged-in smoke test, and silently accepts anonymous callers. This entry closes that trap on the user-JWT side.required: trueflag onwithClaimscannot deliver non-null types because a middleware's contribution type is fixed, and the hand-wrappedwithSupabaseentry infersEntry<string, object, unknown>, which poisons pipeline typing for every entry after it. A separate typed entry is the fix.withRequiredClaimsreads againstwithClaimsas "claims required" vs "claims if present".withAuthstays free for the post-launch multi-mode gate (SDK-1596), which contributes a different shape.