fix(auth): whitelist /auth/mfa/* and /mfa-setup page in 401 interceptor
axios 401 handler was bouncing the user to /login whenever the forced-setup endpoint returned 401 (expected for invalid/expired setup tokens). That made the /mfa-setup page silently redirect back to /login the moment its useEffect fired — user saw the login form again on /mfa-setup URL.
This commit is contained in:
+7
-3
@@ -12,9 +12,13 @@ api.interceptors.response.use(
|
||||
(error) => {
|
||||
if (error.response && error.response.status === 401) {
|
||||
const url: string = error.config?.url || '';
|
||||
const isAuthCheck = url.includes('/auth/login') || url.includes('/auth/me');
|
||||
const onLoginPage = typeof window !== 'undefined' && window.location.pathname === '/login';
|
||||
if (!isAuthCheck && !onLoginPage && typeof window !== 'undefined') {
|
||||
const isAuthCheck =
|
||||
url.includes('/auth/login') ||
|
||||
url.includes('/auth/me') ||
|
||||
url.includes('/auth/mfa/'); // mfa verify + forced-setup
|
||||
const path = typeof window !== 'undefined' ? window.location.pathname : '';
|
||||
const onAuthPage = path === '/login' || path.startsWith('/mfa-setup');
|
||||
if (!isAuthCheck && !onAuthPage && typeof window !== 'undefined') {
|
||||
window.location.href = '/login';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user