Authentication
How to authenticate with Atract's API.
Overview
Atract uses session-based authentication with wallet signatures.
Login Flow
User connects wallet (MetaMask/WalletConnect)
Frontend requests challenge message
User signs message with wallet
Backend verifies signature
Session created, cookie returned
Request Challenge
POST /api/auth/challenge
Content-Type: application/json
{
"address": "0x..."
}Response:
{
"ok": true,
"data": {
"message": "Sign this message to authenticate with Atract...",
"nonce": "abc123"
}
}Submit Signature
POST /api/auth/login
Content-Type: application/json
{
"address": "0x...",
"signature": "0x...",
"nonce": "abc123"
}Response:
{
"ok": true,
"data": {
"user": {
"address": "0x...",
"sessionToken": "..."
}
}
}Sets Cookie:
Set-Cookie: session=<token>; HttpOnly; Secure; SameSite=StrictAuthenticated Requests
Include session cookie in all requests:
GET /api/account
Cookie: session=<token>Logout
POST /api/auth/logout
Cookie: session=<token>Session Expiry
Sessions expire after 24 hours
Refresh by making any authenticated request
After expiry, user must re-authenticate
Security
Signatures verified on backend
Session tokens are random, secure
HttpOnly cookies prevent XSS
HTTPS required in production
Related Pages
Last updated