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 theDocumentation 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.
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 allUser 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 thejwt 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.The MongoDB ObjectId of the user, represented as a 24-character hex string.
The user’s display name as provided during signup.
The user’s unique login handle.
Either
"male" or "female", as provided during signup.The avatar URL auto-generated at signup time via
avatar.iran.liara.run.ISO 8601 timestamp of when the user account was created, added by Mongoose’s
timestamps option.ISO 8601 timestamp of the last update to the user document, added by Mongoose’s
timestamps option.200 Response
Error responses
| HTTP Status | error value | Cause |
|---|---|---|
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.