|
1 | 1 | import { addCorsHeaders, buildCorsHeaders, isCorsDisabled } from './cors.js' |
2 | 2 | import { createSupabaseContext } from './create-supabase-context.js' |
3 | 3 | import type { SupabaseContext, WithSupabaseConfig } from './types.js' |
4 | | -import type { Entry } from '@supabase/web-middleware' |
| 4 | +import { seedContext } from '@supabase/middleware' |
| 5 | +import type { Entry } from '@supabase/middleware' |
5 | 6 |
|
6 | 7 | type AnyEntry = Entry<string, object, unknown> |
7 | 8 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
8 | 9 | type AnyHandler = (req: Request, ctx: any) => Promise<Response> |
9 | 10 |
|
10 | 11 | /** |
11 | 12 | * Accumulate the ctx contributions of a middleware tuple — same logic as |
12 | | - * `pipeline`'s internal `Accumulate`, seeded from `object` (no `BaseContext` |
13 | | - * or `_runtime` in the visible ctx type; see implementation note below). |
| 13 | + * `pipeline`'s internal `Accumulate`, seeded from `object` (the engine reserves |
| 14 | + * no ctx keys; see implementation note below). |
14 | 15 | */ |
15 | 16 | type MiddlewareCtx<Entries extends readonly AnyEntry[]> = |
16 | 17 | Entries extends readonly [ |
@@ -55,7 +56,7 @@ export function withSupabase<Database = unknown>( |
55 | 56 |
|
56 | 57 | /** |
57 | 58 | * Variant that accepts a `middleware` array — each `withFoo(config)` call |
58 | | - * returns an `Entry` from `@supabase/web-middleware`. Middleware run **after** |
| 59 | + * returns an `Entry` from `@supabase/middleware`. Middleware run **after** |
59 | 60 | * the Supabase context is established; they receive `ctx.supabase`, |
60 | 61 | * `ctx.userClaims`, etc. already present and contribute their own typed keys |
61 | 62 | * on top. (This is the server leg of a Plugin: the package's middleware goes |
@@ -86,7 +87,7 @@ export function withSupabase<Database = unknown>( |
86 | 87 | * (the Supabase context is merged before the middleware run) but not at the |
87 | 88 | * type level — a full implementation would widen the prerequisite-validation |
88 | 89 | * seed to include `SupabaseContext`. Ordering and collision checks within the |
89 | | - * middleware array work normally via `web-middleware`'s runtime chain. |
| 90 | + * middleware array work normally via `@supabase/middleware`'s runtime chain. |
90 | 91 | */ |
91 | 92 | export function withSupabase< |
92 | 93 | Database = unknown, |
@@ -135,19 +136,10 @@ export function withSupabase<Database = unknown>( |
135 | 136 | const composed = ( |
136 | 137 | config.middleware as readonly AnyEntry[] |
137 | 138 | ).reduceRight<AnyHandler>((h, entry) => entry(h), handler) |
138 | | - // Seed _runtime so web-middleware entries recognise this as an upstream |
139 | | - // context (isContext() checks for _runtime.getEnv). Falls through to |
140 | | - // process.env; a full implementation would bridge to SupabaseEnv. |
141 | | - const g = globalThis as { |
142 | | - process?: { env?: Record<string, string | undefined> } |
143 | | - } |
144 | | - response = await composed(req, { |
145 | | - ...ctx, |
146 | | - _runtime: { |
147 | | - name: 'unknown' as const, |
148 | | - getEnv: (key: string): string | undefined => g.process?.env?.[key], |
149 | | - }, |
150 | | - }) |
| 139 | + // seedContext() stamps the engine's context marker so middleware entries |
| 140 | + // recognise this as an upstream context. Env access happens through the |
| 141 | + // engine's importable getEnv — no per-ctx facet to bridge. |
| 142 | + response = await composed(req, { ...seedContext(), ...ctx }) |
151 | 143 | } else { |
152 | 144 | response = await handler(req, ctx as object) |
153 | 145 | } |
|
0 commit comments