Skip to content

feat(auth): Implement complete logout functionality with Redis token blacklist and HTTP-only cookie authentication#7

Open
zaibamachhaliya wants to merge 2 commits into
imanchalsingh:mainfrom
zaibamachhaliya:feature/logout
Open

feat(auth): Implement complete logout functionality with Redis token blacklist and HTTP-only cookie authentication#7
zaibamachhaliya wants to merge 2 commits into
imanchalsingh:mainfrom
zaibamachhaliya:feature/logout

Conversation

@zaibamachhaliya
Copy link
Copy Markdown

📋 Summary

This PR adds complete logout functionality with backend token invalidation using Redis blacklist and HTTP-only cookies for secure authentication.


🚀 What's New?

Backend Changes (8 files)

File Change
server/config/redis.js NEW - Redis connection configuration
server/controllers/userController.js Added logoutUser function with token blacklist
server/middleware/authenticationUser.js Added Redis blacklist check in auth middleware
server/routes/routers.js Added POST /logout route
server/index.js Added cookie-parser & updated CORS credentials
server/package.json Added redis and cookie-parser dependencies

Frontend Changes (7 files)

File Change
client/src/components/ProtectedRoute.tsx NEW - Route protection component
client/src/components/Home/Home.tsx Added handleLogout function with API call
client/src/components/Authentication/Login.tsx Migrated to cookie-based auth (removed localStorage)
client/src/components/Authentication/Register.tsx Migrated to cookie-based auth (removed localStorage)
client/src/services/api.ts Added withCredentials: true
client/src/App.tsx Wrapped /home route with ProtectedRoute
client/src/main.tsx Fixed duplicate Router issue

🔒 Security Improvements

Issue Fix
XSS attack on token ✅ HTTP-only cookies (inaccessible to JavaScript)
Token reuse after logout ✅ Redis blacklist with TTL
URL bypass after logout ✅ ProtectedRoute component redirects to login
CSRF attacks ✅ SameSite=Lax cookie attribute

🧪 Testing Done

  • Login sets HTTP-only cookie in browser
  • Cookie sent with subsequent API requests
  • Logout clears cookie from browser
  • Logout adds token to Redis blacklist
  • Blacklisted token returns 401 on /auth call
  • Manual URL /home redirects to login after logout
  • Page refresh maintains session until logout

📊 Files Changed Summary

Type New Files Modified Files Total
Backend 1 (redis.js) 7 8
Frontend 1 (ProtectedRoute.tsx) 6 7
Total 2 13 15

🔧 Technologies Used

  • Redis - Token blacklist storage with TTL
  • cookie-parser - HTTP-only cookie handling
  • JWT - Token generation and verification
  • Axios - withCredentials for cross-origin cookies
  • React Router - ProtectedRoute for route protection

✅ Related Issue

Closes #6 (Logout Functionality)

- Added api.ts service for backend API calls
- Updated Analytics.tsx to fetch real data from backend
- Updated MyFiles.tsx with backend integration
- Removed all localStorage dummy data
- Added file management routes (GET, DELETE, bulk-delete)
- Added File model and controller
- Added .env.example for environment setup
- Fixed Cloudinary upload integration

Closes imanchalsingh#1
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@zaibamachhaliya is attempting to deploy a commit to the imanchalsingh Team on Vercel.

A member of the Team first needs to authorize it.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 28, 2026

👷 Deploy request for file-sharingsystem pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6491252

@imanchalsingh imanchalsingh added SSoC26 Official label of org Hard Point - 40 labels May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hard Point - 40 SSoC26 Official label of org

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Logout Functionality

2 participants