Fix jwt-token

This commit is contained in:
2025-09-24 05:53:30 +02:00
parent 5d4ee01612
commit f7167a41da

View File

@@ -1,9 +1,10 @@
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { useAuth } from '../contexts/AuthContext'; import { useAuth } from '../contexts/AuthContext';
import { formatDistanceToNow } from 'date-fns'; import { formatDistanceToNow } from 'date-fns';
import api from '../services/api';
const SecurityLogs = () => { const SecurityLogs = () => {
const { user, tenant } = useAuth(); const { user, isAuthenticated } = useAuth();
const [logs, setLogs] = useState([]); const [logs, setLogs] = useState([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState(null); const [error, setError] = useState(null);
@@ -20,10 +21,10 @@ const SecurityLogs = () => {
}); });
useEffect(() => { useEffect(() => {
if (user && tenant) { if (isAuthenticated) {
loadSecurityLogs(); loadSecurityLogs();
} }
}, [user, tenant, filters, pagination.page]); }, [isAuthenticated, filters, pagination.page]);
const loadSecurityLogs = async () => { const loadSecurityLogs = async () => {
setLoading(true); setLoading(true);
@@ -34,18 +35,9 @@ const SecurityLogs = () => {
...filters ...filters
}); });
const response = await fetch(`/api/${tenant.slug}/security-logs?${params}`, { const response = await api.get(`/security-logs?${params}`);
headers: { const data = response.data.data || response.data;
'Authorization': `Bearer ${user.token}`,
'Content-Type': 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
setLogs(data.logs || []); setLogs(data.logs || []);
setPagination(prev => ({ setPagination(prev => ({
...prev, ...prev,
@@ -53,7 +45,7 @@ const SecurityLogs = () => {
})); }));
} catch (err) { } catch (err) {
console.error('Failed to load security logs:', err); console.error('Failed to load security logs:', err);
setError(err.message); setError(err.response?.data?.message || err.message);
} finally { } finally {
setLoading(false); setLoading(false);
} }
@@ -96,7 +88,7 @@ const SecurityLogs = () => {
const totalPages = Math.ceil(pagination.total / pagination.limit); const totalPages = Math.ceil(pagination.total / pagination.limit);
// Don't render if user is not authenticated // Don't render if user is not authenticated
if (!user || !tenant) { if (!isAuthenticated) {
return ( return (
<div className="p-6"> <div className="p-6">
<div className="text-center py-8 text-gray-500"> <div className="text-center py-8 text-gray-500">
@@ -110,7 +102,7 @@ const SecurityLogs = () => {
<div className="p-6"> <div className="p-6">
<div className="mb-6"> <div className="mb-6">
<h1 className="text-3xl font-bold mb-2 text-gray-900">Security Logs</h1> <h1 className="text-3xl font-bold mb-2 text-gray-900">Security Logs</h1>
<p className="text-gray-600">Monitor security events for your tenant: {tenant.name}</p> <p className="text-gray-600">Monitor security events for your account</p>
</div> </div>
{error && ( {error && (