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 { 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'
}
});
const response = await api.get(`/security-logs?${params}`);
const data = response.data.data || response.data;
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
}
const data = await response.json();
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 (
<div className="p-6">
<div className="text-center py-8 text-gray-500">
@@ -110,7 +102,7 @@ const SecurityLogs = () => {
<div className="p-6">
<div className="mb-6">
<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>
{error && (