Claxx Auth
Docs
Sign in
User FAQ
  • Reset my password
  • I can't sign in
  • Didn't get reset email
  • Account linking
  • Session expiry
  • Two-factor auth
Admin Guides
Theme Studio
  • Overview
  • Layouts
  • Styling tokens
  • Concept copy
  • Assets & backgrounds
  • Advanced CSS
Admin Shell
  • Users
  • Providers
  • Clients
  • Invitations
Integrations
  • OIDC flow
  • Provider token brokering
  • Email triggers
  • Webhook events
  • Session contract
Reference
  • API
  • Error codes
  • Event shapes
  • Design tokens

Error Codes

Claxx Auth's JSON APIs return failures using a single, versioned envelope. The full list of codes is defined in shared/types/api-errors.ts and produced by the factory methods in shared/utils/api-error.ts.

{
    "success": false,
    "error": {
        "code": "VALIDATION_ERROR",
        "message": "Human-readable detail",
        "status": 400,
        "requestId": "req_01H...",
        "fields": { "email": { "code": "invalid_format", "message": "Invalid email" } }
    }
}

requestId is always present — log it on the caller side so a failure you report can be traced to that request. fields is present only on VALIDATION_ERROR responses derived from Zod issues. debug (with stack, cause, timestamp, service, version) is attached in non-production stages.

Rules of engagement

  • Log code, not message. code is stable across releases; message is human-readable and may be changed or translated.
  • Do not parse message. Localize against code on the caller side if you need translation.
  • On RATE_LIMITED honor Retry-After. Do not retry instantly — the limiter uses a moving window.
  • Distinguish 401 vs 403. 401 = "we don't know who you are, re-authenticate." 403 = "we do, but you can't do that." They require different UX and telemetry.
  • Retry only idempotent requests on 5xx. INTERNAL_ERROR, SERVICE_UNAVAILABLE, REAUTH_REQUIRED, UPSTREAM_PROVIDER_ERROR are transient-looking but have different recovery semantics — see the section on each.

Code reference

The canonical list from ErrorCode in shared/types/api-errors.ts:

CodeHTTPFactoryCategory
VALIDATION_ERROR400ApiError.validation(...)Client / validation
AUTHENTICATION_REQUIRED401ApiError.unauthorized(...)Auth
SIGN_IN_REQUIRED401ApiError.signInRequired(...)Auth
PERMISSION_DENIED403ApiError.forbidden(...)Auth
RESOURCE_NOT_FOUND404ApiError.notFound(...)Not found
RESOURCE_CONFLICT409ApiError.conflict(...)Conflict
RATE_LIMITED429(emitted by rate limiter)Rate limit
INTERNAL_ERROR500ApiError.internal(...)Server
SERVICE_UNAVAILABLE503ApiError.serviceUnavailable()Server
BUSINESS_RULE_VIOLATION422ApiError.businessRule(...)Client / semantics
INVALID_TOKEN401ApiError.invalidToken(...)Provider token brokering
UNAUTHORIZED_CLIENT403ApiError.unauthorizedClient()Provider token brokering
NO_LINKED_ACCOUNT404ApiError.noLinkedAccount()Provider token brokering
INSUFFICIENT_SCOPE403ApiError.insufficientScope()Provider token brokering
REAUTH_REQUIRED502ApiError.reauthRequired()Provider token brokering
UPSTREAM_PROVIDER_ERROR502ApiError.upstreamProviderError()Provider token brokering
SECOND_FACTOR_SETUP_REQUIRED403(admin guards)Auth
SECOND_FACTOR_REQUIRED403(admin guards, factor changes)Auth

Field error codes

fields[<path>].code from FieldErrorCode:

CodeMeaning
requiredMissing field that Zod flagged required
invalid_typeWrong JS type (string/number/boolean mismatch)
too_smallBelow the minimum length / numeric bound
too_largeAbove the maximum length / numeric bound
invalid_formatFailed .email(), .uuid(), .url(), regex, etc.
invalid_enumNot one of z.enum([...]) allowed values
customCustom .refine(...) validator

fields[<path>] may also include received (the supplied value) and expected (a human description).


By category

Validation — client-side fixes required

VALIDATION_ERROR (400)

Raised by ApiError.validation(...) when the payload fails Zod parsing or when a handler needs to reject malformed input before hitting the database. fields enumerates every failed path.

{
    "success": false,
    "error": {
        "code": "VALIDATION_ERROR",
        "message": "Validation failed",
        "status": 400,
        "requestId": "req_01H...",
        "fields": {
            "email": { "code": "invalid_format", "message": "Invalid email" },
            "password": { "code": "too_small", "message": "Password must be at least 12 characters." }
        }
    }
}

Resolve: surface fields[...] under the appropriate form controls. Re-submit with corrected values. Do not retry identical payloads.

BUSINESS_RULE_VIOLATION (422)

Raised by ApiError.businessRule(...) when the request is syntactically valid but violates a domain invariant. Example: a new password that has appeared in known data breaches, when blockPwnedPasswords is on.

Resolve: read message for the specific rule. Either adjust the request (e.g. link a credential account first) or relax the rule in service_settings.

Authentication & authorization

AUTHENTICATION_REQUIRED (401)

No session cookie, invalid session token, or an expired Better Auth session.

{
    "success": false,
    "error": { "code": "AUTHENTICATION_REQUIRED", "message": "Authentication required", "status": 401, "requestId": "req_..." }
}

Resolve: redirect the user to /login (or the hosted login with a client-bound client_slug). Pop the session cookie.

SIGN_IN_REQUIRED (401)

The request needs a session as one particular account and has none. POST /api/auth/accept-invite answers it when an account already uses the invited address and the request is not signed in to that account on this tenant's host (not signed in, or signed in as someone else).

Resolve: send the user to sign in to that account, then retry. The hosted /invite page links to /login?returnTo=/invite?token=..., which comes back to the invitation after sign-in.

PERMISSION_DENIED (403)

Authenticated, but role or scope insufficient. Emitted by requireAdminRole when a non-admin hits /api/admin/**, or by resource-scoped checks that accept an owner but not the requester.

Resolve: do not retry with the same credentials. Escalate to an admin, or request additional scopes via a re-authorize flow.

SECOND_FACTOR_SETUP_REQUIRED (403) and SECOND_FACTOR_REQUIRED (403)

An admin route (/api/admin/**) refused a person who is an admin there, because the security policy says admins need a second factor and this session has not proved two factors. SECOND_FACTOR_SETUP_REQUIRED: the account has no second factor at all (no authenticator app, no passkey on any site). SECOND_FACTOR_REQUIRED: it has one, and this session was opened without it (a password alone, an emailed link, an identity provider). Someone who is not an admin gets PERMISSION_DENIED as before; an application's key is never refused this way. Every refusal is recorded as admin.access.denied.

Resolve: send the person to /admin-access, which lets them add a second factor (setup) or prove theirs with a code, a backup code or a passkey (POST /api/auth/second-factor/verify, POST /api/auth/second-factor/passkey/options and /verify), then retry. The admin pages do this on their own.

SECOND_FACTOR_REQUIRED also answers a request that would change a second factor of an account that has one (add or remove a passkey, switch the authenticator app on, again or off) from a session that has not proved it: a session opened by a password alone or an identity provider. It is answered before the password in the request is looked at, and the try is not counted. Recorded as account.second_factor.change_refused. Resolve: prove the existing factor through the same routes, then send the request again. A session an emailed sign-in link opened may make the change with the password, when the password is older than the session and older than every second factor the account has now (metadata.reason password_newer_than_factor otherwise: the mailbox alone can choose a new password, so an administrator must help). Whether the account has a second factor is asked for the account, on every site: a passkey made for another site counts. When the account's only factor is a passkey of another site, nothing can be proved here, and only an emailed link and the password change its factors on this site.

Not found

RESOURCE_NOT_FOUND (404)

Raised by ApiError.notFound(resource, id?). message follows the pattern "<resource> with id '<id>' not found" or "<resource> not found".

{
    "success": false,
    "error": { "code": "RESOURCE_NOT_FOUND", "message": "User with id '...' not found", "status": 404, "requestId": "req_..." }
}

Resolve: verify the ID. Do not retry.

Conflict

RESOURCE_CONFLICT (409)

Raised by ApiError.conflict(...) when the write conflicts with existing state. The admin user-create endpoint returns a special 409 with data payload containing the existing user's id, authMethod (sso or password), and linkedProviders so the caller can decide whether to link.

{
    "success": false,
    "error": { "code": "RESOURCE_CONFLICT", "message": "User already exists as an enterprise SSO account", "status": 409, "requestId": "req_..." },
    "data": { "id": "...", "email": "...", "authMethod": "sso", "linkedProviders": ["google"], "hasCredentialAccount": false }
}

Resolve: inspect data, then link the existing account instead of creating a new one.

Rate limit

RATE_LIMITED (429)

Emitted by the platform-level rate limiter (per-IP or per-session depending on the route). Always accompanied by a Retry-After header.

Resolve: honor Retry-After. If repeated, back off exponentially. Excessive 429s for the same principal is a signal to stop — not to retry harder.

Server errors

INTERNAL_ERROR (500)

Raised by ApiError.internal(...) or surfaces from an unhandled exception. The error is written to the Worker's log; quote the response's requestId when you report it.

Resolve: surface a generic error to the user, file the requestId if reproducible. Safe to retry idempotent GETs after a short delay.

SERVICE_UNAVAILABLE (503)

Raised by ApiError.serviceUnavailable(...) — typically when a configured binding is missing or the process is still warming. /api/health returns 503 with { status: "unhealthy" } when DB or cache checks fail.

Resolve: retry with exponential backoff. If it persists, check the Worker logs and the health endpoint.

Provider token brokering

These codes only appear on /api/provider-tokens/:provider. They distinguish client-authorization, user-linkage, and upstream failures. See the provider token brokering guide for full flow.

INVALID_TOKEN (401)

Missing or unknown Authorization: Bearer on /api/provider-tokens/:provider.

{
    "success": false,
    "error": { "code": "INVALID_TOKEN", "message": "Access token is expired or invalid", "status": 401, "requestId": "req_..." }
}

Resolve: re-fetch a fresh Claxx Auth access token via the authorization-code flow.

UNAUTHORIZED_CLIENT (403)

The authenticating client is not listed in the provider's allow-list (oauth_clients.allowedProviderTokens).

{
    "success": false,
    "error": { "code": "UNAUTHORIZED_CLIENT", "message": "Client is not authorized to access provider tokens for 'google'", "status": 403, "requestId": "req_..." }
}

Resolve: have an admin add the provider slug to the client's allowedProviderTokens.

NO_LINKED_ACCOUNT (404)

The authenticated user has no row in accounts for the requested provider. Common on first-time use.

Resolve: the user connects the provider from their profile (it asks for their password: POST /api/auth/link-provider).

INSUFFICIENT_SCOPE (403)

A grant exists but does not cover the requiredScopes in the request body. message includes both granted and required sets.

{
    "success": false,
    "error": {
        "code": "INSUFFICIENT_SCOPE",
        "message": "Insufficient scopes for provider 'google'. Granted: [openid, email]. Required: [openid, email, https://www.googleapis.com/auth/calendar.readonly]",
        "status": 403,
        "requestId": "req_..."
    }
}

Resolve: bounce the user through /oauth2/login?provider=<slug>&client_id=<id>&additional_scopes=<space-delimited> to upgrade the grant.

REAUTH_REQUIRED (502)

Upstream refresh token was revoked or is otherwise unusable. Claxxauth does not silently create a new grant — the user must re-authenticate.

Resolve: the user connects the provider again from their profile (POST /api/auth/link-provider, with their password). Treat as a non-retryable 502.

UPSTREAM_PROVIDER_ERROR (502)

The upstream IdP returned a transient failure during refresh (5xx, network timeout, etc.).

Resolve: retry with backoff. Persistent failures should be escalated — check provider status pages.


Protocol-endpoint errors

OIDC (/api/oidc/**), provider sign-in (/oauth2/**), and discovery (/.well-known/**) routes follow their respective specs, not this envelope.

  • OIDC authorization / token endpoints return {"error": "invalid_grant", "error_description": "..."} per OIDC Core §3.1.2.6 and OAuth 2.0 §5.2. Common codes: invalid_request, invalid_client, invalid_grant, unauthorized_client, unsupported_grant_type, invalid_scope.
  • /api/oidc/token/introspect always returns 200 with {"active": true|false} per RFC 7662.
  • /api/oidc/token/revoke always returns 200 with {"ok": true} per RFC 7009.
  • **/.well-known/**** returns 200 with the document or 404 if not applicable.
  • /oauth2/login and /oauth2/callback redirect with an error query parameter on failure (consent_denied, provider_error, missing_params, invalid_state, exchange_failed, session_failed, link_session_mismatch, redirect_not_allowed). The reason parameter narrows session_failed / link_failed cases (account_exists, email_not_verified, account_unavailable, account_claimed_by_other_user, provider_already_linked, link_session_mismatch, invitation_email_mismatch, user_not_found, user_create_failed, internal).

These routes never return the Claxx Auth JSON envelope, by design — they must be consumable by standards-compliant OAuth/OIDC clients.

On this page

  • Rules of engagement
  • Code reference
  • Field error codes
  • By category
  • Validation — client-side fixes required
  • Authentication & authorization
  • Not found
  • Conflict
  • Rate limit
  • Server errors
  • Provider token brokering
  • Protocol-endpoint errors
DocsPrivacyTerms
© 2026 Claxx Digital Group