fix and update
This commit is contained in:
@@ -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)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user