Fix jwt-token

This commit is contained in:
2025-09-15 21:48:38 +02:00
parent eb0303dbd7
commit 32339de9eb
5 changed files with 116 additions and 50 deletions

View File

@@ -64,10 +64,17 @@ async function authenticateToken(req, res, next) {
}]
});
if (!user || !user.is_active) {
if (!user) {
return res.status(401).json({
success: false,
message: 'Invalid or inactive user'
message: 'User not found'
});
}
if (!user.is_active) {
return res.status(401).json({
success: false,
message: 'User account is inactive'
});
}
@@ -80,7 +87,8 @@ async function authenticateToken(req, res, next) {
role: user.role,
is_active: user.is_active,
tenant_id: user.tenant_id,
tenant: user.tenant
tenant: user.tenant,
tenantId: tenantId || (user.tenant ? user.tenant.slug : undefined) // Include tenantId in user object
};
// Set tenant context - prefer JWT tenantId, fallback to user's tenant