fix and update
This commit is contained in:
@@ -12,12 +12,12 @@ interface AvatarAccessResponse {
|
||||
}
|
||||
|
||||
export function useAvatarUrl(userId: string | undefined, hasAvatar: boolean | undefined, token: string | null) {
|
||||
const { isPinLocked, isLoading } = useAuth();
|
||||
const { isPinLocked, isLoading, isApiReady } = useAuth();
|
||||
const [accessUrl, setAccessUrl] = useState<string | null>(null);
|
||||
const [resolvingAccessUrl, setResolvingAccessUrl] = useState(false);
|
||||
|
||||
const refreshAccessUrl = useCallback(async () => {
|
||||
if (!userId || !token || !hasAvatar || isPinLocked || isLoading) {
|
||||
if (!userId || !token || !hasAvatar || isPinLocked || isLoading || !isApiReady) {
|
||||
setAccessUrl(null);
|
||||
setResolvingAccessUrl(false);
|
||||
return;
|
||||
@@ -31,7 +31,7 @@ export function useAvatarUrl(userId: string | undefined, hasAvatar: boolean | un
|
||||
} finally {
|
||||
setResolvingAccessUrl(false);
|
||||
}
|
||||
}, [hasAvatar, isLoading, isPinLocked, token, userId]);
|
||||
}, [hasAvatar, isApiReady, isLoading, isPinLocked, token, userId]);
|
||||
|
||||
useEffect(() => {
|
||||
void refreshAccessUrl();
|
||||
@@ -59,7 +59,7 @@ export function useAvatarUrl(userId: string | undefined, hasAvatar: boolean | un
|
||||
isLoading: isLoadingBlob,
|
||||
hasError
|
||||
} = useResilientBlobUrl(accessUrl, token, {
|
||||
enabled: Boolean(hasAvatar && accessUrl && !isPinLocked && !isLoading),
|
||||
enabled: Boolean(hasAvatar && accessUrl && !isPinLocked && !isLoading && isApiReady),
|
||||
label: `аватар ${userId ?? ''}`.trim()
|
||||
});
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ export function useE2EChat(options: {
|
||||
userId?: string;
|
||||
token?: string | null;
|
||||
}) {
|
||||
const { isLoading } = useAuth();
|
||||
const { isLoading, isApiReady } = useAuth();
|
||||
const isE2E = options.room?.type === 'E2E';
|
||||
const peerUserId = useMemo(
|
||||
() => resolveChatPeerUserId(options.room, options.userId),
|
||||
@@ -65,7 +65,7 @@ export function useE2EChat(options: {
|
||||
const [e2eErrors, setE2eErrors] = useState<Record<string, string>>({});
|
||||
|
||||
useEffect(() => {
|
||||
if (!options.userId || !options.token || isLoading) return;
|
||||
if (!options.userId || !options.token || isLoading || !isApiReady) return;
|
||||
void (async () => {
|
||||
try {
|
||||
const { publicKey } = await ensureE2EKeyPair(options.userId!);
|
||||
@@ -74,7 +74,7 @@ export function useE2EChat(options: {
|
||||
// фоновая инициализация E2E
|
||||
}
|
||||
})();
|
||||
}, [isLoading, options.token, options.userId]);
|
||||
}, [isApiReady, isLoading, options.token, options.userId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isE2E || !peerUserId || !options.token) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
} from '@/lib/api';
|
||||
|
||||
export function useSelectedFamily(enabled = true) {
|
||||
const { user, token, isPinLocked, isLoading } = useAuth();
|
||||
const { user, token, isPinLocked, isLoading, isApiReady } = useAuth();
|
||||
const { selectedGroupId, setSelectedGroupId } = useFamilyOverlay();
|
||||
const [groups, setGroups] = useState<FamilyGroup[]>([]);
|
||||
const [group, setGroup] = useState<FamilyGroup | null>(null);
|
||||
@@ -22,7 +22,7 @@ export function useSelectedFamily(enabled = true) {
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
const accessToken = getAccessToken() ?? token?.trim() ?? null;
|
||||
if (!enabled || !user || !accessToken || isPinLocked || isLoading) {
|
||||
if (!enabled || !user || !accessToken || isPinLocked || isLoading || !isApiReady) {
|
||||
setGroups([]);
|
||||
setGroup(null);
|
||||
setPresenceMembers([]);
|
||||
@@ -62,7 +62,7 @@ export function useSelectedFamily(enabled = true) {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [enabled, isLoading, isPinLocked, selectedGroupId, setSelectedGroupId, token, user]);
|
||||
}, [enabled, isApiReady, isLoading, isPinLocked, selectedGroupId, setSelectedGroupId, token, user]);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
@@ -71,10 +71,10 @@ export function useSelectedFamily(enabled = true) {
|
||||
|
||||
useEffect(() => {
|
||||
const accessToken = getAccessToken() ?? token?.trim() ?? null;
|
||||
if (!enabled || !accessToken || isPinLocked || isLoading || !group) return;
|
||||
if (!enabled || !accessToken || isPinLocked || isLoading || !isApiReady || !group) return;
|
||||
const timer = window.setInterval(() => void refresh(), 25_000);
|
||||
return () => window.clearInterval(timer);
|
||||
}, [enabled, group, isLoading, isPinLocked, refresh, token]);
|
||||
}, [enabled, group, isApiReady, isLoading, isPinLocked, refresh, token]);
|
||||
|
||||
const presenceByUserId = useMemo(
|
||||
() => new Map(presenceMembers.map((member) => [member.userId, member])),
|
||||
|
||||
@@ -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