fix: handle expired JWT/token by forcing logout and redirecting to login view with expired message
This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user