Login & Verification
Authentication endpoints for user login and OTP verification.
Request Login Code
Request an OTP code to be sent to the user's phone number.
Endpoint
POST /api/code/request
Request
json
{
"phone": "+1234567890"
}Response
json
{
"message": "Verification code sent successfully",
"data": {
"expires_in": 300
}
}Error Responses
422- Invalid phone number format429- Too many requests (rate limited)
Verify Login Code
Verify the OTP code and authenticate the user.
Endpoint
POST /api/code/verify
Request
json
{
"phone": "+1234567890",
"code": "123456"
}Response
json
{
"data": {
"user": {
"id": 1,
"phone": "+1234567890",
"username": "user123",
"created_at": "2024-01-01T00:00:00Z"
},
"token": "1|abcdef123456...",
"matrix_credentials": {
"user_id": "@user123:matrix.server",
"access_token": "matrix_token_here",
"device_id": "DEVICE123"
}
}
}Error Responses
401- Invalid or expired code422- Validation error
Login (Alternative)
Alternative login endpoint using phone and code.
Endpoint
POST /api/auth/login
Request
json
{
"phone": "+1234567890",
"code": "123456"
}Response
Same as verify endpoint above.
Check Username Availability
Check if a username is available for registration.
Endpoint
POST /api/auth/username/check
Request
json
{
"username": "desired_username"
}Response
json
{
"available": true,
"message": "Username is available"
}Error Response
json
{
"available": false,
"message": "Username is already taken",
"suggestions": ["username1", "username2", "username3"]
}Generate Username Suggestion
Generate username suggestions based on user preferences.
Endpoint
POST /api/auth/username/generate
Request
json
{
"base": "john",
"include_numbers": true
}Response
json
{
"suggestions": [
"john123",
"john456",
"john789"
]
}