Skip to content

Commit 7979107

Browse files
authored
🚸 Improve login (fastapi#1163)
1 parent 3fce294 commit 7979107

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

frontend/src/hooks/useAuth.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const useAuth = () => {
5858
user,
5959
isLoading,
6060
error,
61+
resetError: () => setError(null),
6162
}
6263
}
6364

frontend/src/routes/login.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const Route = createFileRoute("/login")({
3838

3939
function Login() {
4040
const [show, setShow] = useBoolean()
41-
const { loginMutation, error } = useAuth()
41+
const { loginMutation, error, resetError } = useAuth()
4242
const {
4343
register,
4444
handleSubmit,
@@ -53,7 +53,15 @@ function Login() {
5353
})
5454

5555
const onSubmit: SubmitHandler<AccessToken> = async (data) => {
56-
loginMutation.mutate(data)
56+
if (isSubmitting) return
57+
58+
resetError()
59+
60+
try {
61+
await loginMutation.mutateAsync(data)
62+
} catch {
63+
// error is handled by useAuth hook
64+
}
5765
}
5866

5967
return (

0 commit comments

Comments
 (0)