From 9523db2f53f059c761f2bf1180a831f1f8069443 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 9 Apr 2024 16:12:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=B8=20Improve=20login=20(#1163)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/hooks/useAuth.ts | 1 + frontend/src/routes/login.tsx | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/frontend/src/hooks/useAuth.ts b/frontend/src/hooks/useAuth.ts index 786c36c..58d8db7 100644 --- a/frontend/src/hooks/useAuth.ts +++ b/frontend/src/hooks/useAuth.ts @@ -58,6 +58,7 @@ const useAuth = () => { user, isLoading, error, + resetError: () => setError(null), } } diff --git a/frontend/src/routes/login.tsx b/frontend/src/routes/login.tsx index 5e575b9..55db35f 100644 --- a/frontend/src/routes/login.tsx +++ b/frontend/src/routes/login.tsx @@ -38,7 +38,7 @@ export const Route = createFileRoute("/login")({ function Login() { const [show, setShow] = useBoolean() - const { loginMutation, error } = useAuth() + const { loginMutation, error, resetError } = useAuth() const { register, handleSubmit, @@ -53,7 +53,15 @@ function Login() { }) const onSubmit: SubmitHandler = async (data) => { - loginMutation.mutate(data) + if (isSubmitting) return + + resetError() + + try { + await loginMutation.mutateAsync(data) + } catch { + // error is handled by useAuth hook + } } return (