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