Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Polish: Standardize API calls in FirstRunSetup and SecurityWarning

rcourtman16386fc9d740
diff --git a/frontend-modern/src/components/FirstRunSetup.tsx b/frontend-modern/src/components/FirstRunSetup.tsx
index fc3fb6e6a6..4e8923ec47 100644
--- a/frontend-modern/src/components/FirstRunSetup.tsx
+++ b/frontend-modern/src/components/FirstRunSetup.tsx
@@ -2,7 +2,7 @@ import { Component, createSignal, Show, onMount } from 'solid-js';
import { notificationStore } from '@/stores/notifications';
import { logger } from '@/utils/logger';
import { copyToClipboard } from '@/utils/clipboard';
-import { clearAuth as clearApiClientAuth, setApiToken as setApiClientToken } from '@/utils/apiClient';
+import { clearAuth as clearApiClientAuth, setApiToken as setApiClientToken, apiFetchJSON } from '@/utils/apiClient';
import { getPulseBaseUrl } from '@/utils/url';
import { SectionHeader } from '@/components/shared/SectionHeader';
import { showTokenReveal } from '@/stores/tokenReveal';
@@ -72,16 +72,13 @@ export const FirstRunSetup: Component<{ force?: boolean; showLegacyBanner?: bool
// Fetch bootstrap token path from API
try {
- const response = await fetch('/api/security/status');
- if (response.ok) {
- const data = await response.json();
- if (data.bootstrapTokenPath) {
- setBootstrapTokenPath(data.bootstrapTokenPath);
- setIsDocker(data.isDocker || false);
- setInContainer(data.inContainer || false);
- setLxcCtid(data.lxcCtid || '');
- setDockerContainerName(data.dockerContainerName || '');
- }
+ const data = await apiFetchJSON<any>('/api/security/status');
+ if (data.bootstrapTokenPath) {
+ setBootstrapTokenPath(data.bootstrapTokenPath);
+ setIsDocker(data.isDocker || false);
+ setInContainer(data.inContainer || false);
+ setLxcCtid(data.lxcCtid || '');
+ setDockerContainerName(data.dockerContainerName || '');
}
} catch (error) {
logger.error('Failed to fetch bootstrap token path:', error);
@@ -113,19 +110,11 @@ export const FirstRunSetup: Component<{ force?: boolean; showLegacyBanner?: bool
setIsValidatingToken(true);
try {
- const response = await fetch('/api/security/validate-bootstrap-token', {
+ await apiFetchJSON('/api/security/validate-bootstrap-token', {
method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- },
body: JSON.stringify({ token: bootstrapToken().trim() }),
});
- if (!response.ok) {
- const error = await response.text();
- throw new Error(error || 'Invalid bootstrap setup token');
- }
-
setIsUnlocked(true);
notificationStore.success('Bootstrap token verified. Continue with setup.');
} catch (error) {
diff --git a/frontend-modern/src/components/SecurityWarning.tsx b/frontend-modern/src/components/SecurityWarning.tsx
index 96635f156f..b135f65d9a 100644
--- a/frontend-modern/src/components/SecurityWarning.tsx
+++ b/frontend-modern/src/components/SecurityWarning.tsx
@@ -65,11 +65,10 @@ export const SecurityWarning: Component = () => {
isPrivateNetwork: data.isPrivateNetwork,
clientIP: data.clientIP,
});
+ } catch (error) {
+ logger.error('Failed to fetch security status:', error);
}
- } catch (error) {
- logger.error('Failed to fetch security status:', error);
- }
- });
+ });
const handleDismiss = (duration: 'day' | 'week' | 'forever') => {
const now = new Date();
@@ -121,8 +120,8 @@ export const SecurityWarning: Component = () => {
<Portal>
<div
class={`fixed top-0 left-0 right-0 z-50 border-b shadow-sm ${status()!.publicAccess && !status()!.hasAuthentication
- ? 'bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800'
- : 'bg-yellow-50 dark:bg-yellow-900/20 border-yellow-200 dark:border-yellow-800'
+ ? 'bg-red-50 dark:bg-red-900/20 border-red-200 dark:border-red-800'
+ : 'bg-yellow-50 dark:bg-yellow-900/20 border-yellow-200 dark:border-yellow-800'
}`}
>
<div class="max-w-7xl mx-auto px-4 py-3">