From 6e21552934b99ca3930be124e1cae824953ee822 Mon Sep 17 00:00:00 2001 From: Rutik Date: Mon, 1 Jul 2024 12:34:52 +0530 Subject: [PATCH] fix(signup): handle cookies in Axios requests for successful signup --- backend/src/app.ts | 1 + frontend/src/pages/Signup/SignupHelperFunctions.js | 4 +++- frontend/src/utility/envHelper/envHelper.js | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/src/app.ts b/backend/src/app.ts index 3b9c854..32faa38 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -17,6 +17,7 @@ app.use(cookieParser()); app.use( cors({ origin: config.CLIENT_URL, + credentials: true }) ); diff --git a/frontend/src/pages/Signup/SignupHelperFunctions.js b/frontend/src/pages/Signup/SignupHelperFunctions.js index e54f45f..6e41430 100644 --- a/frontend/src/pages/Signup/SignupHelperFunctions.js +++ b/frontend/src/pages/Signup/SignupHelperFunctions.js @@ -15,6 +15,7 @@ import { Config } from "../../App"; * @param {Function} setUserData - Function to set the user data state. * @param {Function} navigate - Function to navigate to a different route. */ + const registerUser = async (userData, setIsLoading, setUserData, navigate) => { try { const validationMessage = validateUserData(userData); @@ -22,7 +23,8 @@ const registerUser = async (userData, setIsLoading, setUserData, navigate) => { setIsLoading(true); const response = await axios.post( `${Config.endpoint}auth/register`, - userData + userData, + { withCredentials: true } // This is the important part for the cookies ); if (response.status === 201) { diff --git a/frontend/src/utility/envHelper/envHelper.js b/frontend/src/utility/envHelper/envHelper.js index eac64b0..51dfb81 100644 --- a/frontend/src/utility/envHelper/envHelper.js +++ b/frontend/src/utility/envHelper/envHelper.js @@ -25,9 +25,9 @@ export const getConfig = () => { return { endpoint: REACT_ENV === "development" - ? "http://localhost:8082/api/v1" + ? "http://localhost:8082/api/v1/" : REACT_ENV === "deployment" - ? "https://referralnetworkhub.onrender.com/api/v1" + ? "https://referralnetworkhub.onrender.com/api/v1/" : "", }; };