From 3812978eec3bffba94432bfe4baf97e7f7d3b507 Mon Sep 17 00:00:00 2001 From: Mikias Berhanu Date: Tue, 27 Aug 2024 23:18:58 +0300 Subject: [PATCH 1/3] swagger --- .../app/(directories)/auth/login/page.tsx | 17 ++++++++++ .../app/api/auth/[...nextauth]/options.ts | 26 +++++++-------- .../components/SignUp/SignUpLayout.tsx | 33 ++++++++++++------- .../redux/api/authentication-controller.tsx | 2 +- 4 files changed, 51 insertions(+), 27 deletions(-) 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..5334738fc 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("/"); + } else { + setErrorMessage("Invalid email or password"); + } } catch (error) { console.log("error", error); } @@ -72,7 +82,14 @@ const Login = () => { }, })} /> +
+ {!errors.password && loginErrorMessage && ( + + + )} +
+