fix and update
This commit is contained in:
@@ -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