From 86a18c957355a053ddfc3f6843c5dfbb274d4989 Mon Sep 17 00:00:00 2001 From: Piyush Kumar Date: Fri, 15 Mar 2024 08:14:52 +0530 Subject: [PATCH 1/2] #1: fixing error messages in login form --- frontend/src/hooks/useLogin.js | 4 +++- frontend/src/index.css | 5 +++++ frontend/src/pages/Login.js | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/hooks/useLogin.js b/frontend/src/hooks/useLogin.js index f25cb37..7795eef 100644 --- a/frontend/src/hooks/useLogin.js +++ b/frontend/src/hooks/useLogin.js @@ -3,6 +3,7 @@ import { useAuthContext } from "./useAuthContext"; export const useLogin = () => { const [isLoading, setIsLoading] = useState(null); + const [error,setError] = useState(null) const { dispatch } = useAuthContext(); const login = async (email, password) => { @@ -16,6 +17,7 @@ export const useLogin = () => { const json = await response.json(); if (!response.ok) { + setError(json.error) setIsLoading(false); } if (response.ok) { @@ -29,5 +31,5 @@ export const useLogin = () => { } }; - return { login, isLoading }; + return { login, isLoading ,error}; }; diff --git a/frontend/src/index.css b/frontend/src/index.css index 913a231..ed6a2bb 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -119,4 +119,9 @@ form.signup, form.login { padding: 20px; background: #fff; border-radius: 4px; +} + +.error-element{ +color: red; +font-weight: 500; } \ No newline at end of file diff --git a/frontend/src/pages/Login.js b/frontend/src/pages/Login.js index 0163641..b3f3d18 100644 --- a/frontend/src/pages/Login.js +++ b/frontend/src/pages/Login.js @@ -4,7 +4,7 @@ import { useLogin } from "../hooks/useLogin"; const Login = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const { login, isLoading } = useLogin(); + const { login, isLoading, error } = useLogin(); const handleSubmit = async (e) => { e.preventDefault(); @@ -28,7 +28,7 @@ const Login = () => { /> - {/* Display error message if there was an issue with the login */} + {error &&
{error}
} ); }; From 013e23784a2c81b61104165d6314401114ff9a87 Mon Sep 17 00:00:00 2001 From: Piyush Kumar Date: Fri, 15 Mar 2024 08:37:20 +0530 Subject: [PATCH 2/2] #2: fixing signUp form error messages display --- frontend/src/hooks/useSignup.js | 5 +++-- frontend/src/pages/Signup.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useSignup.js b/frontend/src/hooks/useSignup.js index c81a3e9..a8b7d22 100644 --- a/frontend/src/hooks/useSignup.js +++ b/frontend/src/hooks/useSignup.js @@ -4,7 +4,7 @@ import { useAuthContext } from "./useAuthContext"; export const useSignup = () => { const [isLoading, setIsLoading] = useState(null); const { dispatch } = useAuthContext(); - + const [error, setError] = useState(null); const signup = async (email, password) => { setIsLoading(true); @@ -16,6 +16,7 @@ export const useSignup = () => { const json = await response.json(); if (!response.ok) { + setError(json.error); setIsLoading(false); } if (response.ok) { @@ -29,5 +30,5 @@ export const useSignup = () => { } }; - return { signup, isLoading }; + return { signup, isLoading, error }; }; diff --git a/frontend/src/pages/Signup.js b/frontend/src/pages/Signup.js index 5d00c16..e6e1f58 100644 --- a/frontend/src/pages/Signup.js +++ b/frontend/src/pages/Signup.js @@ -4,7 +4,7 @@ import { useSignup } from "../hooks/useSignup"; const Signup = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const { signup, isLoading } = useSignup(); + const { signup, isLoading, error } = useSignup(); const handleSubmit = async (e) => { e.preventDefault(); @@ -30,7 +30,7 @@ const Signup = () => { /> - {/* Display error message if there was an issue with the Sign up */} + {error &&
{error}
} ); };