fix and update

This commit is contained in:
lendry
2026-06-30 09:39:35 +03:00
parent 250976ca08
commit 4e98f6bfab
8 changed files with 192 additions and 110 deletions

View File

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