🚸 Improve login (#1163)

This commit is contained in:
Patrick Arminio
2024-04-09 16:12:19 +02:00
committed by GitHub
parent 1e9cb5ec28
commit 9523db2f53
2 changed files with 11 additions and 2 deletions

View File

@@ -58,6 +58,7 @@ const useAuth = () => {
user, user,
isLoading, isLoading,
error, error,
resetError: () => setError(null),
} }
} }

View File

@@ -38,7 +38,7 @@ export const Route = createFileRoute("/login")({
function Login() { function Login() {
const [show, setShow] = useBoolean() const [show, setShow] = useBoolean()
const { loginMutation, error } = useAuth() const { loginMutation, error, resetError } = useAuth()
const { const {
register, register,
handleSubmit, handleSubmit,
@@ -53,7 +53,15 @@ function Login() {
}) })
const onSubmit: SubmitHandler<AccessToken> = async (data) => { const onSubmit: SubmitHandler<AccessToken> = async (data) => {
loginMutation.mutate(data) if (isSubmitting) return
resetError()
try {
await loginMutation.mutateAsync(data)
} catch {
// error is handled by useAuth hook
}
} }
return ( return (