Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/khushboodaryani/Chat-App/llms.txt

Use this file to discover all available pages before exploring further.

The Users API exposes a single endpoint that returns every registered account in the database, minus the currently authenticated user. It is the data source for the chat sidebar — the client calls this endpoint on mount to build the list of people the logged-in user can start or continue a conversation with. Because it is protected by the protectRoute middleware, only authenticated users can retrieve the contact list.
This endpoint requires a valid jwt cookie. If the cookie is missing or invalid, the server responds with 401 Unauthorized. Make sure the user is logged in before calling this route.

GET /api/users

Returns an array of all User documents stored in MongoDB, filtered to exclude the currently authenticated user. The password field is stripped from every document at the database query level using Mongoose’s .select('-password'), so it is impossible for credentials to leak through this endpoint regardless of how the response is handled on the client.

Request parameters

None. The authenticated user’s identity is derived from the jwt cookie by the protectRoute middleware.

Response — 200 OK

Returns an array of User objects. The array will be empty if no other users have registered yet.
_id
string
The MongoDB ObjectId of the user, represented as a 24-character hex string.
fullName
string
The user’s display name as provided during signup.
username
string
The user’s unique login handle.
gender
string
Either "male" or "female", as provided during signup.
profilePic
string
The avatar URL auto-generated at signup time via avatar.iran.liara.run.
createdAt
string
ISO 8601 timestamp of when the user account was created, added by Mongoose’s timestamps option.
updatedAt
string
ISO 8601 timestamp of the last update to the user document, added by Mongoose’s timestamps option.
200 Response
[
  {
    "_id": "664f1c2e8b3a4c0012ef9def",
    "fullName": "Ali Hassan",
    "username": "alihassan",
    "gender": "male",
    "profilePic": "https://avatar.iran.liara.run/public/boy?username=alihassan",
    "createdAt": "2024-05-28T08:14:22.000Z",
    "updatedAt": "2024-05-28T08:14:22.000Z"
  }
]

Error responses

HTTP Statuserror valueCause
401"Unauthorized - No Token Provided"JWT cookie is absent
401"Unauthorized - Invalid Token"JWT signature verification failed
404"User not found"Decoded JWT refers to a deleted user
500"Internal server error"Unexpected server-side exception
The password field is always excluded via .select('-password') in the Mongoose query — this is enforced entirely server-side and cannot be bypassed by any client-side request manipulation.
On the frontend, this endpoint is consumed by the useGetConversations() custom hook, which fires on component mount to populate the sidebar with the list of available contacts. The hook stores the result in local state and re-renders the sidebar automatically when the data arrives.

Build docs developers (and LLMs) love