Fix jwt-token
This commit is contained in:
@@ -109,6 +109,7 @@ const MapView = () => {
|
|||||||
const [mapCenter, setMapCenter] = useState([59.3293, 18.0686]); // Default to Stockholm center
|
const [mapCenter, setMapCenter] = useState([59.3293, 18.0686]); // Default to Stockholm center
|
||||||
const [mapZoom, setMapZoom] = useState(10); // Default zoom level
|
const [mapZoom, setMapZoom] = useState(10); // Default zoom level
|
||||||
const [mapBounds, setMapBounds] = useState(null);
|
const [mapBounds, setMapBounds] = useState(null);
|
||||||
|
const [isInitialLoad, setIsInitialLoad] = useState(true); // Track if this is the first load
|
||||||
const [showDroneDetections, setShowDroneDetections] = useState(true);
|
const [showDroneDetections, setShowDroneDetections] = useState(true);
|
||||||
const [droneDetectionHistory, setDroneDetectionHistory] = useState([]);
|
const [droneDetectionHistory, setDroneDetectionHistory] = useState([]);
|
||||||
const { recentDetections, deviceStatus } = useSocket();
|
const { recentDetections, deviceStatus } = useSocket();
|
||||||
@@ -166,6 +167,10 @@ const MapView = () => {
|
|||||||
|
|
||||||
const fetchDevices = async () => {
|
const fetchDevices = async () => {
|
||||||
try {
|
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 response = await api.get('/devices/map');
|
||||||
const deviceData = response.data.data;
|
const deviceData = response.data.data;
|
||||||
|
|
||||||
@@ -192,10 +197,13 @@ const MapView = () => {
|
|||||||
|
|
||||||
setMapBounds(bounds);
|
setMapBounds(bounds);
|
||||||
|
|
||||||
// Set center to the middle of all devices
|
// Only set center on initial load, not on periodic refreshes
|
||||||
const centerLat = (minLat + maxLat) / 2;
|
if (isInitialLoad) {
|
||||||
const centerLon = (minLon + maxLon) / 2;
|
const centerLat = (minLat + maxLat) / 2;
|
||||||
setMapCenter([centerLat, centerLon]);
|
const centerLon = (minLon + maxLon) / 2;
|
||||||
|
setMapCenter([centerLat, centerLon]);
|
||||||
|
setIsInitialLoad(false); // Mark that initial load is complete
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching devices:', error);
|
console.error('Error fetching devices:', error);
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ api.interceptors.request.use(
|
|||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem('token');
|
||||||
if (token) {
|
if (token) {
|
||||||
config.headers.Authorization = `Bearer ${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;
|
return config;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user