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 { 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user