diff --git a/web/AAiT-web-group-7/bankdash/app/(directories)/auth/login/page.tsx b/web/AAiT-web-group-7/bankdash/app/(directories)/auth/login/page.tsx index e8a4315cd..d4ef6d0a3 100644 --- a/web/AAiT-web-group-7/bankdash/app/(directories)/auth/login/page.tsx +++ b/web/AAiT-web-group-7/bankdash/app/(directories)/auth/login/page.tsx @@ -1,6 +1,8 @@ "use client"; import Link from "next/link"; +import { useRouter } from "next/navigation"; import { useForm } from "react-hook-form"; +import { useState } from "react"; import { useUserLoginMutation } from "@/redux/api/authentication-controller"; import { signIn } from "next-auth/react"; import ErrorMessage from "@/components/Message/ErrorMessage"; @@ -11,9 +13,11 @@ interface FormValues { } const Login = () => { + const router = useRouter(); const [login, { isLoading }] = useUserLoginMutation(); const { register, handleSubmit, formState } = useForm(); const { errors } = formState; + const [loginErrorMessage, setErrorMessage] = useState(""); const onSubmit = async (inputData: FormValues) => { console.log("inputData", inputData); @@ -25,6 +29,12 @@ const Login = () => { callbackUrl: "/", }); console.log("response", response); + if (response?.ok) { + setErrorMessage(""); + router.push("/dashboard"); + } else { + setErrorMessage("Invalid Username or password"); + } } catch (error) { console.log("error", error); } @@ -72,7 +82,14 @@ const Login = () => { }, })} /> +
+ {!errors.password && loginErrorMessage && ( + + + )} +
+