diff --git a/src/api/client.ts b/src/api/client.ts index 5cfda61..561b2f6 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -48,11 +48,16 @@ apiClient.interceptors.request.use(async (config) => { apiClient.interceptors.response.use( (response) => response, (error) => { - if (error.response?.status === 401) { - localStorage.removeItem('token') - window.location.href = '/login' + // Если сервер вернул 401 или ошибку привязки к Telegram (статус 500 с описанием) + const errorDesc = error.response?.data?.error_description || ''; + + if (error.response?.status === 401 || errorDesc.includes('Telegram') || errorDesc.includes('аккаунт не привязан')) { + // Принудительно очищаем токен, чтобы приложение сбросило авторизацию + localStorage.removeItem('token'); + // Можно сразу перенаправить на корень или страницу входа + window.location.href = '/'; } - return Promise.reject(error) + return Promise.reject(error); } )