diff --git a/frontend-next/src/app/globals.css b/frontend-next/src/app/globals.css index 1679e2d..308cb63 100644 --- a/frontend-next/src/app/globals.css +++ b/frontend-next/src/app/globals.css @@ -29,3 +29,9 @@ input { margin: 5px; } +input.err { + border: 2px solid red; + border-radius: 4px; + padding: 10px 10px; + margin: 5px; +} diff --git a/frontend-next/src/app/login/page.js b/frontend-next/src/app/login/page.js index c3026a3..662b559 100644 --- a/frontend-next/src/app/login/page.js +++ b/frontend-next/src/app/login/page.js @@ -1,39 +1,40 @@ "use client"; -import { useForm } from "react-hook-form"; +import { useForm, Form } from "react-hook-form"; import { useRouter } from "next/navigation"; import "../globals.css" function Login() { var router = useRouter(); - var { register, handleSubmit } = useForm(); - async function Login(data) { - const res = await fetch("/api/login", { - method: "POST", - body: JSON.stringify(data ? data : {}), - }); - - if (res.ok) { - router.push("/app"); - } - } - + //var { register, handleSubmit } = useForm(); + var { register, control, setError, formState: { errors } } = useForm() return (
- + Chat with friends! -
-

Login

-
-
-
-
- Don't have an account? Sign Up -
+
+

Login

+ {(errors.email && errors.password) &&
Invalid Email or Password.
} +
{ + router.push("/app"); + }} + onError={() => { + const formError = { type: "server", message: "Username or Password Incorrect" } + // set same error in both: + setError('password', formError) + setError('email', formError) + }} + control={control} + > +
+
+ +
Need an account? Sign Up
+
diff --git a/frontend-next/src/app/register/page.js b/frontend-next/src/app/register/page.js index a2aa40b..f70bce3 100644 --- a/frontend-next/src/app/register/page.js +++ b/frontend-next/src/app/register/page.js @@ -21,12 +21,12 @@ function Register() {
- + Chat with friends! -
-

Register

+
+

Register