fix and update
This commit is contained in:
@@ -143,7 +143,7 @@ export default function DataPage() {
|
||||
const status = await fetchAccountDeletionStatus(userId, token);
|
||||
setDeletionStatus(status);
|
||||
} catch {
|
||||
setDeletionStatus(null);
|
||||
// Фоновый сбой gateway не должен сбрасывать уже показанный статус удаления.
|
||||
}
|
||||
}, [isPinLocked, token, userId]);
|
||||
|
||||
|
||||
@@ -19,23 +19,24 @@ export default function HomePage() {
|
||||
const router = useRouter();
|
||||
const { user, token, isPinLocked } = useAuth();
|
||||
const { isReady } = useRequireAuth();
|
||||
const userId = user?.id;
|
||||
const contactLine = [user?.phone, user?.username ?? user?.email].filter(Boolean).join(' · ');
|
||||
const [documents, setDocuments] = useState<UserDocument[]>([]);
|
||||
const [activeDocumentType, setActiveDocumentType] = useState<DocumentTypeCode | null>(null);
|
||||
|
||||
const loadDocuments = useCallback(async () => {
|
||||
if (!user || !token || isPinLocked) return;
|
||||
if (!userId || !token || isPinLocked) return;
|
||||
try {
|
||||
const response = await apiFetch<{ documents?: UserDocument[] }>(`/documents/users/${user.id}`, {}, token);
|
||||
const response = await apiFetch<{ documents?: UserDocument[] }>(`/documents/users/${userId}`, {}, token);
|
||||
setDocuments(response.documents ?? []);
|
||||
} catch {
|
||||
setDocuments([]);
|
||||
// Фоновая ошибка не должна очищать уже показанные документы.
|
||||
}
|
||||
}, [isPinLocked, token, user]);
|
||||
}, [isPinLocked, token, userId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isReady && user && !isPinLocked) void loadDocuments();
|
||||
}, [isPinLocked, isReady, loadDocuments, user]);
|
||||
if (isReady && userId && !isPinLocked) void loadDocuments();
|
||||
}, [isPinLocked, isReady, loadDocuments, userId]);
|
||||
|
||||
const documentsByType = useMemo(() => indexDocumentsByType(documents), [documents]);
|
||||
|
||||
|
||||
@@ -67,6 +67,7 @@ export default function SecurityPage() {
|
||||
const { user, token, refreshProfile } = useAuth();
|
||||
const { isReady } = useRequireAuth();
|
||||
const { showToast } = useToast();
|
||||
const userId = user?.id;
|
||||
const [devices, setDevices] = useState<ActiveDevice[]>([]);
|
||||
const [sessions, setSessions] = useState<ActiveSession[]>([]);
|
||||
const [history, setHistory] = useState<SignInEvent[]>([]);
|
||||
@@ -92,14 +93,14 @@ export default function SecurityPage() {
|
||||
const hasEmailContact = Boolean(user?.email || user?.backupEmail);
|
||||
|
||||
const loadSecurity = useCallback(async () => {
|
||||
if (!user || !token) return;
|
||||
if (!userId || !token) return;
|
||||
setIsSecurityLoading(true);
|
||||
try {
|
||||
const [devicesResponse, sessionsResponse, historyResponse, totpResponse] = await Promise.all([
|
||||
apiFetch<{ devices: ActiveDevice[] }>(`/security/users/${user.id}/devices`, {}, token),
|
||||
apiFetch<{ sessions: ActiveSession[] }>(`/security/users/${user.id}/sessions`, {}, token),
|
||||
apiFetch<{ events: SignInEvent[] }>(`/security/users/${user.id}/sign-in-history`, {}, token),
|
||||
apiFetch<TotpStatusResponse>(`/security/users/${user.id}/totp/status`, {}, token)
|
||||
apiFetch<{ devices: ActiveDevice[] }>(`/security/users/${userId}/devices`, {}, token),
|
||||
apiFetch<{ sessions: ActiveSession[] }>(`/security/users/${userId}/sessions`, {}, token),
|
||||
apiFetch<{ events: SignInEvent[] }>(`/security/users/${userId}/sign-in-history`, {}, token),
|
||||
apiFetch<TotpStatusResponse>(`/security/users/${userId}/totp/status`, {}, token)
|
||||
]);
|
||||
setDevices(devicesResponse.devices ?? []);
|
||||
setSessions(sessionsResponse.sessions ?? []);
|
||||
@@ -107,16 +108,17 @@ export default function SecurityPage() {
|
||||
setCurrentSessionId(window.localStorage.getItem(AUTH_SESSION_KEY));
|
||||
setTotpEnabled(Boolean(totpResponse.isEnabled));
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : 'Не удалось загрузить безопасность');
|
||||
const message = getApiErrorMessage(error, 'Не удалось загрузить безопасность');
|
||||
if (message) showToast(message);
|
||||
} finally {
|
||||
setIsSecurityLoading(false);
|
||||
}
|
||||
}, [showToast, token, user]);
|
||||
}, [showToast, token, userId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isReady || !user) return;
|
||||
if (!isReady || !userId) return;
|
||||
void loadSecurity();
|
||||
}, [isReady, loadSecurity, user]);
|
||||
}, [isReady, loadSecurity, userId]);
|
||||
|
||||
async function revokeSession(sessionId: string) {
|
||||
if (!user || !token) return;
|
||||
|
||||
Reference in New Issue
Block a user