From 838366d51087411cfa91e8f0c430068ccf6873b8 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Fri, 13 Jan 2023 16:35:20 +0100 Subject: [PATCH] handle signup api errors --- apps/web/components/signup.tsx | 25 ++++++++++++++++++++++++- apps/web/pages/api/auth/signup.ts | 7 +++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/web/components/signup.tsx b/apps/web/components/signup.tsx index 2dacf1831..ff6c726b8 100644 --- a/apps/web/components/signup.tsx +++ b/apps/web/components/signup.tsx @@ -1,3 +1,4 @@ +import { XCircleIcon } from "@heroicons/react/24/outline"; import { signIn } from "next-auth/react"; import Link from "next/link"; import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; @@ -8,7 +9,6 @@ type FormValues = { username: string; email: string; password: string; - passwordcheck: string; apiError: string; }; @@ -27,6 +27,7 @@ export default function Signup() { }; const signUp: SubmitHandler = async (data) => { + methods.clearErrors(); await fetch("/api/auth/signup", { body: JSON.stringify({ ...data, @@ -48,6 +49,24 @@ export default function Signup() { }); }; + function renderApiError() { + if (!errors.apiError) return; + return ( +
+
+
+
+
+

+ {errors.apiError &&
{errors.apiError?.message}
} +

+
+
+
+ ); + } + return ( <>
@@ -74,6 +93,7 @@ export default function Signup() { state-of-the-art document signing for free.

+ {renderApiError()}