# Auth API

The Auth API: get a session token with email and password, and sign out, with every endpoint's fields, who may call it, its rate limit and a curl example.

## Sign in with an email address and a password. A closed account answers 403 `ACCOUNT_CLOSED` once the password is right, with when it was closed, the decision's number and why in a line. Without two-step sign-in, the answer is the signed-in user and a session token. With it, the answer is a `challenge` instead: send its token with the second step to `POST /auth/login/second-factor` within five minutes. Ten wrong passwords for one address within 15 minutes refuse it (429, `TOO_MANY_SIGN_INS`) until the oldest of them is 15 minutes old, whether or not an account uses it.

`POST /auth/login`

Needs no token. Rate limit: 10 a minute, per address. Not open to apps or API keys: signing in, sessions and upload tokens are the account's own.

### Body

| Field | Type | Required | Notes |
|---|---|---|---|
| `email` | `string` | required |  |
| `password` | `string` | required | At least 8 characters. |

### Response

Returns an `object` with these fields:

| Field | Type | Present | Notes |
|---|---|---|---|
| `user` | [`User`](https://hematite.gg/docs/developers/models/user) |  |  |
| `token` | `string` |  |  |

```bash
curl -X POST 'https://api.hematite.gg/v1/auth/login' \
  -H "Content-Type: application/json" \
  -d '{"email":"nova@example.com","password":"••••••••"}'
```

Example `data`:

```json
{
  "user": {
    "id": 1,
    "username": "nova",
    "email": "nova@example.com",
    "emailConfirmedAt": "2026-11-10T18:24:00.000Z",
    "createdAt": "2026-11-10T18:24:00.000Z",
    "updatedAt": "2026-11-10T18:24:00.000Z",
    "permissionGroupId": 1,
    "subscriptionGroupId": 1,
    "stripeSubscriptionId": "string",
    "domainId": 1,
    "avatarId": 1,
    "stripeCustomerId": "string",
    "inviteId": 1,
    "timeZone": "string",
    "avatar": {
      "key": "images/a1b2c3d4e5f6.png"
    },
    "badgeIds": [
      1
    ],
    "storageUsed": 2457600,
    "storageLimit": 1073741824,
    "imageCount": 1,
    "folderCount": 0,
    "publicImageCount": 0,
    "publicFolderCount": 0,
    "profile": {
      "bio": "Screenshots from ranked nights",
      "hideProfile": false,
      "activityVisibility": "All"
    }
  },
  "token": "hms_live_m0plGGtn67kMZy6D_…"
}
```

## WebAuthn's options for the second step with a passkey: hand them to the browser (`startAuthentication({ optionsJSON })` of `@simplewebauthn/browser`) and send its answer to `POST /auth/login/second-factor` as `passkey`. Each set works once, for five minutes.

`POST /auth/login/passkey-options`

Needs no token. Rate limit: 10 a minute, per address. Not open to apps or API keys: signing in, sessions and upload tokens are the account's own.

### Body

| Field | Type | Required | Notes |
|---|---|---|---|
| `challenge` | `string` | required | The challenge's token from `POST /auth/login`. At most 256 characters. |

### Response

Returns an `object` with these fields:

| Field | Type | Present | Notes |
|---|---|---|---|
| `challenge` | `string` |  |  |
| `timeout` | `number` | optional |  |
| `rpId` | `string` | optional |  |
| `allowCredentials` | `object[]` | optional |  |
| `allowCredentials.id` | `string` |  |  |
| `allowCredentials.type` | `"public-key"` |  |  |
| `allowCredentials.transports` | `enum[]` | optional |  |
| `userVerification` | `enum` | optional | One of `required`, `preferred`, `discouraged`. |

```bash
curl -X POST 'https://api.hematite.gg/v1/auth/login/passkey-options' \
  -H "Content-Type: application/json" \
  -d '{"challenge":"string"}'
```

Example `data`:

```json
{
  "challenge": "string",
  "timeout": 0,
  "rpId": "string",
  "allowCredentials": [
    {
      "id": "string",
      "type": "public-key",
      "transports": [
        "ble"
      ]
    }
  ],
  "userVerification": "required"
}
```

## The second step of signing in with two-step sign-in: the challenge `POST /auth/login` answered, with exactly one of a code from the authenticator app, a recovery code, or a passkey's answer (ask `POST /auth/login/passkey-options` for its options first). Answers the signed-in user and a session token, as signing in without it does. A challenge takes five wrong answers; ten wrong second steps for an account within 15 minutes lock its second step for 15 minutes (429, `SECOND_STEP_LOCKED`) and email the account.

`POST /auth/login/second-factor`

Needs no token. Rate limit: 10 a minute, per address. Not open to apps or API keys: signing in, sessions and upload tokens are the account's own.

### Body

| Field | Type | Required | Notes |
|---|---|---|---|
| `challenge` | `string` | required | The challenge's token from `POST /auth/login`. At most 256 characters. |
| `totp` | `string` |  | The six digits the authenticator app shows now. At most 16 characters. |
| `recoveryCode` | `string` |  | One of the account's recovery codes (`4KQ7-9MXT-2B`); each works once. At most 32 characters. |
| `passkey` | `object` |  | What the browser's `navigator.credentials.get()` answered, as JSON (WebAuthn's `AuthenticationResponseJSON`; `startAuthentication()` of `@simplewebauthn/browser` gives it). |
| `passkey.id` | `string` | required | 1 to 1024 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.rawId` | `string` | required | 1 to 1024 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.type` | `"public-key"` | required |  |
| `passkey.authenticatorAttachment` | `enum` |  | One of `platform`, `cross-platform`. |
| `passkey.clientExtensionResults` | `map of any` |  |  |
| `passkey.response` | `object` | required |  |
| `passkey.response.clientDataJSON` | `string` | required | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.response.authenticatorData` | `string` | required | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.response.signature` | `string` | required | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.response.userHandle` | `string` |  | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |

### Response

Returns an `object` with these fields:

| Field | Type | Present | Notes |
|---|---|---|---|
| `user` | [`User`](https://hematite.gg/docs/developers/models/user) |  |  |
| `token` | `string` |  |  |
| `recoveryCodesLeft` | `integer \| null` |  | After a recovery code: how many are left (a new set from Settings → Security once few are). Null otherwise. |

```bash
curl -X POST 'https://api.hematite.gg/v1/auth/login/second-factor' \
  -H "Content-Type: application/json" \
  -d '{"challenge":"string"}'
```

Example `data`:

```json
{
  "user": {
    "id": 1,
    "username": "nova",
    "email": "nova@example.com",
    "emailConfirmedAt": "2026-11-10T18:24:00.000Z",
    "createdAt": "2026-11-10T18:24:00.000Z",
    "updatedAt": "2026-11-10T18:24:00.000Z",
    "permissionGroupId": 1,
    "subscriptionGroupId": 1,
    "stripeSubscriptionId": "string",
    "domainId": 1,
    "avatarId": 1,
    "stripeCustomerId": "string",
    "inviteId": 1,
    "timeZone": "string",
    "avatar": {
      "key": "images/a1b2c3d4e5f6.png"
    },
    "badgeIds": [
      1
    ],
    "storageUsed": 2457600,
    "storageLimit": 1073741824,
    "imageCount": 1,
    "folderCount": 0,
    "publicImageCount": 0,
    "publicFolderCount": 0,
    "profile": {
      "bio": "Screenshots from ranked nights",
      "hideProfile": false,
      "activityVisibility": "All"
    }
  },
  "token": "hms_live_m0plGGtn67kMZy6D_…",
  "recoveryCodesLeft": 0
}
```

## Delete the current session

`POST /auth/logout`

Needs a session token. Rate limit: 120 a minute, per address. Not open to apps or API keys: signing in, sessions and upload tokens are the account's own.

### Response

`data` is empty.

```bash
curl -X POST 'https://api.hematite.gg/v1/auth/logout' \
  -H "Authorization: $HEMATITE_TOKEN"
```

## The step-up: this sign-in proves again that it's its person, for ten minutes, before a change that hands the account over (two-step sign-in, an upload token, an app, the email or the password). With two-step sign-in on, exactly one of a code from the authenticator app, a recovery code or a passkey's answer (options from `POST /auth/reauth/passkey-options`); without it, the password. Only a sign-in on the website can step up. Answers until when it holds.

`POST /auth/reauth`

Needs a session token. Rate limit: 5 a minute, per address. Not open to apps or API keys: signing in, sessions and upload tokens are the account's own.

### Body

| Field | Type | Required | Notes |
|---|---|---|---|
| `password` | `string` |  | The password, for an account without two-step sign-in. At most 128 characters. |
| `totp` | `string` |  | The six digits the authenticator app shows now. At most 16 characters. |
| `recoveryCode` | `string` |  | One of the account's recovery codes (`4KQ7-9MXT-2B`); each works once. At most 32 characters. |
| `passkey` | `object` |  | What the browser's `navigator.credentials.get()` answered, as JSON (WebAuthn's `AuthenticationResponseJSON`; `startAuthentication()` of `@simplewebauthn/browser` gives it). |
| `passkey.id` | `string` | required | 1 to 1024 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.rawId` | `string` | required | 1 to 1024 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.type` | `"public-key"` | required |  |
| `passkey.authenticatorAttachment` | `enum` |  | One of `platform`, `cross-platform`. |
| `passkey.clientExtensionResults` | `map of any` |  |  |
| `passkey.response` | `object` | required |  |
| `passkey.response.clientDataJSON` | `string` | required | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.response.authenticatorData` | `string` | required | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.response.signature` | `string` | required | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |
| `passkey.response.userHandle` | `string` |  | At most 16384 characters. Matches ^[A-Za-z0-9_-]*$. |

### Response

Returns an `object` with these fields:

| Field | Type | Present | Notes |
|---|---|---|---|
| `until` | `date-time` |  |  |
| `recoveryCodesLeft` | `integer \| null` |  | After a recovery code: how many are left. Null otherwise. |

```bash
curl -X POST 'https://api.hematite.gg/v1/auth/reauth' \
  -H "Authorization: $HEMATITE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"password":"••••••••"}'
```

Example `data`:

```json
{
  "until": "2026-11-10T18:24:00.000Z",
  "recoveryCodesLeft": 0
}
```

## WebAuthn's options for a step-up with a passkey: hand them to the browser and send its answer to `POST /auth/reauth` as `passkey`. Each set works once, for five minutes, for this sign-in.

`POST /auth/reauth/passkey-options`

Needs a session token. Rate limit: 10 a minute, per address. Not open to apps or API keys: signing in, sessions and upload tokens are the account's own.

### Response

Returns an `object` with these fields:

| Field | Type | Present | Notes |
|---|---|---|---|
| `challenge` | `string` |  |  |
| `timeout` | `number` | optional |  |
| `rpId` | `string` | optional |  |
| `allowCredentials` | `object[]` | optional |  |
| `allowCredentials.id` | `string` |  |  |
| `allowCredentials.type` | `"public-key"` |  |  |
| `allowCredentials.transports` | `enum[]` | optional |  |
| `userVerification` | `enum` | optional | One of `required`, `preferred`, `discouraged`. |

```bash
curl -X POST 'https://api.hematite.gg/v1/auth/reauth/passkey-options' \
  -H "Authorization: $HEMATITE_TOKEN"
```

Example `data`:

```json
{
  "challenge": "string",
  "timeout": 0,
  "rpId": "string",
  "allowCredentials": [
    {
      "id": "string",
      "type": "public-key",
      "transports": [
        "ble"
      ]
    }
  ],
  "userVerification": "required"
}
```
