/
evsedov
/
mpo-main
Обзор
Документация
Войти
/
evsedov
/
mpo-main
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/utils/authAppState.ts
54 строки
1 KB
Evgeniy Sedov
refactor(auth): isolate app resume session handling
18 июл 2026, 11:38
18 июл 2026, 11:38
9a60dc1
Код
Авторство
О чём код?
type AppState = { isActive: boolean; }; type AuthAppStateStore = { isAuthenticated: boolean; authPhone: string; authLogin: string; isSessionExpired: () => boolean; clearAuthState: (options?: { keepWin?: boolean }) => Promise<void>; requirePinLogin: ( identifier?: { phone?: string; login?: string } ) => Promise<void>; touchSession: () => Promise<void>; updateLastActive: () => Promise<void>; }; type AuthAppStateNavigator = { replace: (path: string) => Promise<unknown>; }; export const handleAuthAppStateChange = async ( { isActive }: AppState, authStore: AuthAppStateStore, router: AuthAppStateNavigator ) => { if (!isActive) { await authStore.updateLastActive(); return; } if (!authStore.isAuthenticated) { return; } if (!authStore.isSessionExpired()) { await authStore.touchSession(); return; } const pinIdentifier = { phone: authStore.authPhone, login: authStore.authLogin, }; await authStore.clearAuthState({ keepWin: true }); if (pinIdentifier.phone || pinIdentifier.login) { await authStore.requirePinLogin(pinIdentifier); await router.replace("/pin/login"); return; } await router.replace("/"); };