diff --git a/fe-admin/src/pages/LoginPage.tsx b/fe-admin/src/pages/LoginPage.tsx index a37c14d..6097c23 100644 --- a/fe-admin/src/pages/LoginPage.tsx +++ b/fe-admin/src/pages/LoginPage.tsx @@ -24,10 +24,18 @@ export function LoginPage() { navigate(redirectTo, { replace: true }) toast.success('Đăng nhập thành công') } catch (err) { - const msg = axios.isAxiosError(err) - ? err.response?.data?.detail ?? err.response?.data?.title ?? err.message - : 'Lỗi kết nối máy chủ' - toast.error(`Đăng nhập thất bại: ${msg}`) + let msg: string + if (axios.isAxiosError(err)) { + if (err.code === 'ERR_NETWORK' || err.message === 'Network Error') { + const apiUrl = (import.meta.env.VITE_API_BASE_URL ?? window.location.origin) + '/api' + msg = `Không thể kết nối ${apiUrl}. Check dev tools F12 → Network. Có thể do cache cũ — thử Ctrl+Shift+R hoặc tab ẩn danh.` + } else { + msg = err.response?.data?.detail ?? err.response?.data?.title ?? err.message + } + } else { + msg = 'Lỗi không xác định' + } + toast.error(`Đăng nhập thất bại: ${msg}`, { duration: 8000 }) } finally { setIsSubmitting(false) } diff --git a/fe-user/src/pages/LoginPage.tsx b/fe-user/src/pages/LoginPage.tsx index 686e368..2a44c32 100644 --- a/fe-user/src/pages/LoginPage.tsx +++ b/fe-user/src/pages/LoginPage.tsx @@ -24,10 +24,18 @@ export function LoginPage() { navigate(redirectTo, { replace: true }) toast.success('Đăng nhập thành công') } catch (err) { - const msg = axios.isAxiosError(err) - ? err.response?.data?.detail ?? err.response?.data?.title ?? err.message - : 'Lỗi kết nối máy chủ' - toast.error(`Đăng nhập thất bại: ${msg}`) + let msg: string + if (axios.isAxiosError(err)) { + if (err.code === 'ERR_NETWORK' || err.message === 'Network Error') { + const apiUrl = (import.meta.env.VITE_API_BASE_URL ?? window.location.origin) + '/api' + msg = `Không thể kết nối ${apiUrl}. Check dev tools F12 → Network. Có thể do cache cũ — thử Ctrl+Shift+R hoặc tab ẩn danh.` + } else { + msg = err.response?.data?.detail ?? err.response?.data?.title ?? err.message + } + } else { + msg = 'Lỗi không xác định' + } + toast.error(`Đăng nhập thất bại: ${msg}`, { duration: 8000 }) } finally { setIsSubmitting(false) }