refactor(scanner): finished login stuff for current routes

This commit is contained in:
2026-05-06 12:09:47 -05:00
parent a38e2e0339
commit 12412536d1
9 changed files with 91 additions and 46 deletions

View File

@@ -1,5 +1,7 @@
import { create } from "zustand";
const ONE_HOUR = 1000 * 60 * 60;
type MobileUser = {
id: string;
name: string;
@@ -11,19 +13,40 @@ type MobileUser = {
type AuthState = {
user: MobileUser | null;
isUnlocked: boolean;
lastScanAt: number | null;
setUser: (user: MobileUser) => void;
updateLastScan: () => void;
lock: () => void;
logout: () => void;
shouldLockForIdle: () => boolean;
};
export const useMobileAuthStore = create<AuthState>((set) => ({
export const useMobileAuthStore = create<AuthState>((set, get) => ({
user: null,
isUnlocked: false,
lastScanAt: null,
setUser: (user) => set({ user, isUnlocked: true }),
setUser: (user) =>
set({
user,
isUnlocked: true,
lastScanAt: Date.now(),
}),
updateLastScan: () => set({ lastScanAt: Date.now() }),
lock: () => set({ isUnlocked: false }),
logout: () => set({ user: null, isUnlocked: false }),
logout: () =>
set({
user: null,
isUnlocked: false,
lastScanAt: null,
}),
shouldLockForIdle: () => {
const lastScanAt = get().lastScanAt;
if (!lastScanAt) return true;
return Date.now() - lastScanAt > ONE_HOUR;
},
}));