diff --git a/backend/server.js b/backend/server.js index 3f19f00..306d71e 100644 --- a/backend/server.js +++ b/backend/server.js @@ -12,7 +12,15 @@ require('./config/passportConfig'); const app = express(); // CORS configuration -app.use(cors('*')); +const allowedOrigins = (process.env.FRONTEND_URL || 'http://localhost:5173') + .split(',') + .map((origin) => origin.trim()) + .filter(Boolean); + +app.use(cors({ + origin: allowedOrigins, + credentials: true, +})); // Middleware app.use(bodyParser.json()); diff --git a/src/pages/Login/Login.tsx b/src/pages/Login/Login.tsx index e77ee3b..85de642 100644 --- a/src/pages/Login/Login.tsx +++ b/src/pages/Login/Login.tsx @@ -30,11 +30,15 @@ const Login: React.FC = () => { setIsLoading(true); try { - const response = await axios.post(`${backendUrl}/api/auth/login`, formData); + const response = await axios.post( + `${backendUrl}/api/auth/login`, + formData, + { withCredentials: true } + ); setMessage(response.data.message); if (response.data.message === 'Login successful') { - navigate("/"); + navigate("/home"); } } catch (error: any) { setMessage(error.response?.data?.message || "Something went wrong"); diff --git a/src/pages/Signup/Signup.tsx b/src/pages/Signup/Signup.tsx index b55df05..231da5e 100644 --- a/src/pages/Signup/Signup.tsx +++ b/src/pages/Signup/Signup.tsx @@ -38,6 +38,37 @@ const SignUp: React.FC = () => { setIsLoading(true); try { + const response = await axios.post( + `${backendUrl}/api/auth/signup`, + formData, + { withCredentials: true } + ); + setMessage(response.data.message); // Show success message from backend + + // Navigate to login page after successful signup + if (response.data.message === 'User created successfully') { + navigate("/login");} + + + // // Simulate API call (replace with your actual backend integration) + // try { + // // Mock successful signup + // setMessage("Account created successfully! Redirecting to login..."); + + // // In your actual implementation, integrate with your backend here: + // // const response = await fetch(`${backendUrl}/api/auth/signup`, { + // // method: 'POST', + // // headers: { 'Content-Type': 'application/json' }, + // // body: JSON.stringify(formData) + // // }); + + // setTimeout(() => { + // // Navigate to login page in your actual implementation + // console.log("Redirecting to login page..."); + // }, 2000); + + } catch (error) { + setMessage("Something went wrong. Please try again."); const response = await axios.post(`${backendUrl}/api/auth/signup`, formData); setMessage(response.data.message);