Auth & Users API
Authentication and user management endpoints for MASARUK
1. Purpose
This document defines all authentication & user-management endpoints across MASARUK:
- B2C end-user authentication (Web + Mobile)
- Provider Portal authentication (B2B)
- Admin Panel authentication
- JWT token generation
- Profile management
- Password recovery
- Social login integration (Google / Facebook)
This API layer is shared across:
- Next.js Web Frontend
- Flutter Mobile Apps
- Admin Panel
- Provider Portal
2. Auth Model Overview
2.1 Authentication Method
MASARUK backend uses:
- JWT (jsonwebtoken) for all platforms.
- HTTP-only cookies for secure web session refresh tokens.
2.2 Token Behavior
| Platform | Token Type | Storage | Expiry |
|---|---|---|---|
| Web (Next.js) | JWT Access + Refresh Token | Access: Memory, Refresh: HttpOnly Cookie | Access: 15min-1h, Refresh: 7-30d |
| Mobile | JWT | Secure Storage | Configurable (e.g., 30 d) |
| Provider Portal | JWT | Access: Memory, Refresh: HttpOnly Cookie | Configurable |
2.3 Required Headers
Authorization: Bearer <token>
Accept: application/json
Content-Type: application/json
3. Entities Involved
User
(Arabic labels preserved as-is from UI)
| Field | Description |
|---|---|
| id | Primary key |
| full_name | "الاسم بالكامل" |
| "البريد الالكتروني" | |
| phone | "رقم الجوال" |
| password_hash | Hashed password |
| role | ENUM: super_admin, admin, provider_admin, provider_staff, user |
| status | ACTIVE / BLOCKED |
| created_at | Date |
| updated_at | Date |
4. Endpoints
All endpoints below follow the standard error and validation patterns from api-principles-and-versioning.md.
/api/v1/auth/signupCreates a new customer account.
Request Body:
{
"full_name": "محمد أحمد",
"email": "user@example.com",
"phone": "966500000000",
"password": "StrongPass123",
"password_confirmation": "StrongPass123"
}Validation Rules:
- full_name: required, string
- email: required, unique
- phone: required, unique
- password: required, confirmed
Example Response:
{
"success": true,
"token": "<jwt_token>",
"user": {
"id": 1,
"full_name": "محمد أحمد",
"email": "user@example.com",
"phone": "966500000000",
"role": "user"
}
}/api/v1/auth/loginRequest Body:
{
"email": "user@example.com",
"password": "StrongPass123"
}Example Response:
{
"success": true,
"token": "<jwt_token>",
"user": {
"id": 1,
"full_name": "محمد أحمد",
"email": "user@example.com",
"role": "user"
}
}Error Cases:
/api/v1/auth/socialUsed for both Google and Facebook.
Request Body:
{
"provider": "google",
"access_token": "<provider_token>"
}Same shape as normal login (returns token + user).
/api/v1/auth/logoutInvalidates the current JWT token / session according to platform rules.
5. Profile Management
/api/v1/user/profileExample Response:
{
"id": 1,
"full_name": "محمد أحمد",
"email": "user@example.com",
"phone": "966500000000",
"role": "user"
}/api/v1/user/profileRequest Body:
{
"full_name": "محمد أحمد",
"phone": "966500000010"
}/api/v1/user/change-passwordRequest Body:
{
"current_password": "oldPass123",
"new_password": "NewStrong123",
"new_password_confirmation": "NewStrong123"
}6. Password Reset Flow
/api/v1/auth/forgot-passwordRequest Body:
{ "email": "user@example.com" }Example Response:
{ "message": "Password reset link sent" }/api/v1/auth/reset-passwordRequest Body:
{
"token": "<reset_token>",
"email": "user@example.com",
"password": "NewPass123",
"password_confirmation": "NewPass123"
}7. Admin & Provider Authentication
/api/v1/provider/auth/loginUses the same basic login flow but must return provider-specific fields.
Example Response:
{
"token": "<jwt>",
"user": {
"id": 33,
"role": "provider_admin",
"provider_id": 7
}
}- role is either provider_admin or provider_staff.
- provider_id is the owning company.
/api/v1/admin/auth/loginOnly super_admin or admin roles are allowed.
8. Status Mapping
For reference; full mapping lives in 00-guidelines/status-mapping-template.md.
| Arabic (UI) | Internal Enum | Notes |
|---|---|---|
| نشط/فعّال | ACTIVE | Unified internally |
| غير نشط / غير فعّال | INACTIVE | |
| ملغاه | CANCELLED | Used in bookings |
| مكتملة | COMPLETED | |
| قيد التنفيذ | PENDING | Canonical internal ID |
9. Error Patterns
Standardized across all endpoints.