NEW Browse AI tools across categories — updated daily. See what's new →

Supabase Server

Use when writing server-side code with Supabase — Edge Functions, Hono apps, webhook handlers, or any backend that needs Supabase auth and client creation.…

Authorsupabase
Version1.0.0
LicenseMIT
Token count~4,832
UpdatedJun 5, 2026

Install

Quick install

via npx skills · works with 57+ agents
npx skills add https://github.com/supabase/server/tree/HEAD/skills/supabase-server
Or pick agent:
npx skills add supabase/server --skill supabase-server --agent claude-code
npx skills add supabase/server --skill supabase-server --agent cursor
npx skills add supabase/server --skill supabase-server --agent codex
npx skills add supabase/server --skill supabase-server --agent opencode
npx skills add supabase/server --skill supabase-server --agent github-copilot
npx skills add supabase/server --skill supabase-server --agent windsurf
More install options

Shorthand — useful for multi-skill repos:

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

Manual — clone the repo and drop the folder into your agent's skills directory:

git clone https://github.com/supabase/server.git
cp -r server/skills/supabase-server ~/.claude/skills/
How to use: Once installed, ask your agent to "use the supabase-server skill" or describe what you want (e.g. "Use when writing server-side code with Supabase — Edge Functions, Hono apps, web"). Requires Node.js 18+.

supabase-server

Use when writing server-side code with Supabase — Edge Functions, Hono apps, webhook handlers, or any backend that needs Supabase auth and client creation.…

supabase-serverby supabase

Use when writing server-side code with Supabase — Edge Functions, Hono apps, webhook handlers, or any backend that needs Supabase auth and client creation.…

npx skills add https://github.com/supabase/server --skill supabase-serverDownload ZIPGitHub

@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.

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_KEYSUPABASE_PUBLISHABLE_KEY(S) (sb_publishable_...)SUPABASE_SERVICE_ROLE_KEYSUPABASE_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

ImportDeno / Edge FunctionsProvides@supabase/servernpm:@supabase/serverwithSupabase, createSupabaseContext, types, errors@supabase/server/corenpm:@supabase/server/coreverifyAuth, verifyCredentials, extractCredentials, resolveEnv, createContextClient, createAdminClient@supabase/server/adapters/hononpm:@supabase/server/adapters/honowithSupabase (Hono middleware variant)

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.my-function]
verify_jwt = false
`

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.

`// withSupabase — high-level wrapper
import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => {
const { data } = await ctx.supabase.from('todos').select()
return Response.json(data)
}),
}
`
`// createSupabaseContext — returns { data, error } for custom response control
import { createSupabaseContext } from 'npm:@supabase/server'

export default {
fetch: async (req: Request) => {
const { data: ctx, error } = await createSupabaseContext(req, {
auth: 'user',
})
if (error) {
return Response.json(
{ message: error.message, code: error.code },
{ status: error.status },
)
}
const { data } = await ctx.supabase.from('todos').select()
return Response.json(data)
},
}
`

Cloudflare Workers

Requires nodejs_compat compatibility flag in wrangler.toml, or pass env overrides via the env config option. See docs/environment-variables.md.

`import { withSupabase } from '@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => {
const { data } = await ctx.supabase.from('todos').select()
return Response.json(data)
}),
}
`

Hono

CORS is not handled by the adapter — use hono/cors middleware. See docs/adapters/hono.md.

`// Node.js / Bun
import { Hono } from 'hono'
import { withSupabase } from '@supabase/server/adapters/hono'

const app = new Hono()
app.use('*', withSupabase({ auth: 'user' }))

app.get('/todos', async (c) => {
const { supabase } = c.var.supabaseContext
const { data } = await supabase.from('todos').select()
return c.json(data)
})

export default app
`
`// Deno / Supabase Edge Functions
import { Hono } from 'npm:hono'
import { withSupabase } from 'npm:@supabase/server/adapters/hono'

const app = new Hono()
app.use('*', withSupabase({ auth: 'user' }))

app.get('/todos', async (c) => {
const { supabase } = c.var.supabaseContext
const { data } = await supabase.from('todos').select()
return c.json(data)
})

export default { fetch: app.fetch }
`

Cookie-based environments (compose with @supabase/ssr)

For Next.js / SvelteKit / Remix, compose @supabase/server with @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.

`// Key imports for building the adapter
import { createServerClient } from '@supabase/ssr'
import {
verifyCredentials,
createContextClient,
createAdminClient,
} from '@supabase/server/core'
`

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):

`import { withSupabase } from 'npm:@supabase/server'

// Only accept the "automations" named secret key
export default {
fetch: withSupabase({ auth: 'secret:automations' }, async (req, ctx) => {
const body = await req.json()
const { data } = await ctx.supabaseAdmin
.from('scheduled_tasks')
.insert({ name: body.taskName, scheduled_at: body.scheduledAt })
return Response.json({ success: true, data })
}),
}
`

Caller (external service):

`await fetch('https://<project>.supabase.co/functions/v1/my-function', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
apikey: 'sb_secret_automations_...', // the named secret key
},
body: JSON.stringify({
taskName: 'cleanup',
scheduledAt: new Date().toISOString(),
}),
})
`

Use auth: 'secret' to accept any secret key, or auth: 'secret:name' to require a specific named key.

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.

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):

`[functions.process-order]
verify_jwt = false # called with secret key, not a user JWT
`

Called function (supabase/functions/process-order/index.ts):

`import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'secret' }, async (req, ctx) => {
const { orderId } = await req.json()
const { data } = await ctx.supabaseAdmin
.from('orders')
.update({ status: 'processing' })
.eq('id', orderId)
.select()
.single()
return Response.json(data)
}),
}
`

Calling function (supabase/functions/checkout/index.ts):

`import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (req, ctx) => {
const { orderId } = await req.json()

// Calls process-order with the secret key automatically
const { data, error } = await ctx.supabaseAdmin.functions.invoke(
'process-order',
{ body: { orderId } },
)

if (error) {
return Response.json({ error: error.message }, { status: 500 })
}
return Response.json(data)
}),
}
`

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:

`-- 1. Enable the pg_net extension
create extension if not exists pg_net with schema extensions;

-- 2. Store your secret key in Vault
select vault.create_secret(
'sb_secret_...', -- your secret key value
'supabase_secret_key' -- a name to reference it by
);
`

Call the function:

`select net.http_post(
url := 'https://<project-ref>.supabase.co/functions/v1/process-order',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'apikey', (
select decrypted_secret
from vault.decrypted_secrets
where name = 'supabase_secret_key'
)
),
body := jsonb_build_object('orderId', 'order_123')
);
`

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):

`[functions.stripe-webhook]
verify_jwt = false
`

Set secrets:

`supabase secrets set STRIPE_SECRET_KEY=sk_live_...
supabase secrets set STRIPE_WEBHOOK_SECRET=whsec_...
`

Function (supabase/functions/stripe-webhook/index.ts):

`import { withSupabase } from 'npm:@supabase/server'
import Stripe from 'npm:stripe'

const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY')!)

export default {
fetch: withSupabase({ auth: 'none' }, async (req, ctx) => {
const body = await req.text()
const sig = req.headers.get('stripe-signature')!

let event: Stripe.Event
try {
event = await stripe.webhooks.constructEventAsync(
body,
sig,
Deno.env.get('STRIPE_WEBHOOK_SECRET')!,
)
} catch {
return Response.json({ error: 'Invalid signature' }, { status: 401 })
}

switch (event.type) {
case 'checkout.session.completed': {
const session = event.data.object as Stripe.Checkout.Session
await ctx.supabaseAdmin
.from('orders')
.update({ status: 'paid' })
.eq('stripe_session_id', session.id)
break
}
}

return Response.json({ received: true })
}),
}
`

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.

`import { createClient } from 'npm:@supabase/supabase-js@2'

Deno.serve(async (req: Request) => {
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{
global: { headers: { Authorization: req.headers.get('Authorization')! } },
},
)
const { data } = await supabaseClient.from('orders').select('*')
return Response.json(data)
})
`

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.

`import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => {
const { data } = await ctx.supabase.from('orders').select('*')
return Response.json(data)
}),
}
`

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/.

QuestionDoc fileHow do I create a basic endpoint?docs/getting-started.mdWhat auth modes are available? Array syntax? Named keys?docs/auth-modes.mdWhich framework adapters exist? How do I contribute one?src/adapters/README.mdHow do I use this with Hono?docs/adapters/hono.mdHow do I use this with H3 / Nuxt?docs/adapters/h3.mdHow do I use low-level primitives for custom flows?docs/core-primitives.mdHow do environment variables work across runtimes?docs/environment-variables.mdHow do I handle errors? What codes exist?docs/error-handling.mdHow do I get typed database queries?docs/typescript-generics.mdHow do I use this with @supabase/ssr (Next.js, SvelteKit, Remix)?docs/ssr-frameworks.mdWhat's the complete API surface?docs/api-reference.mdWhat security decisions does this package make?docs/security.md

More skills from supabase

skill-creatorby supabaseComprehensive guide for creating modular skills that extend Claude's capabilities with specialized knowledge and workflows. Skills consist of a required SKILL.md file with YAML frontmatter and markdown instructions, plus optional bundled resources (scripts, references, assets) organized by purpose and loaded progressively to conserve context Design skills around concrete usage examples; identify reusable scripts for deterministic tasks, reference files for domain knowledge, and assets for...supabaseby supabaseUse when doing ANY task involving Supabase. Triggers: Supabase products (Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues); client…supabase-postgres-best-practicesby supabasePostgres performance optimization rules across 8 priority categories, from query tuning to advanced features. Organized into 8 rule categories prioritized by impact: query performance and connection management (critical), security and RLS, schema design, concurrency, data access patterns, monitoring, and advanced features Each rule includes detailed explanations, incorrect vs. correct SQL examples, EXPLAIN output analysis, and performance metrics to guide optimization decisions Covers query...dev-toolbar-reviewby supabaseUse when reviewing PRs that touch packages/dev-tools/, packages/common/posthog-client.ts,e2e-studio-testsby supabaseRun e2e tests in the Studio app. Use when asked to run e2e tests, run studio tests, playwright tests, or test the feature.studio-best-practicesby supabaseReact and TypeScript best practices for Supabase Studio. Use when writingstudio-e2e-testsby supabaseWrite and run Playwright E2E tests for Supabase Studio. Use when askedstudio-error-handlingby supabaseError display and troubleshooting pattern for Supabase Studio. Use when

---

Source: https://github.com/supabase/server/tree/HEAD/skills/supabase-server
Author: supabase
Discovered via: mcpservers.org

SKILL.md source

---
name: supabase-server
description: Use when writing server-side code with Supabase — Edge Functions, Hono apps, webhook handlers, or any backend that needs Supabase auth and client creation.…
---

# supabase-server

Use when writing server-side code with Supabase — Edge Functions, Hono apps, webhook handlers, or any backend that needs Supabase auth and client creation.…

# supabase-serverby supabase
Use when writing server-side code with Supabase — Edge Functions, Hono apps, webhook handlers, or any backend that needs Supabase auth and client creation.…

`npx skills add https://github.com/supabase/server --skill supabase-server`Download ZIPGitHub

## @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.

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

ImportDeno / Edge FunctionsProvides`@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)

## 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.my-function]
verify_jwt = false
`
```

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.

```
`// withSupabase — high-level wrapper
import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => {
const { data } = await ctx.supabase.from('todos').select()
return Response.json(data)
}),
}
`
```

```
`// createSupabaseContext — returns { data, error } for custom response control
import { createSupabaseContext } from 'npm:@supabase/server'

export default {
fetch: async (req: Request) => {
const { data: ctx, error } = await createSupabaseContext(req, {
auth: 'user',
})
if (error) {
return Response.json(
{ message: error.message, code: error.code },
{ status: error.status },
)
}
const { data } = await ctx.supabase.from('todos').select()
return Response.json(data)
},
}
`
```

### Cloudflare Workers

Requires `nodejs_compat` compatibility flag in `wrangler.toml`, or pass env overrides via the `env` config option. See `docs/environment-variables.md`.

```
`import { withSupabase } from '@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => {
const { data } = await ctx.supabase.from('todos').select()
return Response.json(data)
}),
}
`
```

### Hono

CORS is not handled by the adapter — use `hono/cors` middleware. See `docs/adapters/hono.md`.

```
`// Node.js / Bun
import { Hono } from 'hono'
import { withSupabase } from '@supabase/server/adapters/hono'

const app = new Hono()
app.use('*', withSupabase({ auth: 'user' }))

app.get('/todos', async (c) => {
const { supabase } = c.var.supabaseContext
const { data } = await supabase.from('todos').select()
return c.json(data)
})

export default app
`
```

```
`// Deno / Supabase Edge Functions
import { Hono } from 'npm:hono'
import { withSupabase } from 'npm:@supabase/server/adapters/hono'

const app = new Hono()
app.use('*', withSupabase({ auth: 'user' }))

app.get('/todos', async (c) => {
const { supabase } = c.var.supabaseContext
const { data } = await supabase.from('todos').select()
return c.json(data)
})

export default { fetch: app.fetch }
`
```

### Cookie-based environments (compose with `@supabase/ssr`)

For Next.js / SvelteKit / Remix, compose `@supabase/server` with `@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.

```
`// Key imports for building the adapter
import { createServerClient } from '@supabase/ssr'
import {
verifyCredentials,
createContextClient,
createAdminClient,
} from '@supabase/server/core'
`
```

### 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):

```
`import { withSupabase } from 'npm:@supabase/server'

// Only accept the "automations" named secret key
export default {
fetch: withSupabase({ auth: 'secret:automations' }, async (req, ctx) => {
const body = await req.json()
const { data } = await ctx.supabaseAdmin
.from('scheduled_tasks')
.insert({ name: body.taskName, scheduled_at: body.scheduledAt })
return Response.json({ success: true, data })
}),
}
`
```

Caller (external service):

```
`await fetch('https://<project>.supabase.co/functions/v1/my-function', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
apikey: 'sb_secret_automations_...', // the named secret key
},
body: JSON.stringify({
taskName: 'cleanup',
scheduledAt: new Date().toISOString(),
}),
})
`
```

Use `auth: 'secret'` to accept any secret key, or `auth: 'secret:name'` to require a specific named key.

## 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.

## 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`):

```
`[functions.process-order]
verify_jwt = false # called with secret key, not a user JWT
`
```

Called function (`supabase/functions/process-order/index.ts`):

```
`import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'secret' }, async (req, ctx) => {
const { orderId } = await req.json()
const { data } = await ctx.supabaseAdmin
.from('orders')
.update({ status: 'processing' })
.eq('id', orderId)
.select()
.single()
return Response.json(data)
}),
}
`
```

Calling function (`supabase/functions/checkout/index.ts`):

```
`import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (req, ctx) => {
const { orderId } = await req.json()

// Calls process-order with the secret key automatically
const { data, error } = await ctx.supabaseAdmin.functions.invoke(
'process-order',
{ body: { orderId } },
)

if (error) {
return Response.json({ error: error.message }, { status: 500 })
}
return Response.json(data)
}),
}
`
```

### 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:

```
`-- 1. Enable the pg_net extension
create extension if not exists pg_net with schema extensions;

-- 2. Store your secret key in Vault
select vault.create_secret(
'sb_secret_...', -- your secret key value
'supabase_secret_key' -- a name to reference it by
);
`
```

Call the function:

```
`select net.http_post(
url := 'https://<project-ref>.supabase.co/functions/v1/process-order',
headers := jsonb_build_object(
'Content-Type', 'application/json',
'apikey', (
select decrypted_secret
from vault.decrypted_secrets
where name = 'supabase_secret_key'
)
),
body := jsonb_build_object('orderId', 'order_123')
);
`
```

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`):

```
`[functions.stripe-webhook]
verify_jwt = false
`
```

Set secrets:

```
`supabase secrets set STRIPE_SECRET_KEY=sk_live_...
supabase secrets set STRIPE_WEBHOOK_SECRET=whsec_...
`
```

Function (`supabase/functions/stripe-webhook/index.ts`):

```
`import { withSupabase } from 'npm:@supabase/server'
import Stripe from 'npm:stripe'

const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY')!)

export default {
fetch: withSupabase({ auth: 'none' }, async (req, ctx) => {
const body = await req.text()
const sig = req.headers.get('stripe-signature')!

let event: Stripe.Event
try {
event = await stripe.webhooks.constructEventAsync(
body,
sig,
Deno.env.get('STRIPE_WEBHOOK_SECRET')!,
)
} catch {
return Response.json({ error: 'Invalid signature' }, { status: 401 })
}

switch (event.type) {
case 'checkout.session.completed': {
const session = event.data.object as Stripe.Checkout.Session
await ctx.supabaseAdmin
.from('orders')
.update({ status: 'paid' })
.eq('stripe_session_id', session.id)
break
}
}

return Response.json({ received: true })
}),
}
`
```

### 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.

```
`import { createClient } from 'npm:@supabase/supabase-js@2'

Deno.serve(async (req: Request) => {
const supabaseClient = createClient(
Deno.env.get('SUPABASE_URL') ?? '',
Deno.env.get('SUPABASE_ANON_KEY') ?? '',
{
global: { headers: { Authorization: req.headers.get('Authorization')! } },
},
)
const { data } = await supabaseClient.from('orders').select('*')
return Response.json(data)
})
`
```

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.

```
`import { withSupabase } from 'npm:@supabase/server'

export default {
fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => {
const { data } = await ctx.supabase.from('orders').select('*')
return Response.json(data)
}),
}
`
```

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/`.

QuestionDoc fileHow do I create a basic endpoint?`docs/getting-started.md`What auth modes are available? Array syntax? Named keys?`docs/auth-modes.md`Which framework adapters exist? How do I contribute one?`src/adapters/README.md`How do I use this with Hono?`docs/adapters/hono.md`How do I use this with H3 / Nuxt?`docs/adapters/h3.md`How do I use low-level primitives for custom flows?`docs/core-primitives.md`How do environment variables work across runtimes?`docs/environment-variables.md`How do I handle errors? What codes exist?`docs/error-handling.md`How do I get typed database queries?`docs/typescript-generics.md`How do I use this with `@supabase/ssr` (Next.js, SvelteKit, Remix)?`docs/ssr-frameworks.md`What's the complete API surface?`docs/api-reference.md`What security decisions does this package make?`docs/security.md`

## More skills from supabase
skill-creatorby supabaseComprehensive guide for creating modular skills that extend Claude's capabilities with specialized knowledge and workflows. Skills consist of a required SKILL.md file with YAML frontmatter and markdown instructions, plus optional bundled resources (scripts, references, assets) organized by purpose and loaded progressively to conserve context Design skills around concrete usage examples; identify reusable scripts for deterministic tasks, reference files for domain knowledge, and assets for...supabaseby supabaseUse when doing ANY task involving Supabase. Triggers: Supabase products (Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron, Queues); client…supabase-postgres-best-practicesby supabasePostgres performance optimization rules across 8 priority categories, from query tuning to advanced features. Organized into 8 rule categories prioritized by impact: query performance and connection management (critical), security and RLS, schema design, concurrency, data access patterns, monitoring, and advanced features Each rule includes detailed explanations, incorrect vs. correct SQL examples, EXPLAIN output analysis, and performance metrics to guide optimization decisions Covers query...dev-toolbar-reviewby supabaseUse when reviewing PRs that touch packages/dev-tools/, packages/common/posthog-client.ts,e2e-studio-testsby supabaseRun e2e tests in the Studio app. Use when asked to run e2e tests, run studio tests, playwright tests, or test the feature.studio-best-practicesby supabaseReact and TypeScript best practices for Supabase Studio. Use when writingstudio-e2e-testsby supabaseWrite and run Playwright E2E tests for Supabase Studio. Use when askedstudio-error-handlingby supabaseError display and troubleshooting pattern for Supabase Studio. Use when

---

**Source**: https://github.com/supabase/server/tree/HEAD/skills/supabase-server
**Author**: supabase
**Discovered via**: mcpservers.org

Related skills 6

azure-storage

★ Featured Official

Azure Storage Services including Blob Storage, File Shares, Queue Storage, Table Storage, and Data Lake. Answers questions about storage access tiers (hot, cool, cold, archive), when to use each tier, and tier comparison. Provides object storage, SMB file shares, async messaging, NoSQL key-value, and big data analytics. Includes lifecycle management. USE FOR: blob storage, file shares, queue storage, table storage, data lake, upload files, download blobs, storage accounts, access tiers, stora...

microsoft 338k
Backend & Database

azure-kusto

★ Featured Official

Query and analyze data in Azure Data Explorer (Kusto/ADX) using KQL for log analytics, telemetry, and time series analysis. WHEN: KQL queries, Kusto database queries, Azure Data Explorer, ADX clusters, log analytics, time series data, IoT telemetry, anomaly detection.

microsoft 337k
Backend & Database

azure-aigateway

★ Featured Official

Configure Azure API Management as an AI Gateway for AI models, MCP tools, and agents. WHEN: semantic caching, token limit, content safety, load balancing, AI model governance, MCP rate limiting, jailbreak detection, add Azure OpenAI backend, add AI Foundry model, test AI gateway, LLM policies, configure AI backend, token metrics, AI cost control, convert API to MCP, import OpenAPI to gateway.

microsoft 337k
Backend & Database

azure-compute

★ Featured Official

Azure VM and VMSS router for recommendations, pricing, autoscale, orchestration, connectivity troubleshooting, capacity reservations, and Essential Machine Management. WHEN: Azure VM, VMSS, scale set, recommend, compare, server, website, burstable, lightweight, VM family, workload, GPU, learning, simulation, dev/test, backend, autoscale, load balancer, Flexible orchestration, Uniform orchestration, cost estimate, connect, refused, Linux, black screen, reset password, reach VM, port 3389, NSG,...

microsoft 281k
Backend & Database

azure-cloud-migrate

★ Featured Official

Assess and migrate cross-cloud workloads to Azure with reports and code conversion. Supports Lambda→Functions, Beanstalk/Heroku/App Engine→App Service, Fargate/Kubernetes/Cloud Run/Spring Boot→Container Apps. WHEN: migrate Lambda to Functions, AWS to Azure, migrate Beanstalk, migrate Heroku, migrate App Engine, Cloud Run migration, Fargate to ACA, ECS/Kubernetes/GKE/EKS to Container Apps, Spring Boot to Container Apps, cross-cloud migration.

microsoft 271k
Backend & Database

azure-upgrade

★ Featured Official

Assess and upgrade Azure workloads between plans, tiers, or SKUs, or modernize Azure SDK dependencies in source code. WHEN: upgrade Consumption to Flex Consumption, upgrade Azure Functions plan, change hosting plan, function app SKU, migrate App Service to Container Apps, modernize legacy Azure Java SDKs (com.microsoft.azure to com.azure), migrate Azure Cache for Redis (ACR/ACRE) to Azure Managed Redis (AMR).

microsoft 201k
Backend & Database