From b969a05224b2fa0d6932ea921446d4e51a99efff Mon Sep 17 00:00:00 2001 From: Saksham2k3s Date: Sun, 9 Jun 2024 17:16:40 +0530 Subject: [PATCH 1/2] Solved issue 182 --- src/pages/Login.jsx | 58 ++++++++++---------------------------------- src/pages/Signup.jsx | 8 +++--- 2 files changed, 18 insertions(+), 48 deletions(-) diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index 4fbb1fe..af1db37 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -33,17 +33,12 @@ function Login() { : `${process.env.REACT_APP_BASE_URL}/canteenLogin`; - // const apiUrl = `http://localhost:4000/api/v1/studentLogin`; - const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentLogin`; + // const apiUrl = `http://localhost:8000/api/v1/studentLogin`; + // // const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentLogin`; - - // Assuming the response contains a token - const token = response.data.token; try { const response = await axios.post(apiUrl, formData); const { token, cantId } = response.data; - - localStorage.setItem("token", token); localStorage.setItem("canteenId", cantId); @@ -51,39 +46,14 @@ function Login() { toast.success("User logged in successfully!"); navigate("/home"); } else { - toast.success("User Logged in "); + toast.success("User Logged in"); navigate(`/section/${cantId}`); } - } - - else{ - const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenLogin`; - // const apiUrl = `http://localhost:4000/api/v1/canteenLogin`; - setLoading(true); - - axios - .post(apiUrl, formData) - .then((response) => { - setLoading(false); - localStorage.setItem("canteenId", response.data.cantId); - localStorage.setItem("token", response.data.token); - toast.success("User Logged in "); - navigate( - `/section/${response.data.cantId}` - ); - }) - .catch((error) => { - //Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown - setLoading(false); - toast.error("Failed to login"); - }); - } catch (error) { - toast.error("Failed To Login. Please try again."); - console.error(error); + const errorMessage = error.response?.data?.message || "Failed to login. Please try again."; + toast.error(errorMessage); } finally { setLoading(false); - } } @@ -148,7 +118,7 @@ function Login() {
-
- -

- Forogt Password ? -

- -
+
+ +

Forgot Password ?

+ +