From 8afa7fd8d4c3c72f82c5f4be73a26bba1a9fde23 Mon Sep 17 00:00:00 2001 From: jeevan-aj Date: Tue, 10 Dec 2024 21:14:54 +0530 Subject: [PATCH] fix:secure:true enabled so when testing in local change it --- backend/controllers/authController.js | 11 +++++++---- client/src/pages/user/Vehicles.jsx | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/controllers/authController.js b/backend/controllers/authController.js index 03bf49e..c20b359 100644 --- a/backend/controllers/authController.js +++ b/backend/controllers/authController.js @@ -51,8 +51,8 @@ export const refreshToken = async (req, res, next) => { await User.updateOne({ _id: user._id }, { refreshToken: newRefreshToken }); res - .cookie("access_token", newAccessToken, { httpOnly: true, maxAge: 900000,sameSite: 'none', }) // 15 minutes - .cookie("refresh_token", newRefreshToken, { httpOnly: true, maxAge: 604800000 ,sameSite: 'none',}) // 7 days + .cookie("access_token", newAccessToken, { httpOnly: true, maxAge: 900000,sameSite: 'none',secure:true }) // 15 minutes + .cookie("refresh_token", newRefreshToken, { httpOnly: true, maxAge: 604800000 ,sameSite: 'none',secure:true}) // 7 days .status(200) .json({ accessToken: newAccessToken }); } catch (error) { @@ -89,17 +89,20 @@ export const signIn = async (req, res, next) => { isAdmin: validUser.isAdmin, isUser: validUser.isUser, }; - next(); + res - .cookie("access_token", accessToken, { httpOnly: true, maxAge: 900000 ,sameSite: 'none',}) // 15 minutes + .cookie("access_token", accessToken, { httpOnly: true, maxAge: 900000 ,sameSite: 'none', secure:true}) // 15 minutes .cookie("refresh_token", refreshToken, { httpOnly: true, maxAge: 604800000, sameSite: 'none', + secure:true }) // 7 days .status(200) .json(responsePayload); + + next(); } catch (error) { next(error); } diff --git a/client/src/pages/user/Vehicles.jsx b/client/src/pages/user/Vehicles.jsx index 2a8b329..150a6a1 100644 --- a/client/src/pages/user/Vehicles.jsx +++ b/client/src/pages/user/Vehicles.jsx @@ -22,6 +22,7 @@ export const onVehicleDetail = async (id, dispatch, navigate) => { headers: { "Content-Type": "application/json", }, + credentials:'include', body: JSON.stringify({ id }), }); const data = await res.json(); @@ -56,7 +57,9 @@ const Vehicles = () => { const fetchData = async () => { console.log(BASE_URL) try { - const res = await fetch(`${BASE_URL}/api/user/listAllVehicles`); + const res = await fetch(`${BASE_URL}/api/user/listAllVehicles`,{ + credentials:'include' + }); if (!res.ok) { console.log("not success"); }