feat: add JWT cookie infrastructure
Adds the foundation for secure cookie-based authentication without changing the authentication flow. This prepares the codebase for moving JWT tokens from Redux state to httpOnly cookies in a follow-up PR. Changes: - Added cookie-parser dependency for HTTP cookie handling - Added cookieParser() middleware to Express application - Created cookieHelpers.js utilities for consistent cookie options - Includes getAuthCookieOptions() for setting secure authentication cookies - Includes getClearAuthCookieOptions() for clearing cookies on logout Infrastructure only - no behavioral changes to authentication flow yet. Files added/modified: - package.json (cookie-parser dependency) - src/app.js (cookieParser middleware) - src/utils/cookieHelpers.js (cookie utilities) Next steps: - Follow-up PR will modify JWT verification to check cookies - Enable secure cookie-based authentication - Add logout functionality to clear httpOnly cookies Risk level: LOW (infrastructure only, no authentication changes)
This commit is contained in:
1 parent
cce930b90a
commit
05945a9a74
5 files changed
+137
No files matched your search
@@ -4,6 +4,7 @@ import { responseHandler } from "./middleware/responseHandler.js";
|
||||
import cors from "cors";
|
||||
import helmet from "helmet";
|
||||
import compression from "compression";
|
||||
import cookieParser from "cookie-parser";
|
||||
import languageMiddleware from "./middleware/languageMiddleware.js";
|
||||
import swaggerUi from "swagger-ui-express";
|
||||
import { handleErrors } from "./middleware/handleErrors.js";
|
||||
@@ -30,6 +31,7 @@ export const createApp = ({ services, controllers, envSettings, frontendPath, op
|
||||
})
|
||||
);
|
||||
app.use(express.json());
|
||||
app.use(cookieParser());
|
||||
app.use(
|
||||
helmet({
|
||||
hsts: false,
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Get standardized cookie options for authentication tokens
|
||||
* @param {Object} options - Additional cookie options
|
||||
* @returns {Object} Cookie options object
|
||||
*/
|
||||
export const getAuthCookieOptions = (options = {}) => {
|
||||
return {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "strict",
|
||||
maxAge: 2 * 60 * 60 * 1000, // 2 hours (matches JWT TTL)
|
||||
...options,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Clear cookie options for authentication tokens
|
||||
* @returns {Object} Cookie clear options object
|
||||
*/
|
||||
export const getClearAuthCookieOptions = () => {
|
||||
return {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "strict",
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user