Server: withSupabaseClient

Alpha. Contributes ctx.supabase — a Supabase client scoped to the caller's identity, so Row-Level Security policies apply. This is the same middleware withSupabase composes internally to build its context.

Standalone, the caller's Bearer token (when present) is attached unverified — PostgREST verifies it on every query. Compose middleware/claims!withClaims upstream when the pipeline itself needs verified claims.

Parameters

Examples

Standalone pipeline

import { pipeline } from '@supabase/middleware'
import { withSupabaseClient } from '@supabase/server/middleware/client'

export default {
  fetch: pipeline([withSupabaseClient()], async (req, ctx) => {
    const { data } = await ctx.supabase.from('posts').select('id, title')
    return Response.json(data)
  }),
}

The composable middleware surface tracks @supabase/middleware 0.x — entry shapes, context keys, and config options may change between 0.x releases.