Fix auth refresh
This commit is contained in:
@@ -33,12 +33,17 @@ 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) {
|
||||||
|
const url = error.config?.url || ''
|
||||||
|
const isAuthEndpoint = url.includes('/auth/login') || url.includes('/auth/register') || url.includes('/auth/2fa')
|
||||||
|
|
||||||
|
if (!isAuthEndpoint) {
|
||||||
localStorage.removeItem('token')
|
localStorage.removeItem('token')
|
||||||
localStorage.removeItem('user')
|
localStorage.removeItem('user')
|
||||||
window.location.href = '/login'
|
window.location.href = '/login'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Forbidden - check if user is banned
|
// Forbidden - check if user is banned
|
||||||
if (error.response?.status === 403) {
|
if (error.response?.status === 403) {
|
||||||
|
|||||||
Reference in New Issue
Block a user