Fix incorrect login fail handling

This commit is contained in:
GW_MC
2025-12-19 21:20:54 +08:00
parent b2b1fbaf65
commit d861e0cd7d

View File

@@ -9,6 +9,7 @@ import { formHook } from '../../providers/FormProvider';
import type { Route } from './+types/login'; import type { Route } from './+types/login';
import { SearchParamKeys } from '../../lib/constants'; import { SearchParamKeys } from '../../lib/constants';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { AxiosError } from 'axios';
const loginFormSchema = v.object({ const loginFormSchema = v.object({
username: v.pipe(v.string(), v.trim(), v.minLength(1, 'Username is required')), username: v.pipe(v.string(), v.trim(), v.minLength(1, 'Username is required')),
@@ -40,7 +41,20 @@ export default function LoginRoute() {
navigate('/'); navigate('/');
}, },
onError: (error) => { onError: (error) => {
if (defaultResponseErrorHandler(error)) return; if (defaultResponseErrorHandler(error, { disableUnauthorizedHandling: true })) return;
if (error instanceof AxiosError && error.status === 401) {
toast.error('Invalid username or password.', {
position: 'top-center',
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: false,
progress: undefined,
theme: 'colored',
});
return;
}
console.error('Login failed:', error); console.error('Login failed:', error);
}, },
}); });
@@ -57,7 +71,7 @@ export default function LoginRoute() {
onSubmit: async ({ value }) => { onSubmit: async ({ value }) => {
toast.dismiss(); toast.dismiss();
return await login({ body: { password: value.password, username: value.username } }); return await login({ body: { password: value.password, username: value.username } }).catch(() => {});
}, },
}); });