Thrown when authentication or authorization fails.
Carries an HTTP status code suitable for returning directly in a response (typically 401 for invalid credentials, 500 for server-side auth failures).
HTTP status code. - `401` — Invalid or missing credentials - `500` — Server-side auth failure (e.g., missing JWKS, env misconfiguration)
Machine-readable error code.
import { AuthError, createSupabaseContext } from '@supabase/server'
const { data: ctx, error } = await createSupabaseContext(request, { auth: 'user' })
if (error) {
// error is an AuthError
return Response.json(
{ message: error.message, code: error.code },
{ status: error.status },
)
}