dev - migração localStorage → httpOnly cookie#71
Merged
Conversation
…as de login, cadastro e logout
… de login e logout
…y em vez de tokens
|
icrcode-senai
approved these changes
Jun 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


This pull request implements a major change in how authentication is handled across both the backend and frontend. The system now uses HTTP-only cookies to store authentication tokens instead of localStorage and Authorization headers. This improves security by protecting tokens from XSS attacks and simplifies session management. The backend sets and clears the cookie, and the frontend no longer manages or sends tokens explicitly. Additionally, several new endpoints and utilities were added to support cookie-based authentication.
Key changes include:
Backend: Migration to Cookie-based Authentication
Added
cookie-parsermiddleware and its types to parse cookies in Express, and updated authentication middleware to extract JWT tokens from thevalida_tokencookie instead of the Authorization header. (backend/package.json,backend/package-lock.json,backend/src/aplicativo.ts,backend/src/middleware/autenticacao.ts) [1] [2] [3] [4] [5] [6] [7] [8] [9]Updated authentication routes to set the JWT as an HTTP-only cookie on login and registration, and to clear it on logout. Also added
/meand/logoutendpoints for session management. (backend/src/modulos/auth/rotas.ts) [1] [2] [3] [4] [5]Frontend: Removal of Token Management and API Adjustments
Removed all logic related to storing, retrieving, and sending tokens in localStorage and Authorization headers. API requests now use
withCredentials: trueto send cookies automatically. (frontend/src/contexts/AuthContext.tsx,frontend/src/services/api.ts,frontend/src/services/auth.ts,frontend/src/pages/Login.tsx,frontend/src/pages/Cadastro.tsx,frontend/src/pages/Perfil.tsx) [1] [2] [3] [4] [5] [6] [7] [8] [9]Updated authentication context and related components to only manage user information, not tokens. Login/logout flows now interact with the backend for session management and no longer rely on local token storage. (
frontend/src/contexts/AuthContext.tsx,frontend/src/services/auth.ts) [1] [2] [3] [4]Testing and Helpers Updates
frontend/src/test/contexts/AuthContext.test.tsx,frontend/src/test/helpers/renderWithProviders.tsx) [1] [2] [3] [4] [5]These changes collectively modernize and secure the authentication flow, moving all sensitive token handling to HTTP-only cookies managed by the backend.