---
title: Errors
description: The AuthError codes and how to show them.
---

# Errors

Functions that change something never throw for expected problems. They return:

```ts
{ ok: true, ...data } | { ok: false, error: AuthError }
```

Functions that only read (`user()`, `sessions.list()`, `workspaces.members()`, …) return data. Without a session they throw `AuthException` with `code: "not_signed_in"`. Mistakes in the config throw `AuthConfigError`.

Redirect flows (Google, GitHub, e-mail links) send the code to `pages.error` as `?error=<code>`.

## Show them in your app's words

```ts
import type { AuthError } from "@kaaarel/auth/errors";

const text: Record<AuthError, string> = { /* … your app's language … */ };
```

Import from `@kaaarel/auth/errors` in pages. It has no server code. `@kaaarel/auth` itself pulls `node:crypto` into the browser bundle and breaks the page.

A full `Record<AuthError, string>` makes TypeScript list every missing code. English defaults are in `messages.en`:

```ts
import { messages } from "@kaaarel/auth/errors";
messages.en.invalid_credentials; // "Wrong e-mail or password."
```

A thrown `AuthException` that crosses a server function boundary arrives in the browser as a plain `Error`. Its `message` is the code, for example `"forbidden"`.

## All codes

| Code | When |
| --- | --- |
| `invalid_input` | A field has the wrong type or format |
| `invalid_email` | The e-mail is not valid |
| `weak_password` | Shorter than `minLength` (default 10) |
| `password_too_long` | Longer than 256 characters |
| `invalid_credentials` | Wrong e-mail or password, or a wrong current password |
| `email_not_verified` | Sign-in before the e-mail is verified (a new link was sent), or linking or inviting by an unverified user |
| `email_taken` | Sign-up without verification, or an e-mail change, to a used e-mail |
| `signup_closed` | `access` does not allow sign-up for this e-mail |
| `access_denied` | `access` does not allow this user to sign in |
| `rate_limited` | Too many attempts |
| `forbidden_origin` | The request came from another site |
| `not_signed_in` | The function needs a session |
| `reauth_required` | A sensitive change needs a sign-in in the last 15 minutes, or the password |
| `invalid_token` | The link or token is not valid, or was used |
| `link_expired` | The link is too old |
| `oauth_failed` | The provider login failed (wrong state, bad answer) |
| `oauth_denied` | The user cancelled at the provider |
| `oauth_email_unverified` | The provider has no verified e-mail for the user |
| `account_linked_elsewhere` | That provider account belongs to another user |
| `last_sign_in_method` | Unlinking would leave no way to sign in |
| `method_disabled` | The method or module is not on |
| `invalid_code` | Wrong two-factor or recovery code |
| `two_factor_not_enabled` | 2FA is off for this user |
| `two_factor_already_enabled` | 2FA is already on |
| `challenge_expired` | The two-factor step timed out or had too many wrong codes |
| `not_found` | The workspace, member or token does not exist for this user |
| `forbidden` | The role is too low, or an API token tried an account change |
| `already_member` | The invited e-mail is already a member |
| `invite_email_mismatch` | The invite is for another e-mail |
| `owner_cannot_leave` | The owner must transfer ownership first |
| `transfer_ownership_first` | Account deletion while owning a shared workspace |
