Server: withSupabaseAdminClient

Alpha. Contributes ctx.supabaseAdmin — an admin Supabase client that bypasses Row-Level Security, authenticated with a secret key. This is the same middleware withSupabase composes internally to build its context.

The client is constructed on the first property access of ctx.supabaseAdmin and memoized for the request. A handler that never accesses it requires no secret key.

Parameters

Examples

Standalone pipeline

import { pipeline } from '@supabase/middleware'
import { withSupabaseAdminClient } from '@supabase/server/middleware/admin-client'

export default {
  fetch: pipeline([withSupabaseAdminClient()], async (req, ctx) => {
    await ctx.supabaseAdmin.from('audit_log').insert({ action: 'ping' })
    return Response.json({ ok: true })
  }),
}

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