@supabase/server 0.2.0-rc.44 → 0.2.0-rc.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -2
- package/dist/adapters/h3/index.cjs +59 -0
- package/dist/adapters/h3/index.d.cts +51 -0
- package/dist/adapters/h3/index.d.mts +51 -0
- package/dist/adapters/h3/index.mjs +58 -0
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.mts +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/package.json +12 -2
- /package/dist/{errors-CAH-RRA3.d.mts → errors-Dyj5Cjt6.d.cts} +0 -0
- /package/dist/{errors-O2ugIMec.d.cts → errors-m42mkqhD.d.mts} +0 -0
package/README.md
CHANGED
|
@@ -252,6 +252,56 @@ export default { fetch: app.fetch }
|
|
|
252
252
|
|
|
253
253
|
The adapter does not handle CORS — use `hono/cors` for that. Per-route auth works naturally by applying the middleware to specific routes.
|
|
254
254
|
|
|
255
|
+
### H3 / Nuxt
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
import { H3 } from 'h3'
|
|
259
|
+
import { withSupabase } from '@supabase/server/adapters/h3'
|
|
260
|
+
|
|
261
|
+
const app = new H3()
|
|
262
|
+
|
|
263
|
+
// Protected — withSupabase validates the JWT before the handler runs
|
|
264
|
+
app.use(withSupabase({ allow: 'user' }))
|
|
265
|
+
|
|
266
|
+
app.get('/games', async (event) => {
|
|
267
|
+
const { supabase } = event.context.supabaseContext
|
|
268
|
+
const { data: myGames } = await supabase.from('favorite_games').select()
|
|
269
|
+
return myGames
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
// Public — no middleware means no auth
|
|
273
|
+
app.get('/health', () => ({ status: 'ok' }))
|
|
274
|
+
|
|
275
|
+
export default { fetch: app.fetch }
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
For **Nuxt**, use `defineHandler` for file routes:
|
|
279
|
+
|
|
280
|
+
```ts
|
|
281
|
+
// server/api/games.get.ts
|
|
282
|
+
import { defineHandler } from 'h3'
|
|
283
|
+
import { withSupabase } from '@supabase/server/adapters/h3'
|
|
284
|
+
|
|
285
|
+
export default defineHandler({
|
|
286
|
+
middleware: [withSupabase({ allow: 'user' })],
|
|
287
|
+
handler: async (event) => {
|
|
288
|
+
const { supabase } = event.context.supabaseContext
|
|
289
|
+
return supabase.from('favorite_games').select()
|
|
290
|
+
},
|
|
291
|
+
})
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
For app-wide auth, register it as a server middleware:
|
|
295
|
+
|
|
296
|
+
```ts
|
|
297
|
+
// server/middleware/supabase.ts
|
|
298
|
+
import { withSupabase } from '@supabase/server/adapters/h3'
|
|
299
|
+
|
|
300
|
+
export default withSupabase({ allow: 'user' })
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
The adapter does not handle CORS — use H3's CORS utilities for that.
|
|
304
|
+
|
|
255
305
|
## Primitives
|
|
256
306
|
|
|
257
307
|
For when you need more control than `withSupabase` provides — multiple routes with different auth, custom response headers, or building your own wrapper.
|
|
@@ -377,9 +427,10 @@ For other environments, pass overrides via the `env` config option or `resolveEn
|
|
|
377
427
|
|
|
378
428
|
- **Supabase Edge Functions** — environment variables are auto-injected. Zero config.
|
|
379
429
|
- **Deno / Bun** — works out of the box with the `export default { fetch }` pattern.
|
|
380
|
-
- **Node.js** — use the [Hono adapter](#hono) or [core primitives](#primitives) with your framework of choice.
|
|
430
|
+
- **Node.js** — use the [Hono adapter](#hono), [H3 adapter](#h3--nuxt), or [core primitives](#primitives) with your framework of choice.
|
|
381
431
|
- **Cloudflare Workers** — enable `nodejs_compat` in `wrangler.toml` or pass env overrides via the `env` config option.
|
|
382
|
-
- **
|
|
432
|
+
- **Nuxt** — use the [H3 adapter](#h3--nuxt) directly as a server middleware.
|
|
433
|
+
- **Next.js / SvelteKit / Remix** — use core primitives to build a cookie-based auth adapter. See [`docs/ssr-frameworks.md`](docs/ssr-frameworks.md).
|
|
383
434
|
|
|
384
435
|
## Exports
|
|
385
436
|
|
|
@@ -388,6 +439,7 @@ For other environments, pass overrides via the `env` config option or `resolveEn
|
|
|
388
439
|
| `@supabase/server` | `withSupabase`, `createSupabaseContext` |
|
|
389
440
|
| `@supabase/server/core` | `verifyAuth`, `verifyCredentials`, `extractCredentials`, `createContextClient`, `createAdminClient`, `resolveEnv` |
|
|
390
441
|
| `@supabase/server/adapters/hono` | `withSupabase` (Hono middleware) |
|
|
442
|
+
| `@supabase/server/adapters/h3` | `withSupabase` (H3 / Nuxt middleware) |
|
|
391
443
|
|
|
392
444
|
## Documentation
|
|
393
445
|
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_create_supabase_context = require('../../create-supabase-context-C_8SbO5w.cjs');
|
|
3
|
+
let h3 = require("h3");
|
|
4
|
+
|
|
5
|
+
//#region src/adapters/h3/middleware.ts
|
|
6
|
+
/**
|
|
7
|
+
* H3 middleware that creates a {@link SupabaseContext} and stores it in `event.context.supabaseContext`.
|
|
8
|
+
*
|
|
9
|
+
* Skips if a previous middleware already set the context, enabling chained middleware via `app.use()`.
|
|
10
|
+
* Throws an `HTTPError` on auth failure.
|
|
11
|
+
*
|
|
12
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use H3's CORS utilities.
|
|
13
|
+
* @returns An H3 middleware.
|
|
14
|
+
*
|
|
15
|
+
* @example App-wide auth via `app.use()`
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { H3 } from 'h3'
|
|
18
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
19
|
+
*
|
|
20
|
+
* const app = new H3()
|
|
21
|
+
* app.use(withSupabase({ allow: 'user' }))
|
|
22
|
+
*
|
|
23
|
+
* app.get('/games', async (event) => {
|
|
24
|
+
* const { supabase } = event.context.supabaseContext
|
|
25
|
+
* return supabase.from('favorite_games').select()
|
|
26
|
+
* })
|
|
27
|
+
*
|
|
28
|
+
* export default { fetch: app.fetch }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example Per-route auth via `defineHandler`
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { defineHandler } from 'h3'
|
|
34
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
35
|
+
*
|
|
36
|
+
* export default defineHandler({
|
|
37
|
+
* middleware: [withSupabase({ allow: 'user' })],
|
|
38
|
+
* handler: async (event) => {
|
|
39
|
+
* const { supabase } = event.context.supabaseContext
|
|
40
|
+
* return supabase.from('favorite_games').select()
|
|
41
|
+
* },
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
function withSupabase(config) {
|
|
46
|
+
return (0, h3.defineMiddleware)(async (event, next) => {
|
|
47
|
+
if (event.context.supabaseContext) return next();
|
|
48
|
+
const { data: ctx, error } = await require_create_supabase_context.createSupabaseContext(event.req, config);
|
|
49
|
+
if (error) throw new h3.HTTPError(error.message, {
|
|
50
|
+
status: error.status,
|
|
51
|
+
cause: error
|
|
52
|
+
});
|
|
53
|
+
event.context.supabaseContext = ctx;
|
|
54
|
+
return next();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
exports.withSupabase = withSupabase;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { f as WithSupabaseConfig, l as SupabaseContext } from "../../types-DqhOaSlC.cjs";
|
|
2
|
+
import { Middleware } from "h3";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/h3/middleware.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* H3 middleware that creates a {@link SupabaseContext} and stores it in `event.context.supabaseContext`.
|
|
7
|
+
*
|
|
8
|
+
* Skips if a previous middleware already set the context, enabling chained middleware via `app.use()`.
|
|
9
|
+
* Throws an `HTTPError` on auth failure.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use H3's CORS utilities.
|
|
12
|
+
* @returns An H3 middleware.
|
|
13
|
+
*
|
|
14
|
+
* @example App-wide auth via `app.use()`
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { H3 } from 'h3'
|
|
17
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
18
|
+
*
|
|
19
|
+
* const app = new H3()
|
|
20
|
+
* app.use(withSupabase({ allow: 'user' }))
|
|
21
|
+
*
|
|
22
|
+
* app.get('/games', async (event) => {
|
|
23
|
+
* const { supabase } = event.context.supabaseContext
|
|
24
|
+
* return supabase.from('favorite_games').select()
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* export default { fetch: app.fetch }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Per-route auth via `defineHandler`
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { defineHandler } from 'h3'
|
|
33
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
34
|
+
*
|
|
35
|
+
* export default defineHandler({
|
|
36
|
+
* middleware: [withSupabase({ allow: 'user' })],
|
|
37
|
+
* handler: async (event) => {
|
|
38
|
+
* const { supabase } = event.context.supabaseContext
|
|
39
|
+
* return supabase.from('favorite_games').select()
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function withSupabase(config?: Omit<WithSupabaseConfig, 'cors'>): Middleware;
|
|
45
|
+
declare module 'h3' {
|
|
46
|
+
interface H3EventContext {
|
|
47
|
+
supabaseContext: SupabaseContext;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { withSupabase };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { f as WithSupabaseConfig, l as SupabaseContext } from "../../types-DKe8uOwI.mjs";
|
|
2
|
+
import { Middleware } from "h3";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/h3/middleware.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* H3 middleware that creates a {@link SupabaseContext} and stores it in `event.context.supabaseContext`.
|
|
7
|
+
*
|
|
8
|
+
* Skips if a previous middleware already set the context, enabling chained middleware via `app.use()`.
|
|
9
|
+
* Throws an `HTTPError` on auth failure.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use H3's CORS utilities.
|
|
12
|
+
* @returns An H3 middleware.
|
|
13
|
+
*
|
|
14
|
+
* @example App-wide auth via `app.use()`
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { H3 } from 'h3'
|
|
17
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
18
|
+
*
|
|
19
|
+
* const app = new H3()
|
|
20
|
+
* app.use(withSupabase({ allow: 'user' }))
|
|
21
|
+
*
|
|
22
|
+
* app.get('/games', async (event) => {
|
|
23
|
+
* const { supabase } = event.context.supabaseContext
|
|
24
|
+
* return supabase.from('favorite_games').select()
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* export default { fetch: app.fetch }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Per-route auth via `defineHandler`
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { defineHandler } from 'h3'
|
|
33
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
34
|
+
*
|
|
35
|
+
* export default defineHandler({
|
|
36
|
+
* middleware: [withSupabase({ allow: 'user' })],
|
|
37
|
+
* handler: async (event) => {
|
|
38
|
+
* const { supabase } = event.context.supabaseContext
|
|
39
|
+
* return supabase.from('favorite_games').select()
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
declare function withSupabase(config?: Omit<WithSupabaseConfig, 'cors'>): Middleware;
|
|
45
|
+
declare module 'h3' {
|
|
46
|
+
interface H3EventContext {
|
|
47
|
+
supabaseContext: SupabaseContext;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
export { withSupabase };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { t as createSupabaseContext } from "../../create-supabase-context-DXD5rxi1.mjs";
|
|
2
|
+
import { HTTPError, defineMiddleware } from "h3";
|
|
3
|
+
|
|
4
|
+
//#region src/adapters/h3/middleware.ts
|
|
5
|
+
/**
|
|
6
|
+
* H3 middleware that creates a {@link SupabaseContext} and stores it in `event.context.supabaseContext`.
|
|
7
|
+
*
|
|
8
|
+
* Skips if a previous middleware already set the context, enabling chained middleware via `app.use()`.
|
|
9
|
+
* Throws an `HTTPError` on auth failure.
|
|
10
|
+
*
|
|
11
|
+
* @param config - Auth modes and optional environment overrides. CORS is excluded — use H3's CORS utilities.
|
|
12
|
+
* @returns An H3 middleware.
|
|
13
|
+
*
|
|
14
|
+
* @example App-wide auth via `app.use()`
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { H3 } from 'h3'
|
|
17
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
18
|
+
*
|
|
19
|
+
* const app = new H3()
|
|
20
|
+
* app.use(withSupabase({ allow: 'user' }))
|
|
21
|
+
*
|
|
22
|
+
* app.get('/games', async (event) => {
|
|
23
|
+
* const { supabase } = event.context.supabaseContext
|
|
24
|
+
* return supabase.from('favorite_games').select()
|
|
25
|
+
* })
|
|
26
|
+
*
|
|
27
|
+
* export default { fetch: app.fetch }
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @example Per-route auth via `defineHandler`
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { defineHandler } from 'h3'
|
|
33
|
+
* import { withSupabase } from '@supabase/server/adapters/h3'
|
|
34
|
+
*
|
|
35
|
+
* export default defineHandler({
|
|
36
|
+
* middleware: [withSupabase({ allow: 'user' })],
|
|
37
|
+
* handler: async (event) => {
|
|
38
|
+
* const { supabase } = event.context.supabaseContext
|
|
39
|
+
* return supabase.from('favorite_games').select()
|
|
40
|
+
* },
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
function withSupabase(config) {
|
|
45
|
+
return defineMiddleware(async (event, next) => {
|
|
46
|
+
if (event.context.supabaseContext) return next();
|
|
47
|
+
const { data: ctx, error } = await createSupabaseContext(event.req, config);
|
|
48
|
+
if (error) throw new HTTPError(error.message, {
|
|
49
|
+
status: error.status,
|
|
50
|
+
cause: error
|
|
51
|
+
});
|
|
52
|
+
event.context.supabaseContext = ctx;
|
|
53
|
+
return next();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { withSupabase };
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as CreateAdminClientOptions, i as ClientAuth, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, u as SupabaseEnv } from "../types-DqhOaSlC.cjs";
|
|
2
|
-
import { i as EnvError, t as AuthError } from "../errors-
|
|
2
|
+
import { i as EnvError, t as AuthError } from "../errors-Dyj5Cjt6.cjs";
|
|
3
3
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
4
4
|
|
|
5
5
|
//#region src/core/resolve-env.d.ts
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as CreateAdminClientOptions, i as ClientAuth, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, u as SupabaseEnv } from "../types-DKe8uOwI.mjs";
|
|
2
|
-
import { i as EnvError, t as AuthError } from "../errors-
|
|
2
|
+
import { i as EnvError, t as AuthError } from "../errors-m42mkqhD.mjs";
|
|
3
3
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
4
4
|
|
|
5
5
|
//#region src/core/resolve-env.d.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as CreateAdminClientOptions, c as JWTClaims, d as UserClaims, f as WithSupabaseConfig, i as ClientAuth, l as SupabaseContext, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, t as Allow, u as SupabaseEnv } from "./types-DqhOaSlC.cjs";
|
|
2
|
-
import { a as EnvGenericError, c as MissingDefaultPublishableKeyError, d as MissingSecretKeyError, f as MissingSupabaseURLError, i as EnvError, l as MissingDefaultSecretKeyError, n as AuthGenericError, o as Errors, r as CreateSupabaseClientError, s as InvalidCredentialsError, t as AuthError, u as MissingPublishableKeyError } from "./errors-
|
|
2
|
+
import { a as EnvGenericError, c as MissingDefaultPublishableKeyError, d as MissingSecretKeyError, f as MissingSupabaseURLError, i as EnvError, l as MissingDefaultSecretKeyError, n as AuthGenericError, o as Errors, r as CreateSupabaseClientError, s as InvalidCredentialsError, t as AuthError, u as MissingPublishableKeyError } from "./errors-Dyj5Cjt6.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/with-supabase.d.ts
|
|
5
5
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as CreateAdminClientOptions, c as JWTClaims, d as UserClaims, f as WithSupabaseConfig, i as ClientAuth, l as SupabaseContext, n as AllowWithKey, o as CreateContextClientOptions, r as AuthResult, s as Credentials, t as Allow, u as SupabaseEnv } from "./types-DKe8uOwI.mjs";
|
|
2
|
-
import { a as EnvGenericError, c as MissingDefaultPublishableKeyError, d as MissingSecretKeyError, f as MissingSupabaseURLError, i as EnvError, l as MissingDefaultSecretKeyError, n as AuthGenericError, o as Errors, r as CreateSupabaseClientError, s as InvalidCredentialsError, t as AuthError, u as MissingPublishableKeyError } from "./errors-
|
|
2
|
+
import { a as EnvGenericError, c as MissingDefaultPublishableKeyError, d as MissingSecretKeyError, f as MissingSupabaseURLError, i as EnvError, l as MissingDefaultSecretKeyError, n as AuthGenericError, o as Errors, r as CreateSupabaseClientError, s as InvalidCredentialsError, t as AuthError, u as MissingPublishableKeyError } from "./errors-m42mkqhD.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/with-supabase.d.ts
|
|
5
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supabase/server",
|
|
3
|
-
"version": "0.2.0-rc.
|
|
3
|
+
"version": "0.2.0-rc.46",
|
|
4
4
|
"description": "Server-side utilities for Supabase. Handles auth, client creation, and context injection so you write business logic, not boilerplate.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"edge",
|
|
@@ -34,6 +34,11 @@
|
|
|
34
34
|
"import": "./dist/adapters/hono/index.mjs",
|
|
35
35
|
"require": "./dist/adapters/hono/index.cjs"
|
|
36
36
|
},
|
|
37
|
+
"./adapters/h3": {
|
|
38
|
+
"types": "./dist/adapters/h3/index.d.mts",
|
|
39
|
+
"import": "./dist/adapters/h3/index.mjs",
|
|
40
|
+
"require": "./dist/adapters/h3/index.cjs"
|
|
41
|
+
},
|
|
37
42
|
"./package.json": "./package.json"
|
|
38
43
|
},
|
|
39
44
|
"main": "./dist/index.cjs",
|
|
@@ -69,9 +74,13 @@
|
|
|
69
74
|
},
|
|
70
75
|
"peerDependencies": {
|
|
71
76
|
"@supabase/supabase-js": "^2.0.0",
|
|
72
|
-
"hono": "^4.0.0"
|
|
77
|
+
"hono": "^4.0.0",
|
|
78
|
+
"h3": "^2.0.0"
|
|
73
79
|
},
|
|
74
80
|
"peerDependenciesMeta": {
|
|
81
|
+
"h3": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
75
84
|
"hono": {
|
|
76
85
|
"optional": true
|
|
77
86
|
}
|
|
@@ -81,6 +90,7 @@
|
|
|
81
90
|
"@commitlint/config-conventional": "^20.4.2",
|
|
82
91
|
"@supabase/supabase-js": "^2.98.0",
|
|
83
92
|
"eslint": "^10.0.2",
|
|
93
|
+
"h3": "2.0.1-rc.20",
|
|
84
94
|
"hono": "^4.12.5",
|
|
85
95
|
"prettier": "3.8.1",
|
|
86
96
|
"pretty-quick": "^4.2.2",
|
|
File without changes
|
|
File without changes
|