Skip to content

Implemented Logout and Logout-All Sessions Endpoints - #370

Merged
yusuftomilola merged 2 commits into
DistinctCodes:mainfrom
Sandijigs:Logout-and-Logout-All-sessions
Oct 4, 2025
Merged

Implemented Logout and Logout-All Sessions Endpoints#370
yusuftomilola merged 2 commits into
DistinctCodes:mainfrom
Sandijigs:Logout-and-Logout-All-sessions

Conversation

@Sandijigs

Copy link
Copy Markdown
Contributor

PR: Implement Logout and Logout-All Sessions Endpoints

📋 Description

This PR implements two authentication-related endpoints for user session management:

  1. Single Session Logout (POST /auth/logout) - Invalidates the current user session/token
  2. Multi-Session Logout (POST /auth/logout-all) - Invalidates all active sessions/tokens for the authenticated user across all devices

Both endpoints follow authentication best practices with proper token invalidation, error handling, and security measures.

✨ Changes Made

Endpoints Implemented

  • POST /auth/logout - Logs out the current session

    • Invalidates the current authentication token
    • Removes session data from storage
    • Returns appropriate success/error responses
  • POST /auth/logout-all - Logs out all sessions

    • Invalidates all tokens associated with the authenticated user
    • Clears all active sessions across devices
    • Returns appropriate success/error responses

Security & Error Handling

  • ✅ Authentication middleware ensures only authenticated users can access these endpoints
  • ✅ Proper error handling for edge cases:
    • Invalid or expired tokens
    • Missing authentication credentials
    • Non-existent sessions
  • ✅ Appropriate HTTP status codes and error messages

Testing

  • ✅ Server runs without runtime errors
  • ✅ Endpoints tested with valid and invalid tokens
  • ✅ Verified session invalidation works correctly
  • ✅ Confirmed multi-device logout functionality

Screenshot

Screenshot 2025-10-04 at 10 07 14 pm

Closes #309

🧪 Testing Instructions

  1. Start the server
  2. Authenticate a user to get a valid token
  3. Test single logout:
   curl -X POST http://localhost:PORT/auth/logout \
     -H "Authorization: Bearer YOUR_TOKEN"

@vercel

vercel Bot commented Oct 4, 2025

Copy link
Copy Markdown

@Sandijigs is attempting to deploy a commit to the naijabuz's projects Team on Vercel.

A member of the Team first needs to authorize it.

@yusuftomilola yusuftomilola left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Will resolve the other errors on my end.

@yusuftomilola
yusuftomilola merged commit da0876b into DistinctCodes:main Oct 4, 2025
4 of 5 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.

BACKEND: Implement Logout and Logout-All Sessions Endpoints

2 participants