fix and update

This commit is contained in:
lendry
2026-07-02 00:10:22 +03:00
parent bcdfbc3861
commit 4306d0ce37
11 changed files with 375 additions and 41 deletions

View File

@@ -0,0 +1,35 @@
import { AUTH_USER_CACHE_KEY } from '@/lib/api';
const PIN_IDLE_WATCH_KEY = 'auth:pin-idle-watch-user';
function readCachedUserId(): string | null {
if (typeof window === 'undefined') return null;
const raw = window.localStorage.getItem(AUTH_USER_CACHE_KEY);
if (!raw) return null;
try {
const parsed = JSON.parse(raw) as { id?: string };
return parsed.id ?? null;
} catch {
return null;
}
}
export function markPinIdleWatch(userId?: string | null) {
if (typeof window === 'undefined') return;
const resolvedUserId = userId ?? readCachedUserId();
if (!resolvedUserId) return;
window.localStorage.setItem(PIN_IDLE_WATCH_KEY, resolvedUserId);
}
export function clearPinIdleWatch() {
if (typeof window === 'undefined') return;
window.localStorage.removeItem(PIN_IDLE_WATCH_KEY);
}
export function isPinIdleWatchActive(userId?: string | null) {
if (typeof window === 'undefined') return false;
const stored = window.localStorage.getItem(PIN_IDLE_WATCH_KEY);
if (!stored) return false;
const resolvedUserId = userId ?? readCachedUserId();
return Boolean(resolvedUserId && stored === resolvedUserId);
}