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/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/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 &&