Wraps a request handler with Supabase auth, client creation, and CORS handling.
Built for the Web API Request/Response standard that all modern runtimes implement natively. Handles CORS preflight, credential verification, context creation, and error responses. Your handler only runs on successful auth.
Auth modes, CORS, and environment overrides. See WithSupabaseConfig.
Receives the `Request` and a fully-initialized SupabaseContext.
import { withSupabase } from '@supabase/server'
export default {
fetch: withSupabase({ auth: 'user' }, async (req, ctx) => {
const { data } = await ctx.supabase.rpc('get_my_profile')
return Response.json(data)
}),
}