From 35f5de75bd910bb11d2e9924f32b7de2134174a7 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Thu, 4 Sep 2025 14:18:30 +0000 Subject: [PATCH] fix: store username during login to fix password change 401 error (addresses #396) --- .../src/components/Settings/ChangePasswordModal.tsx | 7 ++----- frontend-modern/src/utils/apiClient.ts | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frontend-modern/src/components/Settings/ChangePasswordModal.tsx b/frontend-modern/src/components/Settings/ChangePasswordModal.tsx index 163fb0bf9..cf3bf015c 100644 --- a/frontend-modern/src/components/Settings/ChangePasswordModal.tsx +++ b/frontend-modern/src/components/Settings/ChangePasswordModal.tsx @@ -13,9 +13,6 @@ export const ChangePasswordModal: Component = (props) const [confirmPassword, setConfirmPassword] = createSignal(''); const [loading, setLoading] = createSignal(false); const [error, setError] = createSignal(''); - - // Debug logging - console.log('ChangePasswordModal rendered, isOpen:', props.isOpen); const handleSubmit = async (e: Event) => { e.preventDefault(); @@ -46,8 +43,8 @@ export const ChangePasswordModal: Component = (props) .find(row => row.startsWith('pulse_csrf=')) ?.split('=')[1]; - // Get the actual username from localStorage or use 'admin' as fallback - const authUser = localStorage.getItem('authUser') || 'admin'; + // Get the actual username from sessionStorage or use 'admin' as fallback + const authUser = sessionStorage.getItem('pulse_auth_user') || 'admin'; const headers: Record = { 'Content-Type': 'application/json', 'Authorization': `Basic ${btoa(`${authUser}:${currentPassword()}`)}`, diff --git a/frontend-modern/src/utils/apiClient.ts b/frontend-modern/src/utils/apiClient.ts index d19211b27..78ebd778e 100644 --- a/frontend-modern/src/utils/apiClient.ts +++ b/frontend-modern/src/utils/apiClient.ts @@ -57,6 +57,9 @@ class ApiClient { type: 'basic', value: this.authHeader })); + + // Also store username for password change functionality + sessionStorage.setItem('pulse_auth_user', username); } // Set API token @@ -75,6 +78,7 @@ class ApiClient { this.authHeader = null; this.apiToken = null; sessionStorage.removeItem('pulse_auth'); + sessionStorage.removeItem('pulse_auth_user'); } // Check if we have any auth configured