* docs: add initial documentation and skills.md
* docs: apply formatting
* docs: update SKILL.md to resolve docs from package location and ship docs with npm
SKILL.md now instructs agents to find documentation in the installed
@supabase/server package (node_modules or repo root) instead of using
relative paths. Added docs/ and SKILL.md to package.json files array
so they ship with npm installs.
* docs: add missing HTTPException import in error-handling example
* docs: fix strictNullChecks issues, duplicate variables, and missing context in examples
- Add non-null assertions (!) after error guards where TS can't narrow
destructured result tuples
- Split duplicate variable declarations into separate code blocks
- Add missing imports and show where variables like `auth` come from
- Keep { data, error } destructuring pattern consistent with SDK convention
* docs: reframe as runtime-agnostic and add env auto-injection details
- getting-started: replace Edge Function framing with runtime-neutral
language, explain module worker pattern works across Deno/Bun/Workers,
add Runtimes section covering all supported environments
- webhooks: replace Deno.env with process.env for portable examples
- environment-variables: add "Auto-injected in" column distinguishing
Platform vs Local CLI, reframe section headers
- auth-modes: clean up example key values
- core-primitives: clarify "Integration with frameworks" wording
- types: simplify TSDoc for publishable/secret key descriptions
* docs: add SSR frameworks guide and update references
Add docs/ssr-frameworks.md covering the pattern for using core
primitives in Next.js, SvelteKit, Nuxt, and Remix — cookie extraction,
env bridging, JWKS caching, and a complete Next.js adapter example.
Replace the basic SSR example in core-primitives.md with a pointer
to the new dedicated doc. Add SSR row to SKILL.md routing table.
* docs: add disclaimer of new package
* docs: extend explanation on keys env vars
* docs: add platform-specific quick starts to SKILL.md
Split the single generic example into per-platform sections
(Edge Functions, Cloudflare Workers, Hono, SSR Frameworks) so
AI agents pick the correct import specifier for each runtime.
Adds npm: prefix to all Deno examples and a Deno column to the
entry points table. Also adds createSupabaseContext examples.
* docs: add server-to-server quick starts and allow:always guardrails
Add secret key auth and webhook signature verification quick starts
to SKILL.md. Add explicit decision tree for allow:'always' so AI
agents confirm with the user before leaving endpoints unprotected.
* docs: add legacy keys warning, skills install, remove webhook docs
- Add legacy keys warning to SKILL.md (avoid anon/service_role keys)
- Add AI coding skills install section to README
- Add server-to-server quick start with caller code to README
- Add runtimes, documentation table, and named secret keys to README
- Remove verifyWebhookSignature references from all docs
- Delete docs/webhooks.md (code removal in separate PR)
* docs: add verify_jwt = false note for non-user auth modes
Edge Functions require verify_jwt = false in config.toml when
using allow: public, secret, or always — otherwise the platform
rejects requests before the handler runs.
* docs: add edge function recipes and refactor env vars doc
Add recipes for function-to-function calls, pg_net from database,
Stripe webhooks, and generic webhook signature verification.
Document the @supabase/server/wrappers entry point.
Refactor environment-variables.md into Supabase vs non-Supabase sections.
* docs: add security doc covering timing-safe comparison, auth model, CORS
* docs: link auth-modes timing-safe mentions to security.md
* docs: adding 'local cli' to secrets table
This envs will be injected from cli too
* docs: setting Deno as first installation choice
* docs: adding 'verify_jwt=false' disclaimer for non-user auth
* docs: split Deno/Supabase runtime section, merge Deno/Node/Bun
* docs(skills): adding legacy code migration example
* docs(skills): explaining why legacy code should be migrated
* docs: rewrite migration section, improve skill description triggers
---------
Co-authored-by: Kalleby Santos <kalleby_santos@hotmail.com>
7.8 KiB
API Reference
Complete reference for every export, organized by entry point.
@supabase/server
withSupabase
function withSupabase<Database = unknown>(
config: WithSupabaseConfig,
handler: (req: Request, ctx: SupabaseContext<Database>) => Promise<Response>,
): (req: Request) => Promise<Response>
Wraps a fetch handler with auth, CORS, and client creation. Returns a (req: Request) => Promise<Response> function suitable for export default { fetch }.
- Handles
OPTIONSpreflight when CORS is enabled - Verifies credentials per
config.allow - Returns JSON error response on auth failure
- Adds CORS headers to all responses
createSupabaseContext
function createSupabaseContext<Database = unknown>(
request: Request,
options?: WithSupabaseConfig,
): Promise<
| { data: SupabaseContext<Database>; error: null }
| { data: null; error: AuthError }
>
Creates a SupabaseContext from a request. Returns a result tuple. The cors option is ignored.
Defaults to allow: 'user' when options is omitted.
@supabase/server/core
verifyAuth
function verifyAuth(
request: Request,
options: { allow: AllowWithKey | AllowWithKey[]; env?: Partial<SupabaseEnv> },
): Promise<{ data: AuthResult; error: null } | { data: null; error: AuthError }>
Extracts credentials from a request and verifies them. Convenience wrapper over extractCredentials + verifyCredentials.
verifyCredentials
function verifyCredentials(
credentials: Credentials,
options: { allow: AllowWithKey | AllowWithKey[]; env?: Partial<SupabaseEnv> },
): Promise<{ data: AuthResult; error: null } | { data: null; error: AuthError }>
Verifies pre-extracted credentials against allowed auth modes. Tries each mode in order — first match wins.
extractCredentials
function extractCredentials(request: Request): Credentials
Reads Authorization: Bearer <token> and apikey headers from a request. Pure extraction, no validation. Synchronous.
resolveEnv
function resolveEnv(
overrides?: Partial<SupabaseEnv>,
): { data: SupabaseEnv; error: null } | { data: null; error: EnvError }
Resolves Supabase environment configuration from runtime variables. SUPABASE_URL is the only hard requirement.
createContextClient
function createContextClient<Database = unknown>(
options?: CreateContextClientOptions,
): SupabaseClient<Database>
Creates a user-scoped Supabase client. RLS applies. Throws EnvError if URL or publishable key is missing.
Configured with:
- Publishable key (named or default) as
apikeyheader - User's JWT as
Authorization: Bearerheader (whenauth.tokenis provided) persistSession: false,autoRefreshToken: false,detectSessionInUrl: false
createAdminClient
function createAdminClient<Database = unknown>(
options?: CreateAdminClientOptions,
): SupabaseClient<Database>
Creates an admin Supabase client that bypasses RLS. Throws EnvError if URL or secret key is missing.
@supabase/server/adapters/hono
withSupabase (Hono)
function withSupabase(
config?: Omit<WithSupabaseConfig, 'cors'>,
): MiddlewareHandler
Hono middleware. Sets c.var.supabaseContext on the Hono context. Throws HTTPException on auth failure with cause: AuthError.
Skips if c.var.supabaseContext is already set (enables route-level overrides).
Defaults to allow: 'user' when config is omitted.
Types
Allow
type Allow = 'always' | 'public' | 'secret' | 'user'
AllowWithKey
type AllowWithKey = Allow | `public:${string}` | `secret:${string}`
Extended auth mode with named key support. Examples: 'public:web', 'secret:*', 'secret:internal'.
SupabaseContext<Database>
interface SupabaseContext<Database = unknown> {
supabase: SupabaseClient<Database>
supabaseAdmin: SupabaseClient<Database>
userClaims: UserClaims | null
claims: JWTClaims | null
authType: Allow
}
WithSupabaseConfig
interface WithSupabaseConfig {
allow?: AllowWithKey | AllowWithKey[] // default: 'user'
env?: Partial<SupabaseEnv>
cors?: boolean | Record<string, string> // default: true
supabaseOptions?: SupabaseClientOptions<string>
}
SupabaseEnv
interface SupabaseEnv {
url: string
publishableKeys: Record<string, string>
secretKeys: Record<string, string>
jwks: JsonWebKeySet | null
}
Credentials
interface Credentials {
token: string | null
apikey: string | null
}
AuthResult
interface AuthResult {
authType: Allow
token: string | null
userClaims: UserClaims | null
claims: JWTClaims | null
keyName?: string | null
}
JWTClaims
interface JWTClaims {
sub: string
iss?: string
aud?: string | string[]
exp?: number
iat?: number
role?: string
email?: string
app_metadata?: Record<string, unknown>
user_metadata?: Record<string, unknown>
[key: string]: unknown
}
UserClaims
interface UserClaims {
id: string
role?: string
email?: string
appMetadata?: Record<string, unknown>
userMetadata?: Record<string, unknown>
}
ClientAuth
interface ClientAuth {
token?: string | null
keyName?: string | null
}
CreateContextClientOptions
interface CreateContextClientOptions {
auth?: ClientAuth
env?: Partial<SupabaseEnv>
supabaseOptions?: SupabaseClientOptions<string>
}
CreateAdminClientOptions
interface CreateAdminClientOptions {
auth?: Pick<ClientAuth, 'keyName'>
env?: Partial<SupabaseEnv>
supabaseOptions?: SupabaseClientOptions<string>
}
JsonWebKeySet
interface JsonWebKeySet {
keys: JsonWebKey[]
}
Error Classes
EnvError
class EnvError extends Error {
readonly status: 500
readonly code: string
}
AuthError
class AuthError extends Error {
readonly status: number // 401 or 500
readonly code: string
}
Error Code Constants
| Constant | Value | Class | Meaning |
|---|---|---|---|
EnvGenericError |
'ENV_ERROR' |
EnvError |
Generic environment error |
MissingSupabaseURLError |
'MISSING_SUPABASE_URL' |
EnvError |
SUPABASE_URL not set |
MissingPublishableKeyError |
'MISSING_PUBLISHABLE_KEY' |
EnvError |
Named publishable key not found |
MissingDefaultPublishableKeyError |
'MISSING_DEFAULT_PUBLISHABLE_KEY' |
EnvError |
No default publishable key |
MissingSecretKeyError |
'MISSING_SECRET_KEY' |
EnvError |
Named secret key not found |
MissingDefaultSecretKeyError |
'MISSING_DEFAULT_SECRET_KEY' |
EnvError |
No default secret key |
AuthGenericError |
'AUTH_ERROR' |
AuthError |
Generic auth error |
InvalidCredentialsError |
'INVALID_CREDENTIALS' |
AuthError |
No credential matched |
CreateSupabaseClientError |
'CREATE_SUPABASE_CLIENT_ERROR' |
AuthError |
Client creation failed after auth |
Errors Factory Map
const Errors: {
[MissingSupabaseURLError]: () => EnvError
[MissingPublishableKeyError]: (name: string) => EnvError
[MissingDefaultPublishableKeyError]: () => EnvError
[MissingSecretKeyError]: (name: string) => EnvError
[MissingDefaultSecretKeyError]: () => EnvError
[InvalidCredentialsError]: () => AuthError
[CreateSupabaseClientError]: () => AuthError
}
Keyed by error code constant. Each entry returns a pre-configured error instance.