Server: createContextClient

Creates a Supabase client scoped to the caller's context.

Configured with a publishable key and (optionally) the caller's JWT, so Row-Level Security policies apply. Stateless — one client per request.

Which key is used

With auth.keyName set, that named key from SUPABASE_PUBLISHABLE_KEYS is used — and it throws if the key doesn't exist. With keyName omitted, the default key is used, falling back to the first key in the set when no default exists.

Note this differs from the "publishable" auth mode, which matches the default key only and never falls back — see index.AuthModeWithKey.

Parameters

Examples

With verified auth

const { data: auth } = await verifyAuth(request, { auth: 'user' })
const supabase = createContextClient({
  auth: { token: auth.token, keyName: auth.keyName },
})
const { data } = await supabase.rpc('get_my_items')