Authentication Guide

EMTITHAL uses JWT Bearer tokens. All protected endpoints require an Authorization: Bearer <token> header.

1. Register

Create a new account with an email and password. A verification email is sent automatically.

POST https://api.emtithal.aisc.sa/api/v1/auth/register
Content-Type: application/json

{
  "email": "engineer@example.sa",
  "password": "YourSecurePassword!"
}

2. Verify Email

After registering, an OTP is emailed. Submit it to activate your account:

POST https://api.emtithal.aisc.sa/api/v1/auth/verify-email
Content-Type: application/json

{
  "email": "engineer@example.sa",
  "otp": "123456"
}

3. Login

Exchange credentials for a short-lived access token and a longer-lived refresh token:

POST https://api.emtithal.aisc.sa/api/v1/auth/login
Content-Type: application/json

{
  "email": "engineer@example.sa",
  "password": "YourSecurePassword!"
}

// Response:
{
  "access_token": "eyJhbGci...",
  "refresh_token": "eyJhbGci...",
  "token_type": "bearer",
  "expires_in": 900
}

4. Use the Token

Add the Authorization header to every protected request:

GET https://api.emtithal.aisc.sa/api/v1/auth/me
Authorization: Bearer eyJhbGci...
Accept-Language: ar

5. Refresh the Token

Access tokens expire in 15 minutes. Use the refresh token to get a new pair without re-logging in:

POST https://api.emtithal.aisc.sa/api/v1/auth/refresh
Content-Type: application/json

{
  "refresh_token": "eyJhbGci..."
}

6. Logout

Invalidate all tokens for the current session:

POST https://api.emtithal.aisc.sa/api/v1/auth/logout
Authorization: Bearer eyJhbGci...

Error Handling

Auth errors return bilingual JSON envelopes. Common codes:

Code HTTP Meaning (EN) Meaning (AR)
AUTH.INVALID_CREDENTIALS401Email or password is incorrectالبريد الإلكتروني أو كلمة المرور غير صحيحة
AUTH.EMAIL_NOT_VERIFIED403Email address must be verified before logging inيجب التحقق من البريد الإلكتروني قبل تسجيل الدخول
AUTH.INVALID_TOKEN401Access token is invalid or expiredرمز الوصول غير صالح أو منتهي الصلاحية
AUTH.SESSION_EXPIRED401Your session has expired. Please log in againانتهت جلستك. يرجى تسجيل الدخول من جديد
AUTH.MISSING_TOKEN401Authorization header with Bearer token is requiredيجب إرسال رمز Bearer في ترويسة التفويض
AUTH.EMAIL_ALREADY_REGISTERED409An account with this email already existsيوجد حساب مسجل بهذا البريد الإلكتروني

See all error codes →


Locale Header

Send Accept-Language: ar or Accept-Language: en on any request. All error responses carry both languages in the bilingual envelope; this header controls which language is primary.