Server: AuthError

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).

Parameters

Examples

Catching an AuthError

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 })
}