Fix login error vanishing: exclude auth endpoints from 401 interceptor
The global axios 401 interceptor was firing window.location.href = '/login' on every 401 response, including POST /auth/login with wrong credentials. This caused a full page reload to /login, which remounted the entire React tree and reset all LockScreen state (loginError, username, password) before the user could see the error alert. Fix: skip the redirect for /auth/* endpoints, which legitimately return 401 for invalid credentials. The interceptor still redirects to /login for expired sessions on protected API calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
5426657b2e
commit
c4c06be148
@ -13,7 +13,11 @@ api.interceptors.response.use(
|
|||||||
(response) => response,
|
(response) => response,
|
||||||
(error) => {
|
(error) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
window.location.href = '/login';
|
const url = error.config?.url || '';
|
||||||
|
// Don't redirect on auth endpoints — they legitimately return 401
|
||||||
|
if (!url.startsWith('/auth/')) {
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user