fix and update

This commit is contained in:
lendry
2026-06-30 16:03:33 +03:00
parent 69063c8fba
commit 2eeb928a72
6 changed files with 138 additions and 19 deletions

View File

@@ -7,14 +7,17 @@ import { useAuth } from '@/components/id/auth-provider';
export function useRequireAuth() {
const router = useRouter();
const pathname = usePathname();
const { user, isLoading, isApiReady, isSessionReady, isPinLocked, hasStoredSession } = useAuth();
const { user, isLoading, isApiReady, isSessionReady, isPinLocked, hasStoredSession, token } = useAuth();
const authResolved = !isLoading && isSessionReady;
const isAuthenticated = Boolean(user || isPinLocked);
useEffect(() => {
if (isLoading || !isApiReady || !isSessionReady) return;
if (user || isPinLocked || hasStoredSession) return;
if (!authResolved) return;
if (isAuthenticated || hasStoredSession || token) return;
if (pathname.startsWith('/auth/')) return;
router.replace('/auth/login');
}, [hasStoredSession, isApiReady, isLoading, isPinLocked, isSessionReady, pathname, router, user]);
}, [authResolved, hasStoredSession, isAuthenticated, pathname, router, token]);
return {
user,
@@ -22,6 +25,7 @@ export function useRequireAuth() {
isPinLocked,
isApiReady,
isSessionReady,
isReady: !isLoading && isApiReady && isSessionReady && Boolean(user || isPinLocked || hasStoredSession)
authResolved,
isReady: authResolved && isAuthenticated && isApiReady
};
}