Thrown when authentication or authorization fails.
Carries an HTTP status code suitable for returning directly in a response (401 when the request's credentials are at fault, 500 when the server is misconfigured and could not have authenticated anyone).
Always `"@supabase/server"`.
Machine-readable error code.
Actionable next step, when one applies.
Documentation URL for this error's `code`.
Structured, non-sensitive diagnostics — accepted auth modes, which credential headers were present, configured key *names*, JWT header fields. Never key values or token payloads.
HTTP status code. - `401` — The request's credentials are at fault (MissingCredentialsError, InvalidApiKeyError, InvalidJwtError). - `500` — The server is misconfigured (JwksNotConfiguredError, NoKeysConfiguredError, JwksFetchFailedError, CreateSupabaseClientError).
import { createSupabaseContext } from '@supabase/server'
const { data: ctx, error } = await createSupabaseContext(request, { auth: 'user' })
if (error) {
// error is an AuthError — `toJSON()` includes source, code, message, hint, docs, details
return Response.json(error.toJSON(), { status: error.status })
}