correction flow 4
This commit is contained in:
parent
791459131b
commit
d368e07e97
2
.env
2
.env
@ -42,3 +42,5 @@ NEXT_PUBLIC_IFRAME_AI_ASSISTANT_URL=https://alma.slm-lab.net
|
||||
|
||||
ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB
|
||||
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
|
||||
LEANTIME_API_KEY=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
|
||||
LEANTIME_API_URL=https://agilite.slm-lab.net
|
||||
@ -83,31 +83,44 @@ export const authOptions: NextAuthOptions = {
|
||||
token.first_name = profile.given_name || '';
|
||||
token.last_name = profile.family_name || '';
|
||||
token.role = profile.groups || [];
|
||||
token.accessToken = account.access_token;
|
||||
token.refreshToken = account.refresh_token;
|
||||
token.accessToken = account.access_token || '';
|
||||
token.refreshToken = account.refresh_token || '';
|
||||
token.accessTokenExpires = account.expires_at ? account.expires_at * 1000 : Date.now() + 60 * 60 * 1000;
|
||||
|
||||
// Create or update Leantime user
|
||||
try {
|
||||
const leantimeResponse = await fetch(`${process.env.LEANTIME_URL}/api/users`, {
|
||||
const leantimeResponse = await fetch(`${process.env.LEANTIME_API_URL}/api/jsonrpc`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'apiKey': process.env.LEANTIME_API_KEY!,
|
||||
'x-api-key': process.env.LEANTIME_API_KEY!,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
firstname: token.first_name,
|
||||
lastname: token.last_name,
|
||||
username: token.username,
|
||||
email: profile.email,
|
||||
role: token.role.includes('admin') ? 'admin' : 'user',
|
||||
method: 'leantime.rpc.Users.Users.addUser',
|
||||
jsonrpc: '2.0',
|
||||
id: 1,
|
||||
params: {
|
||||
values: {
|
||||
firstname: token.first_name,
|
||||
lastname: token.last_name,
|
||||
username: token.username,
|
||||
email: profile.email,
|
||||
role: token.role.includes('admin') ? 'admin' : 'user',
|
||||
password: Math.random().toString(36).slice(-8), // Generate a random password
|
||||
status: 'a', // Active status
|
||||
source: 'keycloak',
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
if (!leantimeResponse.ok) {
|
||||
console.error('Failed to create/update Leantime user:', await leantimeResponse.text());
|
||||
const responseData = await leantimeResponse.json();
|
||||
console.log('Leantime response:', responseData);
|
||||
|
||||
if (!leantimeResponse.ok || !responseData.result) {
|
||||
console.error('Failed to create/update Leantime user:', responseData);
|
||||
} else {
|
||||
console.log('Successfully created/updated Leantime user');
|
||||
console.log('Successfully created/updated Leantime user with ID:', responseData.result);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error creating/updating Leantime user:', error);
|
||||
@ -194,15 +207,27 @@ export const authOptions: NextAuthOptions = {
|
||||
|
||||
// Delete user from Leantime
|
||||
if (token.username) {
|
||||
const leantimeResponse = await fetch(`${process.env.LEANTIME_URL}/api/users/${token.username}`, {
|
||||
method: 'DELETE',
|
||||
const leantimeResponse = await fetch(`${process.env.LEANTIME_API_URL}/api/jsonrpc`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'apiKey': process.env.LEANTIME_API_KEY!,
|
||||
'Content-Type': 'application/json',
|
||||
'x-api-key': process.env.LEANTIME_API_KEY!,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
method: 'leantime.rpc.Users.Users.deleteUser',
|
||||
jsonrpc: '2.0',
|
||||
id: 1,
|
||||
params: {
|
||||
id: token.username
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
if (!leantimeResponse.ok) {
|
||||
console.error('Failed to delete Leantime user:', await leantimeResponse.text());
|
||||
const responseData = await leantimeResponse.json();
|
||||
console.log('Leantime delete response:', responseData);
|
||||
|
||||
if (!leantimeResponse.ok || !responseData.result) {
|
||||
console.error('Failed to delete Leantime user:', responseData);
|
||||
} else {
|
||||
console.log('Successfully deleted Leantime user');
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user