Fix jwt-token

This commit is contained in:
2025-09-17 20:00:11 +02:00
parent 2881f171ff
commit 86932f5c8e
4 changed files with 39 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
import React, { createContext, useContext, useEffect, useState } from 'react';
import { io } from 'socket.io-client';
import { useAuth } from './AuthContext';
import { useMultiTenantAuth } from './MultiTenantAuthContext';
import toast from 'react-hot-toast';
import APP_CONFIG from '../config/app';
@@ -17,6 +18,7 @@ export const SocketProvider = ({ children }) => {
localStorage.getItem('notificationsEnabled') !== 'false' // Default to enabled
);
const { isAuthenticated } = useAuth();
const { state: { tenant } } = useMultiTenantAuth();
// Mobile notification management
const [notificationCooldown, setNotificationCooldown] = useState(new Map());
@@ -135,6 +137,12 @@ export const SocketProvider = ({ children }) => {
// Join dashboard room for general updates
newSocket.emit('join_dashboard');
// 🔒 SECURITY: Join tenant-specific room for isolated updates
if (tenant) {
newSocket.emit('join_tenant_room', tenant);
console.log(`🔒 Joined tenant room: ${tenant}`);
}
toast.success('Connected to real-time updates');
});
@@ -224,7 +232,7 @@ export const SocketProvider = ({ children }) => {
setConnected(false);
}
}
}, [isAuthenticated]);
}, [isAuthenticated, tenant]);
const joinDeviceRoom = (deviceId) => {
if (socket) {