Skip to content

fix(types): only accept 'none' as the last entry of AuthConfig - #148

Merged
mandarini merged 2 commits into
mainfrom
fix/auth-config-types
Sep 9, 2026
Merged

fix(types): only accept 'none' as the last entry of AuthConfig#148
mandarini merged 2 commits into
mainfrom
fix/auth-config-types

Conversation

@johnstonmatt

Copy link
Copy Markdown
Contributor

Previously auth accepted AuthModeWithKey[], which let 'none' appear anywhere in the list even though it matches every request — making later modes unreachable and ['none'] indistinguishable from a bare 'none', both silently accepted.

  • Add AuthConfig, restricting the auth option to a single mode, an ordered list of credentialed modes, or that list with 'none' only as the final entry; the deprecated allow keeps the old looser type so mid-migration code still compiles, and requiresCredentials still scans the full list for it
  • Add CredentialedAuthMode (AuthModeWithKey minus 'none') as the building block for AuthConfig, giving the unwrapped single-mode form its own name instead of leaving it implicit
  • Update README, docs/api-reference.md, docs/auth-modes.md, and the supabase-server skill to document the new type and the "'none' goes last, or alone" rule, and add type-level tests in src/types.test.ts

@johnstonmatt
johnstonmatt requested review from a team as code owners September 7, 2026 19:31
@pkg-pr-new

pkg-pr-new Bot commented Sep 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 1f9d8eb

@mandarini
mandarini force-pushed the fix/auth-config-types branch from ff78a14 to 8ee541b Compare September 8, 2026 10:05
Base automatically changed from feat/withsupabase-composite to main September 9, 2026 11:06
`auth` took `AuthModeWithKey[]`, which let `'none'` sit anywhere in the
list. It matches every request, so any mode after it is unreachable, and
a list of just `['none']` says nothing that a bare `auth: 'none'` doesn't
— both were accepted silently.

`AuthConfig` moves that rule into the type: a list is one or more
credentialed modes, optionally followed by `'none'`. The optional-user
form `['user', 'none']` is unaffected, which is what the e2e apps and the
docs use.

The deprecated `allow` keeps the looser element type so code mid-migration
still compiles, so `requiresCredentials` still scans the whole list rather
than checking the last entry.
AuthConfig reached the single-mode form through AuthModeWithKey, which
also carries 'none'. Splitting it into `'none' | CredentialedAuthMode`
makes the union say what it accepts — a bare mode, an ordered list, or
'none' — rather than leaving a reader to subtract 'none' from one member
and find it again in another.

The type is equivalent to what it replaced, so no call site moves; what
changes is that the unwrapped form is now stated, tested and documented
instead of inherited.
@mandarini
mandarini force-pushed the fix/auth-config-types branch from 8ee541b to 1f9d8eb Compare September 9, 2026 11:06
@mandarini
mandarini merged commit edfb411 into main Sep 9, 2026
10 checks passed
@mandarini
mandarini deleted the fix/auth-config-types branch September 9, 2026 11:09
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.

2 participants