Fix jwt-token
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user