From f7167a41da5e220182011f5ab9b3fa328b8c9694 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Wed, 24 Sep 2025 05:53:30 +0200 Subject: [PATCH] Fix jwt-token --- client/src/pages/SecurityLogs.jsx | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/client/src/pages/SecurityLogs.jsx b/client/src/pages/SecurityLogs.jsx index 03e0083..265453c 100644 --- a/client/src/pages/SecurityLogs.jsx +++ b/client/src/pages/SecurityLogs.jsx @@ -1,9 +1,10 @@ import React, { useState, useEffect } from 'react'; import { useAuth } from '../contexts/AuthContext'; import { formatDistanceToNow } from 'date-fns'; +import api from '../services/api'; const SecurityLogs = () => { - const { user, tenant } = useAuth(); + const { user, isAuthenticated } = useAuth(); const [logs, setLogs] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); @@ -20,10 +21,10 @@ const SecurityLogs = () => { }); useEffect(() => { - if (user && tenant) { + if (isAuthenticated) { loadSecurityLogs(); } - }, [user, tenant, filters, pagination.page]); + }, [isAuthenticated, filters, pagination.page]); const loadSecurityLogs = async () => { setLoading(true); @@ -34,18 +35,9 @@ const SecurityLogs = () => { ...filters }); - const response = await fetch(`/api/${tenant.slug}/security-logs?${params}`, { - headers: { - 'Authorization': `Bearer ${user.token}`, - 'Content-Type': 'application/json' - } - }); - - if (!response.ok) { - throw new Error(`HTTP ${response.status}: ${response.statusText}`); - } - - const data = await response.json(); + const response = await api.get(`/security-logs?${params}`); + const data = response.data.data || response.data; + setLogs(data.logs || []); setPagination(prev => ({ ...prev, @@ -53,7 +45,7 @@ const SecurityLogs = () => { })); } catch (err) { console.error('Failed to load security logs:', err); - setError(err.message); + setError(err.response?.data?.message || err.message); } finally { setLoading(false); } @@ -96,7 +88,7 @@ const SecurityLogs = () => { const totalPages = Math.ceil(pagination.total / pagination.limit); // Don't render if user is not authenticated - if (!user || !tenant) { + if (!isAuthenticated) { return (
@@ -110,7 +102,7 @@ const SecurityLogs = () => {

Security Logs

-

Monitor security events for your tenant: {tenant.name}

+

Monitor security events for your account

{error && (