mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 12:35:25 +02:00
fix(auth): reduce forced logout
This commit is contained in:
+10
-6
@@ -10,7 +10,7 @@ import { TopBar } from './components/TopBar';
|
||||
import { ProductDescriptions } from './components/ProductDescriptions';
|
||||
import { MatrixView } from './components/MatrixView';
|
||||
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 { LoginPage } from './components/LoginPage';
|
||||
import { DimensionsView } from './components/DimensionsView';
|
||||
@@ -124,7 +124,7 @@ export default function App() {
|
||||
|
||||
const checkUserStatus = async () => {
|
||||
try {
|
||||
const res = await fetch('/api/users-admin', {
|
||||
const res = await safeFetch('/api/users-admin', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@@ -136,8 +136,12 @@ export default function App() {
|
||||
if (!isMounted) return;
|
||||
|
||||
if (!res.ok) {
|
||||
console.warn('[App] Validation check failed, logging out.');
|
||||
handleSignOut();
|
||||
if (res.status === 401 || res.status === 403) {
|
||||
console.warn('[App] Session is no longer valid, logging out.');
|
||||
handleSignOut();
|
||||
} else {
|
||||
console.warn('[App] Validation check temporarily unavailable:', res.status);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -154,8 +158,8 @@ export default function App() {
|
||||
// Check immediately on mount/session change
|
||||
checkUserStatus();
|
||||
|
||||
// Check periodically every 5 minutes
|
||||
const interval = setInterval(checkUserStatus, 5 * 60 * 1000);
|
||||
// Check periodically, but keep it lightweight to avoid interrupting work.
|
||||
const interval = setInterval(checkUserStatus, 30 * 60 * 1000);
|
||||
|
||||
return () => {
|
||||
isMounted = false;
|
||||
|
||||
Reference in New Issue
Block a user