Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep auth status unknown on load failure (#5479)
[._.]/ Adam Eivy00317b764be3
diff --git a/client/src/components/settings/SecurityTab.jsx b/client/src/components/settings/SecurityTab.jsxindex c2d66f314d..0a08fd1177 100644--- a/client/src/components/settings/SecurityTab.jsx+++ b/client/src/components/settings/SecurityTab.jsx@@ -1,6 +1,7 @@-import { useEffect, useState } from 'react';+import { useCallback, useEffect, useState } from 'react';import { Lock, ShieldCheck, ShieldOff } from 'lucide-react';import toast from '../ui/Toast';+import Banner from '../ui/Banner';import FormField from '../ui/FormField';import BrailleSpinner from '../BrailleSpinner';import { getAuthStatus, setAuthPassword, clearAuthPassword } from '../../services/api';@@ -12,7 +13,8 @@ import { getAuthStatus, setAuthPassword, clearAuthPassword } from '../../service// session cookie obtained by /api/auth/login.export function SecurityTab() {const [loading, setLoading] = useState(true);- const [enabled, setEnabled] = useState(false);+ const [enabled, setEnabled] = useState(null);+ const [loadError, setLoadError] = useState(false);const [currentPassword, setCurrentPassword] = useState('');const [newPassword, setNewPassword] = useState('');const [confirmPassword, setConfirmPassword] = useState('');@@ -21,13 +23,26 @@ export function SecurityTab() {const [disablePassword, setDisablePassword] = useState('');const [disabling, setDisabling] = useState(false);- useEffect(() => {+ const loadAuthStatus = useCallback(() => {+ setLoading(true);+ setLoadError(false);+ setEnabled(null);getAuthStatus({ silent: true })- .then((s) => setEnabled(!!s?.enabled))- .catch(() => null)+ .then((status) => {+ if (typeof status?.enabled !== 'boolean') {+ setLoadError(true);+ return;+ }+ setEnabled(status.enabled);+ })+ .catch(() => setLoadError(true)).finally(() => setLoading(false));}, []);+ useEffect(() => {+ loadAuthStatus();+ }, [loadAuthStatus]);+const handleSubmit = async (event) => {event.preventDefault();if (saving) return;@@ -86,6 +101,28 @@ export function SecurityTab() {);}+ if (loadError || enabled === null) {+ return (+ <Banner+ tone="error"+ size="md"+ title="Authentication status unknown"+ role="alert"+ actions={+ <button+ type="button"+ onClick={loadAuthStatus}+ className="min-h-11 px-4 py-2 text-sm font-medium bg-port-error/20 hover:bg-port-error/30 text-port-error rounded transition-colors"+ >+ Retry+ </button>+ }+ >+ PortOS could not confirm whether login protection is enabled. Retry before changing security settings.+ </Banner>+ );+ }+return (<div className="space-y-6"><div className="bg-port-card border border-port-border rounded-lg p-4">diff --git a/client/src/components/settings/SecurityTab.test.jsx b/client/src/components/settings/SecurityTab.test.jsxnew file mode 100644index 0000000000..ab6e470303--- /dev/null+++ b/client/src/components/settings/SecurityTab.test.jsx@@ -0,0 +1,89 @@+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { SecurityTab } from './SecurityTab';+import * as api from '../../services/api';++vi.mock('../../services/api', () => ({+ getAuthStatus: vi.fn(),+ setAuthPassword: vi.fn(),+ clearAuthPassword: vi.fn(),+}));++vi.mock('../ui/Toast', () => ({+ default: {+ success: vi.fn(),+ error: vi.fn(),+ },+}));++describe('SecurityTab', () => {+ beforeEach(() => {+ vi.clearAllMocks();+ });++ afterEach(() => {+ cleanup();+ });++ it('renders the enabled password controls after a valid status response', async () => {+ api.getAuthStatus.mockResolvedValue({ enabled: true });++ render(<SecurityTab />);++ expect(await screen.findByText('Login password enabled')).toBeInTheDocument();+ expect(screen.getByText('Change password')).toBeInTheDocument();+ expect(screen.getByLabelText('Current password')).toBeInTheDocument();+ expect(screen.getByRole('button', { name: 'Disable login' })).toBeInTheDocument();+ expect(screen.queryByText('Set a password')).not.toBeInTheDocument();+ expect(api.getAuthStatus).toHaveBeenCalledWith({ silent: true });+ });++ it('renders the disabled password controls after a valid status response', async () => {+ api.getAuthStatus.mockResolvedValue({ enabled: false });++ render(<SecurityTab />);++ expect(await screen.findByText('Login password disabled')).toBeInTheDocument();+ expect(screen.getByText('Set a password')).toBeInTheDocument();+ expect(screen.getByRole('button', { name: 'Enable login' })).toBeInTheDocument();+ expect(screen.queryByLabelText('Current password')).not.toBeInTheDocument();+ });++ it('keeps both password flows hidden when the status request rejects', async () => {+ api.getAuthStatus.mockRejectedValue(new Error('Server unavailable'));++ render(<SecurityTab />);++ expect(await screen.findByRole('alert')).toHaveTextContent('Authentication status unknown');+ expect(screen.getByRole('button', { name: 'Retry' })).toBeInTheDocument();+ expect(screen.queryByText('Login password disabled')).not.toBeInTheDocument();+ expect(screen.queryByText('Set a password')).not.toBeInTheDocument();+ expect(screen.queryByRole('button', { name: 'Enable login' })).not.toBeInTheDocument();+ });++ it('treats a malformed success payload as an unknown status', async () => {+ api.getAuthStatus.mockResolvedValue({ enabled: 'false' });++ render(<SecurityTab />);++ expect(await screen.findByRole('alert')).toHaveTextContent('Authentication status unknown');+ expect(screen.queryByText('Login password disabled')).not.toBeInTheDocument();+ expect(screen.queryByText('Set a password')).not.toBeInTheDocument();+ expect(screen.queryByRole('button', { name: 'Enable login' })).not.toBeInTheDocument();+ });++ it('retries a failed status load and restores the matching controls', async () => {+ api.getAuthStatus+ .mockRejectedValueOnce(new Error('Server unavailable'))+ .mockResolvedValueOnce({ enabled: true });++ render(<SecurityTab />);++ fireEvent.click(await screen.findByRole('button', { name: 'Retry' }));++ expect(await screen.findByText('Login password enabled')).toBeInTheDocument();+ expect(screen.getByText('Change password')).toBeInTheDocument();+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();+ await waitFor(() => expect(api.getAuthStatus).toHaveBeenCalledTimes(2));+ });+});