- Endpoint:
POST /auth/register
- Description: Registers a new user in the system.
POST /auth/register
Content-Type: application/json
{
"username": "johndoe",
"email": "johndoe@example.com",
"password": "securePassword123"
}
{
"message": "User registered successfully",
"user": {
"id": "64b8f8b3a19d4b0012345678",
"username": "johndoe",
"email": "johndoe@example.com",
"createdAt": "2024-10-31T08:22:17.123Z"
}
}
- Endpoint:
POST /auth/login
- Description: Logs in an existing user and initiates a session.
POST /auth/login
Content-Type: application/json
{
"email": "johndoe@example.com",
"password": "securePassword123"
}
{
"message": "Login successful",
"user": {
"id": "64b8f8b3a19d4b0012345678",
"username": "johndoe",
"email": "johndoe@example.com",
"sessionToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
}
- Endpoint:
GET /users
- Description: Retrieves a list of all registered users. Authentication is required.
GET /users
Authorization: Bearer <session-token>
{
"users": [
{
"id": "64b8f8b3a19d4b0012345678",
"username": "johndoe",
"email": "johndoe@example.com"
},
{
"id": "64b8f8b3a19d4b0012345679",
"username": "janedoe",
"email": "janedoe@example.com"
}
]
}
- Endpoint:
PATCH /users/:id
- Description: Updates a user's information by ID. Authentication and ownership are required.
PATCH /users/64b8f8b3a19d4b0012345678
Content-Type: application/json
Authorization: Bearer <session-token>
{
"username": "johnsmith"
}
{
"message": "User updated successfully",
"user": {
"id": "64b8f8b3a19d4b0012345678",
"username": "johnsmith",
"email": "johndoe@example.com"
}
}
- Endpoint:
DELETE /users/:id
- Description: Deletes a user by ID. Authentication and ownership are required.
DELETE /users/64b8f8b3a19d4b0012345678
Authorization: Bearer <session-token>
{
"message": "User deleted successfully"
}