fix(auth): reduce forced logout

This commit is contained in:
Christian Vidal Wolf
2026-05-26 11:36:11 +02:00
parent 178d34bc45
commit 070da5ad0f
+10 -6
View File
@@ -10,7 +10,7 @@ import { TopBar } from './components/TopBar';
import { ProductDescriptions } from './components/ProductDescriptions'; import { ProductDescriptions } from './components/ProductDescriptions';
import { MatrixView } from './components/MatrixView'; import { MatrixView } from './components/MatrixView';
import { EditPanel } from './components/EditPanel'; import { EditPanel } from './components/EditPanel';
import { getAllSyncedRows, saveRowToSupabase, saveHistoryEntry, deleteHistoryEntry, getHistoryDataForMerge } from './lib/supabase'; import { getAllSyncedRows, saveRowToSupabase, saveHistoryEntry, deleteHistoryEntry, getHistoryDataForMerge, safeFetch } from './lib/supabase';
import { getStoredSession, signOut, type AuthSession } from './lib/auth'; import { getStoredSession, signOut, type AuthSession } from './lib/auth';
import { LoginPage } from './components/LoginPage'; import { LoginPage } from './components/LoginPage';
import { DimensionsView } from './components/DimensionsView'; import { DimensionsView } from './components/DimensionsView';
@@ -124,7 +124,7 @@ export default function App() {
const checkUserStatus = async () => { const checkUserStatus = async () => {
try { try {
const res = await fetch('/api/users-admin', { const res = await safeFetch('/api/users-admin', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
@@ -136,8 +136,12 @@ export default function App() {
if (!isMounted) return; if (!isMounted) return;
if (!res.ok) { if (!res.ok) {
console.warn('[App] Validation check failed, logging out.'); if (res.status === 401 || res.status === 403) {
handleSignOut(); console.warn('[App] Session is no longer valid, logging out.');
handleSignOut();
} else {
console.warn('[App] Validation check temporarily unavailable:', res.status);
}
return; return;
} }
@@ -154,8 +158,8 @@ export default function App() {
// Check immediately on mount/session change // Check immediately on mount/session change
checkUserStatus(); checkUserStatus();
// Check periodically every 5 minutes // Check periodically, but keep it lightweight to avoid interrupting work.
const interval = setInterval(checkUserStatus, 5 * 60 * 1000); const interval = setInterval(checkUserStatus, 30 * 60 * 1000);
return () => { return () => {
isMounted = false; isMounted = false;