|
1 | 1 | /** |
2 | 2 | * Server-side Supabase utilities for modern runtimes. |
| 3 | + * |
| 4 | + * `@supabase/server` gives you batteries-included auth and client creation for |
| 5 | + * Edge Functions, Workers, and any server runtime that speaks standard `fetch`. |
| 6 | + * One import, one line of config — auth is verified, Supabase clients are ready, |
| 7 | + * CORS is handled. Your handler only runs on successful auth. |
| 8 | + * |
| 9 | + * ```ts |
| 10 | + * import { withSupabase } from '@supabase/server' |
| 11 | + * |
| 12 | + * export default { |
| 13 | + * fetch: withSupabase({ auth: 'user' }, async (_req, ctx) => { |
| 14 | + * const { data: myGames } = await ctx.supabase.from('favorite_games').select() |
| 15 | + * return Response.json(myGames) |
| 16 | + * }), |
| 17 | + * } |
| 18 | + * ``` |
| 19 | + * |
| 20 | + * ## Auth modes |
| 21 | + * |
| 22 | + * | Mode | Credential | Use case | |
| 23 | + * |------|-----------|----------| |
| 24 | + * | `"user"` | Valid JWT | Authenticated user endpoints | |
| 25 | + * | `"publishable"` | Publishable key | Client-facing, key-validated endpoints | |
| 26 | + * | `"secret"` | Secret key | Server-to-server, internal calls | |
| 27 | + * | `"none"` | None | Open endpoints | |
| 28 | + * |
| 29 | + * Array syntax tries modes in order — first match wins: |
| 30 | + * ```ts |
| 31 | + * withSupabase({ auth: ['user', 'secret'] }, handler) |
| 32 | + * ``` |
| 33 | + * |
| 34 | + * ## Framework adapters |
| 35 | + * |
| 36 | + * Adapters for Hono, H3 / Nuxt, Elysia, and NestJS ship inside this package: |
| 37 | + * |
| 38 | + * ```ts |
| 39 | + * import { withSupabase } from '@supabase/server/adapters/hono' |
| 40 | + * import { withSupabase } from '@supabase/server/adapters/h3' |
| 41 | + * import { withSupabase } from '@supabase/server/adapters/elysia' |
| 42 | + * import { withSupabase, SupabaseCtx } from '@supabase/server/adapters/nestjs' |
| 43 | + * ``` |
| 44 | + * |
| 45 | + * ## Composable primitives |
| 46 | + * |
| 47 | + * For custom flows, all lower-level functions are available from `@supabase/server/core`: |
| 48 | + * |
| 49 | + * ```ts |
| 50 | + * import { verifyAuth, createContextClient, createAdminClient } from '@supabase/server/core' |
| 51 | + * ``` |
| 52 | + * |
| 53 | + * ## Installation |
| 54 | + * |
| 55 | + * ```sh |
| 56 | + * npm install @supabase/server |
| 57 | + * # or |
| 58 | + * deno add jsr:@supabase/server |
| 59 | + * ``` |
| 60 | + * |
3 | 61 | * @module |
4 | 62 | * @packageDocumentation |
5 | 63 | */ |
|
0 commit comments