Skip to main content

Authentication

TaskSocial uses JWT-based authentication with an HttpOnly cookie. The authentication flow is:

Register a user

Create an account using:
Example request:
The server validates the registration data and stores the new user in MongoDB. Passwords are hashed with bcrypt before they are stored.

Log in

After registering, log in using:
Example request:
The server:
  1. Finds the user by email.
  2. Compares the submitted password with the stored bcrypt hash.
  3. Creates a JWT after successful verification.
  4. Stores the JWT in an HttpOnly tokenName cookie.
You do not need to generate an API key manually. After a successful login, the server sends the JWT through the tokenName cookie. The cookie is marked as HttpOnly, which means client-side JavaScript cannot directly read the authentication token. The browser can still send the cookie with requests to the API. The basic flow is:

Making a protected request

Once logged in, you can access protected endpoints. For example:
The authentication middleware reads the tokenName cookie and verifies the JWT.
If authentication succeeds, the request continues to the relevant controller. If the JWT is missing or invalid, the protected request is rejected.

Authentication and task ownership

Authentication identifies the user making the request. Task ownership adds another authorization check. When a user tries to update or delete a task, the backend checks whether that task belongs to the authenticated user. This prevents one user from modifying another user’s tasks. The flow is:

Log out

To log out, use:
The server clears the authentication cookie. After logging out, protected endpoints can no longer be accessed using the cleared cookie.

Authentication endpoints

For request schemas, responses, and interactive examples, see the API Reference.