Server: withSupabase

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.

Parameters

Examples

Basic usage

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)
  }),
}