Fix jwt-token

This commit is contained in:
2025-09-14 09:38:58 +02:00
parent 5e7a4829e3
commit 81ed8a13eb
3 changed files with 97 additions and 14 deletions

View File

@@ -15,7 +15,7 @@ async function authenticateToken(req, res, next) {
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
const user = await User.findByPk(decoded.userId, {
attributes: ['id', 'username', 'email', 'role', 'is_active']
attributes: ['id', 'username', 'email', 'role', 'is_active', 'tenant_id']
});
if (!user || !user.is_active) {
@@ -26,6 +26,12 @@ async function authenticateToken(req, res, next) {
}
req.user = user;
// Extract tenant info from JWT token if available
if (decoded.tenantId) {
req.tenantId = decoded.tenantId;
}
next();
} catch (error) {
console.error('Token verification error:', error);