🚸 Improve login (#1163)
This commit is contained in:
@@ -58,6 +58,7 @@ const useAuth = () => {
|
|||||||
user,
|
user,
|
||||||
isLoading,
|
isLoading,
|
||||||
error,
|
error,
|
||||||
|
resetError: () => setError(null),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 (
|
||||||
|
Reference in New Issue
Block a user