Skip to content

feat: add withRequiredClaims user-mode auth gate - #127

Merged
mandarini merged 3 commits into
mainfrom
feat/required-claims-gate
Aug 27, 2026
Merged

feat: add withRequiredClaims user-mode auth gate#127
mandarini merged 3 commits into
mainfrom
feat/required-claims-gate

Conversation

@mandarini

@mandarinimandarini commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Adds withRequiredClaims, the user-mode auth gate. Implements SDK-1614.

What

  • New defineMiddleware entry at @supabase/server/middleware/required-claims. It verifies the Bearer token against the project JWKS (the same core as withSupabase's user mode) and contributes non-nulljwtClaims: JWTClaims.
  • Missing token, or an sb_* API key in the Authorization slot: 401 INVALID_CREDENTIALS, handler never runs. Invalid token: the same 401. Token present but no JWKS: 500 ENV_ERROR. The token check runs before JWKS resolution, so a token-less request 401s even on a misconfigured project.
  • Keyed on jwtClaims, so composing it with withClaims, or inside withSupabase's middleware: array, is a compile-time conflict. Type tests pin both, plus pipeline([withRequiredClaims(), withPostgresClient()], h) compiling with non-null ctx.jwtClaims.
  • Docs: new api-reference section; the gate callouts from docs: state that withClaims is not an auth gate #125 (withClaims docstring, api-reference, postgres.md) now point at this entry instead of the hand-wrapped withSupabase workaround.

Why

  • withClaims is 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.
  • A required: true flag on withClaims cannot deliver non-null types because a middleware's contribution type is fixed, and the hand-wrapped withSupabase entry infers Entry<string, object, unknown>, which poisons pipeline typing for every entry after it. A separate typed entry is the fix.
  • Naming: withRequiredClaims reads against withClaims as "claims required" vs "claims if present". withAuth stays free for the post-launch multi-mode gate (SDK-1596), which contributes a different shape.

@pkg-pr-new

pkg-pr-newBot commented Aug 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@supabase/server@127

commit: 4a88731

@mandarini
mandarini marked this pull request as ready for review August 26, 2026 13:43
@mandarini
mandarini requested review from a team as code ownersAugust 26, 2026 13:43
@mandarinimandarini self-assigned this Aug 26, 2026
@mandarini
mandariniforce-pushed the feat/required-claims-gate branch from e632950 to 825e79aCompareAugust 27, 2026 12:28
@mandarini
mandarini merged commit 05a95b6 into mainAug 27, 2026
9 checks passed
@mandarini
mandarini deleted the feat/required-claims-gate branch August 27, 2026 14:45
Sign up for freeto 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.

2 participants

@mandarini@spydon