diff --git a/docs/api/authentication.md b/docs/api/authentication.md index 7e8a4be..16d777c 100644 --- a/docs/api/authentication.md +++ b/docs/api/authentication.md @@ -1,33 +1,99 @@ # Authentication API -The Authentication API handles user registration, login, profile retrieval, and role-based access. All protected endpoints require a **JWT Bearer Token**, which must be included in the request headers as: +The Authentication API handles user registration, login, profile retrieval, and role-based access. All protected endpoints require a JWT Bearer Token, which must be included in the request headers as: -``` +```javascript Authorization: Bearer ``` If the token is missing or invalid, the API will return a `401 Unauthorized` response. ---- +*** ## Base URL -``` +```javascript /api/auth ``` ---- +*** ## Endpoints Overview -| Method | Endpoint | Description | Auth Required | -|--------|----------|-------------|---------------| -| POST | `/api/auth/register` | Register a new user | No | -| POST | `/api/auth/login` | Authenticate an existing user and get a token | No | -| GET | `/profile` | Get details of the logged-in user | Yes | -| POST | `/invite-admin` | Create a new admin user (admin-only route) | Yes (Admin) | - ---- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Method

+
+

Endpoint

+
+

Description

+
+

Auth Required

+
+

POST

+
+

/api/auth/register

+
+

Register a new user

+
+

No

+
+

POST

+
+

/api/auth/login

+
+

Authenticate an existing user and get a token

+
+

No

+
+

GET

+
+

/profile

+
+

Get details of the logged-in user

+
+

Yes

+
+

POST

+
+

/invite-admin

+
+

Create a new admin user (admin-only route)

+
+

Yes (Admin)

+
+ +*** ## 1. Register User @@ -59,7 +125,7 @@ Registers a new user into the system. } ``` ---- +*** ## 2. Login User @@ -90,7 +156,7 @@ Authenticates a user and returns a JWT token required for accessing protected en } ``` ---- +*** ## 3. Get Current Authenticated User @@ -100,7 +166,7 @@ Returns profile information of the currently logged-in user. This is useful for ### Headers -``` +```javascript Authorization: Bearer ``` @@ -116,7 +182,7 @@ Authorization: Bearer } ``` ---- +*** ## 4. Invite Admin (Admin Only) @@ -126,7 +192,7 @@ Allows an existing admin to create another admin user. ### Headers -``` +```javascript Authorization: Bearer ``` @@ -154,13 +220,65 @@ Authorization: Bearer } ``` ---- +*** ## Common Error Responses -| Status | Reason | Example | -|--------|--------|---------| -| 400 | Missing fields | `{"message": "Email and password required"}` | -| 401 | Invalid or missing token | `{"message": "Not authorized"}` | -| 403 | User does not have permission | `{"message": "Access denied, admin only"}` | -| 409 | Email already registered | `{"message": "User already exists"}` | \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Status

+
+

Reason

+
+

Example

+
+

400

+
+

Missing fields

+
+

{"message": "Email and password required"}

+
+

401

+
+

Invalid or missing token

+
+

{"message": "Not authorized"}

+
+

403

+
+

User does not have permission

+
+

{"message": "Access denied, admin only"}

+
+

409

+
+

Email already registered

+
+

{"message": "User already exists"}

+
+