Server: AuthError

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

Parameters

Examples

Catching an AuthError

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