fix(layout): use authenticated api client for version/upgrade calls

Plain axios was called without the Authorization header, so the
requireAdmin middleware rejected every request with 401. The catch
block set versionError but the error state was also not yet deployed,
leaving the spinner stuck on 'Checking version…' forever.

Switch both axios.get('/api/nixserver/system/version') and
axios.post('/api/nixserver/system/upgrade') to the api client from
../api/client, which automatically attaches Bearer token from
localStorage on every request.
This commit is contained in:
NixReaper
2026-04-11 14:15:48 -05:00
parent 146c17abd8
commit 90dbf94c18
+3 -3
View File
@@ -9,8 +9,8 @@ import {
ChevronDown, ChevronRight, Search, RotateCcw, RefreshCcw, ChevronDown, ChevronRight, Search, RotateCcw, RefreshCcw,
ArrowUpCircle, CheckCircle2, AlertCircle, Loader2 ArrowUpCircle, CheckCircle2, AlertCircle, Loader2
} from 'lucide-react' } from 'lucide-react'
import axios from 'axios'
import { useAuth } from '../contexts/AuthContext' import { useAuth } from '../contexts/AuthContext'
import { api } from '../api/client'
// ─── Nav data ──────────────────────────────────────────────────────────────── // ─── Nav data ────────────────────────────────────────────────────────────────
@@ -468,7 +468,7 @@ export default function Layout() {
const fetchVersion = useCallback(async () => { const fetchVersion = useCallback(async () => {
setVersionError(false) setVersionError(false)
try { try {
const { data } = await axios.get('/api/nixserver/system/version', { timeout: 10_000 }) const { data } = await api.get('/nixserver/system/version', { timeout: 10_000 })
setVersionInfo(data.data) setVersionInfo(data.data)
} catch { } catch {
setVersionError(true) setVersionError(true)
@@ -481,7 +481,7 @@ export default function Layout() {
if (upgradeState === 'confirm') { if (upgradeState === 'confirm') {
setUpgradeState('running') setUpgradeState('running')
try { try {
await axios.post('/api/nixserver/system/upgrade') await api.post('/nixserver/system/upgrade')
setUpgradeState('done') setUpgradeState('done')
} catch { } catch {
setUpgradeState('error') setUpgradeState('error')