Use the following base URL for all requests:
http://localhost:5000/api/v1
If your backend port is 5001, use:
http://localhost:5001/api/v1
Successful response example:
{
"success": true,
"message": "...",
"data": { ... },
"meta": null,
"error": null
}Error response example:
{
"success": false,
"message": "...",
"data": null,
"error": {
"code": "..."
}
}- Endpoint:
POST /auth/signup - Description: Register a new user
- Headers:
Content-Type: application/json
- Body:
{ "name": "User Name", "email": "user@example.com", "password": "password123" } - Returns:
success: truemessage: "User registered successfully. Now you can login"data: null
- Status codes:
201 Createdon success400 Bad Requestwhen required fields are missing or email already exists500 Internal Server Erroron unexpected failure
- Endpoint:
POST /auth/login - Description: Login an existing user and issue the auth cookie
- Headers:
Content-Type: application/json
- Body:
{ "email": "user@example.com", "password": "password123" } - Returns:
success: truemessage: "Login successful"(or similar)data.userobject containing user details- Sets
accessTokencookie in the response
- Status codes:
200 OKon success400 Bad Requestwhen credentials are invalid or missing401 Unauthorizedwhen login fails500 Internal Server Erroron unexpected failure
- Endpoint:
GET /auth/me - Description: Get the profile of the currently authenticated user
- Headers:
- Cookie must include
accessToken
- Cookie must include
- Returns:
success: truemessage: "User profile fetched successfully"data.userobject
- Status codes:
200 OKon success401 Unauthorizedif no token or token is invalid404 Not Foundif the user cannot be found
- Endpoint:
GET /auth/admin - Description: Verify that the authenticated user is an admin
- Headers:
- Cookie must include
accessToken
- Cookie must include
- Returns:
success: truemessage: "Hello admin"data: null
- Status codes:
200 OKon success401 Unauthorizedif not authenticated403 Forbiddenif authenticated but not admin
- Endpoint:
POST /auth/logout - Description: Logout the user by clearing the auth cookie and revoking token data
- Headers:
- Cookie must include
accessToken
- Cookie must include
- Returns:
success: truemessage: "Logged out successfully"data: null
- Status codes:
200 OKon success401 Unauthorizedif not authenticated
- Endpoint:
POST /task/create - Description: Create a new task for the authenticated user
- Headers:
Content-Type: application/json- Cookie must include
accessToken
- Body:
{ "title": "Task title", "description": "Task description" } - Returns:
success: truemessage: "Task created successfully"data.taskobject
- Status codes:
201 Createdon success400 Bad Requestwhen title or description is missing401 Unauthorizedif not authenticated
- Endpoint:
PATCH /task/update - Description: Update an existing task owned by the authenticated user
- Headers:
Content-Type: application/json- Cookie must include
accessToken
- Body:
{ "taskId": "taskObjectId", "title": "Updated title", "description": "Updated description" } - Returns:
success: truemessage: "Task updated successfully"data.taskobject
- Status codes:
200 OKon success400 Bad Requestwhen required fields are missing401 Unauthorizedif not authenticated404 Not Foundif task not found or not owned by the user
- Endpoint:
GET /task/my-tasks - Description: Retrieve all tasks for the authenticated user
- Headers:
- Cookie must include
accessToken
- Cookie must include
- Returns:
success: truemessage: "Tasks retrieved successfully"data.tasksarray
- Status codes:
200 OKon success401 Unauthorizedif not authenticated
- Endpoint:
DELETE /task/delete - Description: Delete a task owned by the authenticated user
- Headers:
Content-Type: application/json- Cookie must include
accessToken
- Body:
{ "taskId": "taskObjectId" } - Returns:
success: truemessage: "Task deleted successfully"data.taskobject
- Status codes:
200 OKon success400 Bad Requestwhen taskId is missing401 Unauthorizedif not authenticated404 Not Foundif task not found or not owned by the user
- Endpoint:
GET /task/all-tasks - Description: Retrieve all tasks in the system (admin only)
- Headers:
- Cookie must include
accessToken - User must be admin
- Cookie must include
- Returns:
success: truemessage: "All tasks retrieved successfully"data.tasksarray
- Status codes:
200 OKon success401 Unauthorizedif not authenticated403 Forbiddenif authenticated but not admin
- Endpoint:
DELETE /task/admin-delete - Description: Delete any task by ID (admin only)
- Headers:
Content-Type: application/json- Cookie must include
accessToken - User must be admin
- Body:
{ "taskId": "taskObjectId" } - Returns:
success: truemessage: "Task deleted successfully"data.taskobject
- Status codes:
200 OKon success400 Bad Requestwhen taskId is missing401 Unauthorizedif not authenticated403 Forbiddenif not admin404 Not Foundif task not found
- All protected routes require the
accessTokencookie returned by login. - Use
{{baseUrl}}in API clients like Postman when you define an environment variable. - If your backend is running on port
5001, usehttp://localhost:5001/api/v1as the base URL. - The admin-only routes must be accessed by users with
role: "admin".
- Description: Admin users are created manually through a backend script, not through a public API.
- Reason:
- Admin accounts are sensitive and should not be exposed to public signup.
- A public admin creation API would allow anyone to create elevated users.
- Admin credentials should be created securely only by developers or system administrators.
- How to create:
- Run the backend script directly from the terminal:
node ./utils/adminUserGenerate.js
- This script connects to the database, checks for an existing admin, and creates one if needed.
- It typically seeds a default admin user with a secure hashed password.
- Run the backend script directly from the terminal:
- What to do after creation:
- Use the created admin email and password to log in via
POST /auth/login. - Change the password immediately after first login if the script uses a default value.
- Use the created admin email and password to log in via
- Admin creation is a privileged operation that should not be available to regular users.
- Exposing admin creation through an API can lead to unauthorized privilege escalation.
- Keeping admin creation out of public routes helps protect your system from abuse.
- Use a secure backend script or protected deployment tool to assign admin roles.