Skip to content

Feat/logout#35

Merged
ayshadogo merged 6 commits intoDfunder:mainfrom
nafiuishaaq:feat/logout
Mar 4, 2026
Merged

Feat/logout#35
ayshadogo merged 6 commits intoDfunder:mainfrom
nafiuishaaq:feat/logout

Conversation

@nafiuishaaq
Copy link
Contributor

I've implemented the logout functionality with the following changes:

  1. Created Authentication Middleware (src/middlewares/auth.js)
    Verifies JWT tokens from the Authorization header
    Validates that the token is an access token (not refresh token)
    Attaches the user object and userId to the request
  2. Added Logout Controller (src/controllers/auth.controller.js)
    Added the logout function that:
    Gets the authenticated user's ID from the request
    Finds the user in the database
    Clears the refreshTokenHash and refreshTokenExpiresAt fields
    Returns a 200 OK response
  3. Added Logout Route (src/routes/auth.routes.js)
    Added POST /api/auth/logout endpoint
    Protected by the authenticate middleware
    Calls the logout controller
    API Endpoint
    POST /api/auth/logout
    Headers: Authorization: Bearer <access_token>
    Response: 200 OK with message "Logout successful"
    The logout endpoint securely invalidates the user's session by clearing the stored refresh token hash from the database, preventing any future token refresh attempts.

Closes #24

@ayshadogo
Copy link
Contributor

@nafiuishaaq
Please resolve conflicts

@nafiuishaaq
Copy link
Contributor Author

Resolved sir @ayshadogo

@ayshadogo ayshadogo merged commit b0f8f8b into Dfunder:main Mar 4, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Logout Endpoint

2 participants