From 08fc0e790eab549dd9b27e20ef7bac6b17dc3e10 Mon Sep 17 00:00:00 2001 From: Karan Date: Sun, 23 Feb 2025 10:48:41 +0530 Subject: [PATCH] Fixed cookie issue --- Backend/Controllers/user.controller.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Backend/Controllers/user.controller.js b/Backend/Controllers/user.controller.js index ff83e6c..b5a7302 100644 --- a/Backend/Controllers/user.controller.js +++ b/Backend/Controllers/user.controller.js @@ -65,12 +65,12 @@ const loginUser = catchAsyncErrors(async (req, res) => { return res .status(200) - .cookie(process.env.TOKEN_NAME, token, { + .cookie("uid", token, { + httpOnly: true, // Prevent access from JavaScript (recommended for security) + secure: false, // ⚠️ Set to `false` for localhost + sameSite: "Lax", // Use "Lax" instead of "None" for better compatibility path: "/", - sameSite: "None", - secure: process.env.NODE_ENV === "production", - httpOnly: true, - expires: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), + expires: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days }) .json({ success: true, @@ -260,8 +260,6 @@ const resetPassword = catchAsyncErrors(async (req, res) => { // get user personal details const getUserDetails = catchAsyncErrors(async (req, res) => { - - const user = await User.findById(req.user._id); if (!user) {