Fix jwt-token

This commit is contained in:
2025-09-15 06:27:00 +02:00
parent e194d8278a
commit 9413d45a10

View File

@@ -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' }
);