Fix jwt-token
This commit is contained in:
@@ -36,6 +36,13 @@ const Layout = () => {
|
|||||||
|
|
||||||
// Build navigation based on user permissions
|
// Build navigation based on user permissions
|
||||||
const navigation = React.useMemo(() => {
|
const navigation = React.useMemo(() => {
|
||||||
|
console.log('🔍 Layout navigation recalculating:', {
|
||||||
|
userExists: !!user,
|
||||||
|
userRole: user?.role,
|
||||||
|
canAccessSettings: user?.role ? canAccessSettings(user.role) : false,
|
||||||
|
hasDebugPermission: user?.role ? hasPermission(user.role, 'debug.access') : false
|
||||||
|
});
|
||||||
|
|
||||||
if (!user?.role) {
|
if (!user?.role) {
|
||||||
return baseNavigation; // Return base navigation if user not loaded yet
|
return baseNavigation; // Return base navigation if user not loaded yet
|
||||||
}
|
}
|
||||||
@@ -52,6 +59,7 @@ const Layout = () => {
|
|||||||
nav.push({ name: 'Debug', href: '/debug', icon: BugAntIcon });
|
nav.push({ name: 'Debug', href: '/debug', icon: BugAntIcon });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('✅ Navigation built:', nav.map(n => n.name));
|
||||||
return nav;
|
return nav;
|
||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,16 @@ async function authenticateToken(req, res, next) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
||||||
|
|
||||||
|
// Log what's in the token for debugging
|
||||||
|
console.log('🔍 JWT Token decoded:', {
|
||||||
|
userId: decoded.userId,
|
||||||
|
username: decoded.username,
|
||||||
|
role: decoded.role,
|
||||||
|
tenantId: decoded.tenantId,
|
||||||
|
provider: decoded.provider
|
||||||
|
});
|
||||||
|
|
||||||
const user = await User.findByPk(decoded.userId, {
|
const user = await User.findByPk(decoded.userId, {
|
||||||
attributes: ['id', 'username', 'email', 'role', 'is_active', 'tenant_id']
|
attributes: ['id', 'username', 'email', 'role', 'is_active', 'tenant_id']
|
||||||
});
|
});
|
||||||
@@ -30,6 +40,9 @@ async function authenticateToken(req, res, next) {
|
|||||||
// Extract tenant info from JWT token if available
|
// Extract tenant info from JWT token if available
|
||||||
if (decoded.tenantId) {
|
if (decoded.tenantId) {
|
||||||
req.tenantId = decoded.tenantId;
|
req.tenantId = decoded.tenantId;
|
||||||
|
console.log('✅ Tenant context set:', decoded.tenantId);
|
||||||
|
} else {
|
||||||
|
console.log('⚠️ No tenantId in JWT token');
|
||||||
}
|
}
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|||||||
Reference in New Issue
Block a user