# User Authentication

### Authentication Flow

#### 1. Wallet Connection

```javascript
// Connect wallet using AppKit
import { useAppKit, useAppKitAccount } from "@reown/appkit/react";

const { open } = useAppKit();
const { address, isConnected } = useAppKitAccount();
```

#### 2. Message Signing

```javascript
// Sign fixed message
const messageToSign = "cooking.city";
const encodedMessage = new TextEncoder().encode(messageToSign);
const signature = await walletProvider.signMessage(encodedMessage);
```

#### 3. Login to Obtain Token

**Endpoint**: `POST /api/auth/solana/login`

**Request Parameters**:

```json
{
  "invite_code": null,
  "message": "cooking.city",
  "public_key": "user_wallet_public_key",
  "signature": "signature_result_in_hex_format"
}
```

**Response Example**:

```json
{
  "code": 200,
  "data": {
    "profile": {
      "address": "user_wallet_address",
      "avatar_url": null,
      "bio": null,
      "created_at": "2024-01-01T00:00:00Z",
      "nick_name": "user_nickname"
    },
    "token": "jwt_token_string"
  }
}
```

### Token Usage

Add the obtained token to request headers:

```
Authorization: Bearer your_jwt_token
```

### User Information Query

**Endpoint**: `GET /api/auth/me`

**Request Headers**:

```
Authorization: Bearer your_jwt_token
```

**Response Example**:

```json
{
  "code": 200,
  "data": {
    "profile": {
      "address": "user_wallet_address",
      "avatar_url": "avatar_url",
      "bio": "user_bio",
      "created_at": "creation_time",
      "nick_name": "nickname",
      "twitter_screen_name": "twitter_username",
      "telegram_username": "telegram_username",
      "points": "points_amount"
    }
  }
}
```

### Key Points

* Fixed signing message: `"cooking.city"`
* Signature result must be converted to hex format
* Token expiration is set according to business requirements
* Supports invitation code mechanism (invite\_code can be null)


---

# Agent Instructions: 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://cooking-city-launchpad.gitbook.io/docs/api-documentation/user-authentication.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.
