Skip to content

feat: secure auth refactor with http-only cookies & token rotation#1305

Open
PremSahith wants to merge 1 commit into
JiyaBatra:mainfrom
PremSahith:feat/1295-secure-auth-refactor
Open

feat: secure auth refactor with http-only cookies & token rotation#1305
PremSahith wants to merge 1 commit into
JiyaBatra:mainfrom
PremSahith:feat/1295-secure-auth-refactor

Conversation

@PremSahith

Copy link
Copy Markdown
Contributor

🛠️ Related Issue

Closes: #1295

📌 Description

This PR addresses issue #1295 by completely overhauling the application's authentication flow. It migrates away from the insecure practice of returning JWT access tokens in the JSON response payload and storing them in client-side localStorage. Instead, it introduces a dual-token (Access + Refresh) architecture utilizing strict, HttpOnly cookies to prevent Cross-Site Scripting (XSS) token theft and implements automated token rotation.

✨ Changes Made

  • Secure Dual-Token System: Refactored backend routes (login.js, register.js, googleAuth.js) to generate a short-lived accessToken (15 mins) and a long-lived refreshToken (7 days), attached directly to the response via secure, HttpOnly cookies.
  • Refresh Token Endpoint & Rotation: Added /api/auth/refresh endpoint to handle token rotation securely when the current access token expires.
  • Axios Interceptors: Added a global Axios interceptor (client/src/config/axiosSetup.js) that automatically catches 401 Unauthorized responses, hits the refresh endpoint, and silently retries the failed requests.
  • Client Storage Cleanup: Overhauled AuthProvider.jsx, Signup.jsx, Login.jsx, and OAuthCallback.jsx to completely remove all traces of localStorage.setItem('authToken'), leaving only non-sensitive user data in state for quick UI hydration.

📷 Screenshots

N/A - This is a purely logical and security-oriented refactor, no user-facing UI changes were made.

🧪 Type of Change

  • Bug fix
  • New feature
  • UI/UX improvement
  • Documentation update

✔️ Checklist

  • My code follows project style guidelines
  • I have tested my changes
  • I have linked the related issue
  • No unnecessary files are included

🚨 Notes for Contributors

  • Ensure that REFRESH_TOKEN_SECRET and optionally REFRESH_TOKEN_EXPIRES_IN are configured in your .env for the backend.

@vercel

vercel Bot commented Jun 21, 2026

Copy link
Copy Markdown

@PremSahith is attempting to deploy a commit to the jiya's projects Team on Vercel.

A member of the Team first needs to authorize it.

@netlify

netlify Bot commented Jun 21, 2026

Copy link
Copy Markdown

Deploy Preview for codevibeforyou ready!

Name Link
🔨 Latest commit 4752d7a
🔍 Latest deploy log https://app.netlify.com/projects/codevibeforyou/deploys/6a37ae63797b8d00086a35d7
😎 Deploy Preview https://deploy-preview-1305--codevibeforyou.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@PremSahith

Copy link
Copy Markdown
Contributor Author

@JiyaBatra Could you review this and suggest if any improvements are required

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.

[Feature]: Secure Authentication Refactor (HTTP-Only Cookies & Refresh Token Rotation)

1 participant