Fix auth refresh

This commit is contained in:
2025-12-20 00:43:36 +07:00
parent a77a757317
commit 22385e8742

View File

@@ -33,11 +33,16 @@ function isBanInfo(detail: unknown): detail is BanInfo {
client.interceptors.response.use( client.interceptors.response.use(
(response) => response, (response) => response,
(error: AxiosError<{ detail: string | BanInfo }>) => { (error: AxiosError<{ detail: string | BanInfo }>) => {
// Unauthorized - redirect to login // Unauthorized - redirect to login (but not for auth endpoints)
if (error.response?.status === 401) { if (error.response?.status === 401) {
localStorage.removeItem('token') const url = error.config?.url || ''
localStorage.removeItem('user') const isAuthEndpoint = url.includes('/auth/login') || url.includes('/auth/register') || url.includes('/auth/2fa')
window.location.href = '/login'
if (!isAuthEndpoint) {
localStorage.removeItem('token')
localStorage.removeItem('user')
window.location.href = '/login'
}
} }
// Forbidden - check if user is banned // Forbidden - check if user is banned