diff --git a/app/api/users/route.ts b/app/api/users/route.ts index 5eaea69c..0ea8ae01 100644 --- a/app/api/users/route.ts +++ b/app/api/users/route.ts @@ -202,18 +202,17 @@ function validateUsername(username: string): { isValid: boolean; error?: string // Helper function to create user in Leantime async function createLeantimeUser(userData: { + username: string; firstName: string; lastName: string; email: string; - password: string; - roles: string[]; }): Promise<{ success: boolean; error?: string }> { try { - const response = await fetch('https://agilite.slm-lab.net/api/jsonrpc', { + const response = await fetch('https://agilite.slm-lab.net/index.php/api/jsonrpc', { method: 'POST', headers: { 'Content-Type': 'application/json', - 'X-API-Key': process.env.LEANTIME_TOKEN || '', + 'x-api-key': process.env.LEANTIME_API_KEY!, }, body: JSON.stringify({ method: 'leantime.rpc.Users.Users.addUser', @@ -221,38 +220,14 @@ async function createLeantimeUser(userData: { id: 1, params: { values: { - '0': 0, // This will be set by Leantime - '1': userData.lastName, - '2': userData.firstName, - '3': '20', // Default role - '4': '', // profileId - '5': 'a', // status - '6': userData.email, - '7': 0, // twoFAEnabled - '8': 0, // clientId - '9': null, // clientName - '10': '', // jobTitle - '11': '', // jobLevel - '12': '', // department - '13': new Date().toISOString(), // modified - lastname: userData.lastName, firstname: userData.firstName, - role: '20', // Default role - profileId: '', - status: 'a', - username: userData.email, - password: userData.password, - twoFAEnabled: 0, - clientId: 0, - clientName: null, - jobTitle: '', - jobLevel: '', - department: '', - modified: new Date().toISOString(), - createdOn: new Date().toISOString(), + lastname: userData.lastName, + username: userData.username, + email: userData.email, + status: 'active', + role: 'user', // Default role in Leantime + password: Math.random().toString(36).slice(-8), // Generate a random password source: 'keycloak', - notifications: 1, - settings: '{}' } } }) @@ -265,7 +240,7 @@ async function createLeantimeUser(userData: { console.error('Leantime user creation failed:', data); return { success: false, - error: data.error?.message || 'Failed to create user in Leantime' + error: 'Failed to create user in Leantime' }; } @@ -437,11 +412,10 @@ export async function POST(req: Request) { // Create user in Leantime const leantimeResult = await createLeantimeUser({ + username: data.username, firstName: data.firstName, lastName: data.lastName, email: data.email, - password: data.password, - roles: validRoles, }); if (!leantimeResult.success) {