Fix jwt-token

This commit is contained in:
2025-08-19 03:48:11 +02:00
parent c042eed0e9
commit b7bef2b2bb
2 changed files with 15 additions and 4 deletions

View File

@@ -109,6 +109,7 @@ const MapView = () => {
const [mapCenter, setMapCenter] = useState([59.3293, 18.0686]); // Default to Stockholm center
const [mapZoom, setMapZoom] = useState(10); // Default zoom level
const [mapBounds, setMapBounds] = useState(null);
const [isInitialLoad, setIsInitialLoad] = useState(true); // Track if this is the first load
const [showDroneDetections, setShowDroneDetections] = useState(true);
const [droneDetectionHistory, setDroneDetectionHistory] = useState([]);
const { recentDetections, deviceStatus } = useSocket();
@@ -166,6 +167,10 @@ const MapView = () => {
const fetchDevices = async () => {
try {
// Debug: Check if token exists before making request
const token = localStorage.getItem('token');
console.log('MapView: fetchDevices - Token exists:', !!token, 'Token length:', token?.length);
const response = await api.get('/devices/map');
const deviceData = response.data.data;
@@ -192,10 +197,13 @@ const MapView = () => {
setMapBounds(bounds);
// Set center to the middle of all devices
// Only set center on initial load, not on periodic refreshes
if (isInitialLoad) {
const centerLat = (minLat + maxLat) / 2;
const centerLon = (minLon + maxLon) / 2;
setMapCenter([centerLat, centerLon]);
setIsInitialLoad(false); // Mark that initial load is complete
}
}
} catch (error) {
console.error('Error fetching devices:', error);

View File

@@ -33,6 +33,9 @@ api.interceptors.request.use(
const token = localStorage.getItem('token');
if (token) {
config.headers.Authorization = `Bearer ${token}`;
console.log('🔑 API Request: Token added to', config.url, 'Token length:', token.length);
} else {
console.warn('⚠️ API Request: No token found for', config.url);
}
return config;
},