User Authentication
Authentication Flow
1. Wallet Connection
// Connect wallet using AppKit
import { useAppKit, useAppKitAccount } from "@reown/appkit/react";
const { open } = useAppKit();
const { address, isConnected } = useAppKitAccount();
2. Message Signing
// 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:
{
"invite_code": null,
"message": "cooking.city",
"public_key": "user_wallet_public_key",
"signature": "signature_result_in_hex_format"
}
Response Example:
{
"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:
{
"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)
Last updated