Authentication Endpoints
These endpoints handle user registration, login, logout, and session refresh.
Register a New User
Section titled “Register a New User”Create a new user account.
POST /auth/registerRequest Body
Section titled “Request Body”{ "email": "user@example.com", "password": "secure_password_123", "name": "John Doe"}Parameters
Section titled “Parameters”| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Valid email address |
password | string | Yes | Minimum 8 characters |
name | string | Yes | User’s full name |
Response
Section titled “Response”{ "success": true, "data": { "userId": "user_123456", "email": "user@example.com", "name": "John Doe", "createdAt": "2024-01-15T10:30:00.000Z" }}Errors
Section titled “Errors”| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR | Invalid email or password too short |
| 409 | CONFLICT | Email already registered |
Authenticate and receive access credentials.
POST /auth/loginRequest Body
Section titled “Request Body”{ "email": "user@example.com", "password": "secure_password_123"}Parameters
Section titled “Parameters”| Field | Type | Required | Description |
|---|---|---|---|
email | string | Yes | Registered email address |
password | string | Yes | User’s password |
Response
Section titled “Response”{ "success": true, "data": { "accessToken": "eyJhbGciOiJIUzI1NiIs...", "refreshToken": "dGhpcyBpcyBhIHJlZnJlc2g...", "expiresIn": 3600, "user": { "userId": "user_123456", "email": "user@example.com", "name": "John Doe" } }}Errors
Section titled “Errors”| Status | Code | Description |
|---|---|---|
| 401 | UNAUTHORIZED | Invalid email or password |
Logout
Section titled “Logout”Invalidate the current session.
POST /auth/logoutHeaders
Section titled “Headers”Authorization: Bearer {access_token}Response
Section titled “Response”{ "success": true, "data": { "message": "Logged out successfully" }}Refresh Token
Section titled “Refresh Token”Obtain a new access token using a refresh token.
POST /auth/refreshRequest Body
Section titled “Request Body”{ "refreshToken": "dGhpcyBpcyBhIHJlZnJlc2g..."}Response
Section titled “Response”{ "success": true, "data": { "accessToken": "eyJhbGciOiJIUzI1NiIs...", "expiresIn": 3600 }}Errors
Section titled “Errors”| Status | Code | Description |
|---|---|---|
| 401 | UNAUTHORIZED | Invalid or expired refresh token |
Code Examples
Section titled “Code Examples”# Registercurl -X POST https://api.momail.io/v1/auth/register \ -H "Content-Type: application/json" \ -d '{ "email": "user@example.com", "password": "secure_password_123", "name": "John Doe" }'
# Logincurl -X POST https://api.momail.io/v1/auth/login \ -H "Content-Type: application/json" \ -d '{ "email": "user@example.com", "password": "secure_password_123" }'// Registerconst registerResponse = await fetch('https://api.momail.io/v1/auth/register', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: 'user@example.com', password: 'secure_password_123', name: 'John Doe' })});
const { data } = await registerResponse.json();console.log('User ID:', data.userId);
// Loginconst loginResponse = await fetch('https://api.momail.io/v1/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: 'user@example.com', password: 'secure_password_123' })});
const { data: loginData } = await loginResponse.json();localStorage.setItem('accessToken', loginData.accessToken);import requests
# Registerresponse = requests.post( 'https://api.momail.io/v1/auth/register', json={ 'email': 'user@example.com', 'password': 'secure_password_123', 'name': 'John Doe' })print(f"User created: {response.json()['data']['userId']}")
# Loginlogin_response = requests.post( 'https://api.momail.io/v1/auth/login', json={ 'email': 'user@example.com', 'password': 'secure_password_123' })token = login_response.json()['data']['accessToken']