fix: handle expired JWT/token by forcing logout and redirecting to login view with expired message

This commit is contained in:
2026-05-28 08:13:02 +07:00
parent 29308d756a
commit c2a5857f62
3 changed files with 58 additions and 8 deletions
+14 -1
View File
@@ -1,7 +1,7 @@
import React, { useState, useRef } from 'react';
import { DownloadIcon, UploadIcon } from '../utils/svgs';
const ImportExport = ({ token, onRefreshData }) => {
const ImportExport = ({ token, onRefreshData, onLogout }) => {
const [dragActive, setDragActive] = useState(false);
const [status, setStatus] = useState({ type: '', message: '' });
const fileInputRef = useRef(null);
@@ -130,6 +130,11 @@ const ImportExport = ({ token, onRefreshData }) => {
body: JSON.stringify(payload)
});
if (res.status === 401 || res.status === 403) {
onLogout('Сессия истекла, войдите заново');
return;
}
const data = await res.json();
if (res.ok) {
setStatus({ type: 'success', message: `Импорт завершен! Загружено компаний: ${payload.companies.length}, отделов: ${payload.departments.length}, сотрудников: ${payload.employees.length}` });
@@ -151,6 +156,10 @@ const ImportExport = ({ token, onRefreshData }) => {
const res = await fetch('/api/admin/export', {
headers: { 'Authorization': `Bearer ${token}` }
});
if (res.status === 401 || res.status === 403) {
onLogout('Сессия истекла, войдите заново');
return;
}
if (!res.ok) throw new Error('Ошибка экспорта данных с сервера');
const data = await res.json();
@@ -173,6 +182,10 @@ const ImportExport = ({ token, onRefreshData }) => {
const res = await fetch('/api/admin/export', {
headers: { 'Authorization': `Bearer ${token}` }
});
if (res.status === 401 || res.status === 403) {
onLogout('Сессия истекла, войдите заново');
return;
}
if (!res.ok) throw new Error('Ошибка экспорта данных с сервера');
const data = await res.json();