From 9413d45a10bf2b6c6781b319bfb72aace3429852 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Mon, 15 Sep 2025 06:27:00 +0200 Subject: [PATCH] Fix jwt-token --- server/tests/middleware/auth.test.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/server/tests/middleware/auth.test.js b/server/tests/middleware/auth.test.js index 87b0007..bc28c24 100644 --- a/server/tests/middleware/auth.test.js +++ b/server/tests/middleware/auth.test.js @@ -93,9 +93,13 @@ describe('Authentication Middleware', () => { const user = await createTestUser({ username: 'testuser', role: 'admin' }); console.log('Created user:', user.toJSON()); // Debug log + // Get the actual string value of the UUID + const userId = user.getDataValue('id') || user.id; + console.log('User ID for JWT:', userId, typeof userId); + const token = jwt.sign( { - userId: user.id, // Use the UUID directly + userId: userId, username: user.username, role: user.role, email: user.email @@ -113,7 +117,7 @@ describe('Authentication Middleware', () => { await authenticateToken(req, res, next); expect(req.user).to.exist; - expect(req.user.id).to.equal(user.id); + expect(req.user.id).to.equal(userId); expect(req.user.username).to.equal(user.username); expect(req.user.role).to.equal(user.role); expect(next.errors).to.have.length(0); @@ -122,9 +126,13 @@ describe('Authentication Middleware', () => { it('should handle token with tenantId', async () => { const tenant = await createTestTenant({ slug: 'test-tenant' }); const user = await createTestUser({ username: 'testuser', tenant_id: tenant.id }); + + // Get the actual string value of the UUID + const userId = user.getDataValue('id') || user.id; + const token = jwt.sign( { - userId: user.id.toString(), // Convert UUID to string + userId: userId, username: user.username, role: user.role, tenantId: tenant.slug @@ -172,8 +180,15 @@ describe('Authentication Middleware', () => { username: 'inactive', is_active: false }); + + // Get the actual string value of the UUID + const userId = user.getDataValue('id') || user.id; + const token = jwt.sign( - { userId: user.id.toString(), username: user.username }, // Convert UUID to string + { + userId: userId, + username: user.username + }, process.env.JWT_SECRET || 'test-secret', { expiresIn: '1h' } );