From acfbccfe26fd99c0c01453c9b3f3a18ed1237ef4 Mon Sep 17 00:00:00 2001 From: theborakompanioni Date: Fri, 15 Aug 2025 13:42:25 +0200 Subject: [PATCH] fix: use auth store in Logs component --- src/components/Logs.tsx | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/components/Logs.tsx b/src/components/Logs.tsx index 83064c61..87406856 100644 --- a/src/components/Logs.tsx +++ b/src/components/Logs.tsx @@ -1,12 +1,13 @@ import { useState, useCallback, useEffect, useRef } from 'react' import { AlertTriangle, Loader2, RefreshCw, Download } from 'lucide-react' import { useTranslation } from 'react-i18next' +import { useStore } from 'zustand' import { Alert, AlertDescription } from '@/components/ui/alert' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader } from '@/components/ui/card' import { fetchLog } from '@/lib/api/logs' -import { getSession } from '@/lib/session' +import { authStore } from '@/store/authStore' const JMWALLETD_LOG_FILE_NAME = 'jmwalletd_stdout.log' @@ -90,7 +91,7 @@ function LogContent({ content, refresh }: LogContentProps) { className="flex items-center gap-2" > {isLoadingRefresh ? : } - Refresh + {t('global.refresh')} @@ -110,6 +111,7 @@ function LogContent({ content, refresh }: LogContentProps) { } export const Logs = () => { + const authState = useStore(authStore, (state) => state.state) const { t } = useTranslation() const [alert, setAlert] = useState() const [isInitialized, setIsInitialized] = useState(false) @@ -118,8 +120,7 @@ export const Logs = () => { const refresh = useCallback( async (signal: AbortSignal) => { - const session = getSession() - if (!session?.auth?.token) { + if (!authState?.auth?.token) { setAlert({ variant: 'destructive', message: 'No authentication token available. Please login again.', @@ -128,7 +129,7 @@ export const Logs = () => { } return fetchLog({ - token: session.auth.token, + token: authState.auth.token, signal, fileName: JMWALLETD_LOG_FILE_NAME, }) @@ -142,7 +143,7 @@ export const Logs = () => { if (signal.aborted) return // Check if it's a 404 or similar error indicating endpoint doesn't exist - const isEndpointNotFound = e.message.includes('HTTP 404') || e.message.includes('Empty reply') + const isEndpointNotFound = e.message?.includes('HTTP 404') || e.message?.includes('Empty reply') setAlert({ variant: 'default', @@ -153,12 +154,8 @@ export const Logs = () => { }), }) }) - .finally(() => { - if (signal.aborted) return - setIsLoading(false) - }) }, - [t], + [t, authState], ) useEffect(() => {