Fix jwt-token
This commit is contained in:
@@ -390,10 +390,8 @@ async function loginLocal(req, res, next) {
|
||||
// Get tenant information from request (set by multi-tenant auth middleware)
|
||||
let tenantId = null;
|
||||
if (req.tenant && req.tenant.id) {
|
||||
console.log('🔧 DEBUG: Looking for tenant with slug:', req.tenant.id);
|
||||
// Find the actual tenant in database
|
||||
const tenant = await Tenant.findOne({ where: { slug: req.tenant.id } });
|
||||
console.log('🔧 DEBUG: Found tenant:', tenant ? { id: tenant.id, slug: tenant.slug } : 'null');
|
||||
if (tenant) {
|
||||
tenantId = tenant.id;
|
||||
}
|
||||
@@ -422,9 +420,7 @@ async function loginLocal(req, res, next) {
|
||||
whereClause[Op.and].push({ tenant_id: null });
|
||||
}
|
||||
|
||||
console.log('🔧 DEBUG: User search whereClause:', JSON.stringify(whereClause, null, 2));
|
||||
const user = await User.findOne({ where: whereClause });
|
||||
console.log('🔧 DEBUG: Found user:', user ? { id: user.id, username: user.username, tenant_id: user.tenant_id } : 'null');
|
||||
|
||||
if (!user) {
|
||||
console.log(`❌ Authentication failed for "${username}" in tenant "${req.tenant?.id}" - User not found`);
|
||||
@@ -434,14 +430,7 @@ async function loginLocal(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
console.log('🔧 DEBUG: Comparing password with hash:', {
|
||||
passwordLength: password.length,
|
||||
hashLength: user.password_hash?.length,
|
||||
hashPrefix: user.password_hash?.substring(0, 10) + '...'
|
||||
});
|
||||
|
||||
const passwordMatch = await bcrypt.compare(password, user.password_hash);
|
||||
console.log('🔧 DEBUG: Password match result:', passwordMatch);
|
||||
|
||||
if (!passwordMatch) {
|
||||
console.log(`❌ Authentication failed for "${username}" in tenant "${req.tenant?.id}" - Invalid password`);
|
||||
|
||||
Reference in New Issue
Block a user