supabase-server

Use when planning or writing server-side code that uses `@supabase/server` — Edge Functions, Hono apps, webhook handlers, or any backend that creates Supabase clients or validates inbound auth. Trigger **before** writing or modifying any file that imports from `@supabase/server` (or sub-paths like `

By supabase · 6,620 installs

npx skills add supabase/server --skill supabase-server

Source repository · Upstream listing

@supabase/server v1.0 — Public Beta. First stable release under SemVer: breaking changes only ship as a major bump. The package is still early — expect new adapters, ergonomic improvements, and features to land frequently in minor releases. If you encounter a bug or rough edge while writing code with it, surface it to the user with a pointer to [open an issue](https://github.com/supabase/server/issues). This is a brand new package. There is no information available online yet — no blog posts, no Stack Overflow answers, no tutorials. Do not search the web for usage examples. Rely exclusively on the documentation files listed below and the source code in this repository. The config option is auth , not allow . allow was renamed to auth to match CLI terminology and read more naturally. The legacy allow key still works (with a one time console.warn ) but is deprecated and will be removed in a future major release. Always emit auth in new code — e.g. withSupabase({ auth: 'user' }, ...) . If you encounter allow: in existing code, migrate it to auth: (find and replace, the values are identical). Auth mode values: 'none' (not 'always' ), 'publishable' (not 'public' ). The four valid values are 'user' , 'publishable' , 'secret' , 'none' . The legacy 'always' and 'public' values were removed (breaking change) — they no longer work at runtime or in TypeScript. Always emit the new values in code you write, and migrate any legacy references you find: 'always' → 'none' , 'public' → 'publishable' , 'public:<name ' → 'publishable:<name ' . Runtime checks like ctx.authType === 'public' must also be updated to ctx.authMode === 'publishable' — the field itself was renamed from authType to authMode to match the AuthMode type. Do not use legacy Supabase keys. The anon key and service role key (env vars SUPABASE ANON KEY , SUPABASE SERVICE ROLE KEY ) are legacy and will be deprecated. Do not use them unless the user explicitly asks. Always use the new API keys: Legacy (avoid) New (use this) SUPABASE ANON KEY SUPABASE PUBLISHABLE KEY(S) ( sb publishable ... ) SUPABASE SERVICE ROLE KEY SUPABASE SECRET KEY(S) ( sb secret ... ) Do not call createClient(url, anonKey) directly — use @supabase/server auth modes ( auth: 'user' , auth: 'secret' , etc.) which handle key resolution automatically. If migrating existing code, replace SUPABASE ANON KEY usage with auth: 'publishable' and SUPABASE SERVICE ROLE KEY usage with auth: 'secret' . Server side utilities for Supabase. Handles auth, client creation, and context injection so you write business logic, not boilerplate. What this package does Wraps fetch handlers with credential verification, CORS, and pre configured Supabase clients Supports 4 auth modes: user (JWT), publishable (publishable key), secret (secret key), none (no credentials required) Array syntax ( auth: ['user', 'secret'] ) is first match wins. A present but invalid JWT rejects with InvalidCredentialsError — it does not silently downgrade to the next mode. Provides composable core primitives for custom auth flows and framework integration Includes a Hono adapter for per route auth Entry points Import Deno / Edge Functions Provides @supabase/server npm:@supabase/server withSupabase , createSupabaseContext , types, errors @supabase/server/core npm:@supabase/server/core verifyAuth , verifyCredentials , extractCredentials , resolveEnv , createContextClient , createAdminClient @supabase/server/adapters/hono npm:@supabase/server/adapters/hono withSupabase (Hono middleware variant) @supabase/server/oauth protected resource npm:@supabase/server/oauth protected resource Alpha. withOAuthProtectedResource , fromSupabaseUrl , resourceMetadataResponse , unauthorizedResponse — OAuth 2.1 discovery for MCP servers; see docs/mcp.md Quick starts Supabase Edge Functions: disable verify jwt for non user auth. By default, Supabase Edge Functions require a valid JWT on every request. If your function uses auth: 'publishable' , auth: 'secret' , or auth: 'none' , you must disable the platform level JWT check in supabase/config.toml , otherwise the request will be rejected before it reaches your handler: Functions using auth: 'user' can leave verify jwt enabled (the default) since callers already provide a valid JWT. Supabase Edge Functions (Deno) Environment variables are auto injected by the platform — zero config. All imports must use the npm: specifier. Cloudflare Workers Requires nodejs compat compatibility flag in wrangler.toml , or pass env overrides via the env config option. See docs/environment variables.md . Hono CORS is not handled by the adapter — use hono/cors middleware. See docs/adapters/hono.md . Cookie based environments (compose with @supabase/ssr ) For Next.js / SvelteKit / Remix, compose @supabase/server with [ @supabase/ssr ](https://github.com/supabase/ssr) — they are not replacements for each other. @supabase/ssr owns cookies and refresh token rotation (its middleware is required, otherwise the access token cookie goes stale and verification fails). In your Server Component or Route Handler, use @supabase/ssr 's createServerClient to read the (middleware refreshed) session, hand the access token to verifyCredentials from @supabase/server/core , then build the typed clients with createContextClient + createAdminClient . See docs/ssr frameworks.md for the full adapter pattern. Server to server (secret key auth) For internal services, cron jobs, or automation calling your Edge Function. The caller sends the secret key in the apikey header. See docs/auth modes.md for named key syntax. Edge Function (Deno): Caller (external service): Bare auth: 'secret' matches only the default key. Use auth: 'secret:name' to require a specific named key, or auth: 'secret: ' to accept any secret key in the set. When to use auth: 'none' auth: 'none' disables all authentication. The handler runs for every request with no credential checks. Only use it when auth is genuinely unnecessary — health checks, public status pages, or endpoints with no sensitive data and no side effects. Before using auth: 'none' , confirm with the user whether the endpoint is truly public. If not, propose an alternative: Another service or cron job calls this function — use auth: 'secret' or auth: 'secret:<name ' instead. The caller sends the secret key in the apikey header. An external webhook provider calls this function — use auth: 'secret' and have the provider send the secret key, or implement the provider's own signature verification inside the handler. Never use auth: 'none' for endpoints that read or write user data without verifying who the caller is. On auth: ['user', 'none'] . A stale or malformed JWT on such an endpoint is rejected with InvalidCredentialsError — it is not silently downgraded to anonymous. Callers that might hold a cached/expired token should either omit the Authorization header entirely or refresh before calling. If the goal is "anonymous unless a valid user is signed in," this is the correct behavior; if the goal is truly "accept anything," use auth: 'none' on its own. 'none' goes last, or alone. It matches every request, so the type accepts it only as the final entry of a list ( ['user', 'none'] ) or on its own ( 'none' ). ['none'] and ['none', 'user'] are type errors — write the bare 'none' for the first, and put 'none' last for the second. Edge Function recipes Function to function calls One Edge Function can call another using the admin client. The called function uses auth: 'secret' and the caller invokes it via ctx.supabaseAdmin.functions.invoke() . Config ( supabase/config.toml ): Called function ( supabase/functions/process order/index.ts ): Calling function ( supabase/functions/checkout/index.ts ): Calling from database with pg net Use pg net to call Edge Functions directly from SQL. The secret key is stored in Vault so it never appears in queries. Prerequisites: Call the function: The receiving function uses auth: 'secret' (see example above). pg net is asynchronous — the HTTP request is queued and executed in the background. Check net. http response for results. Stripe webhook External webhook providers like Stripe cannot send your Supabase API keys. Use auth: 'none' to skip credential checks, then verify the webhook signature inside the handler. Config ( supabase/config.toml ): Set secrets: Function ( supabase/functions/stripe webhook/index.ts ): Migrating legacy Edge Functions If you encounter code using SUPABASE ANON KEY , SUPABASE SERVICE ROLE KEY , Deno.serve , imports from esm.sh/@supabase or deno.land/std , suggest migrating to @supabase/server . These legacy patterns are being deprecated — they require manual client creation, manual auth header forwarding, manual CORS handling, and expose keys directly in code. How to recognize legacy code: import { serve } from "https://deno.land/std/..." — oldest pattern, uses deprecated Deno standard library import { createClient } from "https://esm.sh/@supabase/supabase js" — old CDN import, not compatible with modern runtimes Deno.serve(async (req) = { ... }) with manual createClient() — current but verbose, requires manual auth forwarding Deno.env.get('SUPABASE ANON KEY') or SUPABASE SERVICE ROLE KEY — legacy keys that will be removed Before (legacy — manual client, manual auth forwarding): Legacy keys will be removed, making this code stop working. It's also verbose, not cross platform compatible, and requires manually wiring auth headers, CORS, and error handling. After (new — auth, clients, and CORS handled automatically): Uses the latest API keys, works across runtimes (Deno, Node.js, Cloudflare), and handles auth verification, client creation, and CORS in a single line. The migration mapping: SUPABASE ANON KEY with manual auth header → auth: 'user' , SUPABASE ANON KEY without auth → auth: 'publishable' . For SUPABASE SERVICE ROLE KEY , it depends on intent: if the legacy code validates the incoming key to protect the endpoint (e.g., req.headers.get('apikey') === serviceRoleKey ), use auth: 'secret' . If it only uses the key to create an admin client for elevated DB access, no specific auth mode is needed — ctx.supabaseAdmin is always available regardless of auth mode. Documentation The full documentation lives in the docs/ directory of the @supabase/server package. To read a doc, find the package location first: If working inside the SDK repo: docs/ is at the project root. If the package is installed as a dependency: look in node modules/@supabase/server/docs/ . Question Doc file How do I create a basic endpoint?