> For the complete documentation index, see [llms.txt](https://ocx.gitbook.io/ocx-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ocx.gitbook.io/ocx-doc/auth.md).

# auth

Endpoints for Sign-In With Ethereum (SIWE) and session management. For the full background on the flow, see [Authentication → SIWE](file:///7302513/authentication/siwe.md).

## POST /auth/nonce

Request a nonce for the user to sign.

**Auth**: none.

**Request**

```json
{ "walletAddress": "0xYourAddress" }
```

**Response**

```json
{ "nonce": "a1b2c3d4..." }
```

**Errors**

| Status | When                                 |
| ------ | ------------------------------------ |
| 400    | `walletAddress` missing or malformed |

## POST /auth/siwe

Verify a signed SIWE message and establish a session.

**Auth**: none.

**Request**

```json
{
  "message": "api.ocx.global wants you to sign in with your Ethereum account...",
  "signature": "0x..."
}
```

**Response** — sets `Set-Cookie: astra_session=<jwt>; HttpOnly; Secure; SameSite=None; Path=/; Max-Age=604800`.

```json
{
  "userId": "01HW...",
  "walletAddress": "0xYourAddress"
}
```

**Errors**

| Status | `code`                 | When                                    |
| ------ | ---------------------- | --------------------------------------- |
| 400    | `INVALID_SIWE_MESSAGE` | Message is malformed                    |
| 400    | `NONCE_MISMATCH`       | Nonce doesn't match one we issued       |
| 401    | `INVALID_SIGNATURE`    | Signature doesn't match claimed address |

## GET /auth/me

Returns the currently authenticated user, or `null` if not signed in.

**Auth**: optional (this endpoint intentionally returns `null` rather than 401 for unauthenticated callers).

**Response (signed in)**

```json
{
  "userId": "01HW...",
  "walletAddress": "0xYourAddress"
}
```

**Response (not signed in)**

```json
null
```

## POST /auth/logout

Revokes the session and clears the cookie.

**Auth**: required.

**Response**

```json
{ "message": "Logged out" }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ocx.gitbook.io/ocx-doc/auth.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
