Sistemato home e keycloak

This commit is contained in:
Lorenzo Sanesi
2026-07-26 00:38:08 +02:00
parent 5855352c8c
commit 8d1a3e0d18
34 changed files with 744 additions and 131 deletions
@@ -8,3 +8,52 @@ export async function findUserByEmail(email: string): Promise<KeycloakUserSummar
const [utente] = response.data;
return utente ? { id: utente.id } : null;
}
export interface KeycloakUserProfile {
id: string;
email: string;
firstName: string;
lastName: string;
}
export async function getUserById(userId: string): Promise<KeycloakUserProfile> {
const response = await keycloakAdminHttp.get<{
id: string;
email?: string;
firstName?: string;
lastName?: string;
}>(`/users/${userId}`);
return {
id: response.data.id,
email: response.data.email ?? '',
firstName: response.data.firstName ?? '',
lastName: response.data.lastName ?? '',
};
}
export interface UpdateUserProfileInput {
email: string;
firstName: string;
lastName: string;
}
// Il realm ha `registrationEmailAsUsername: true`, quindi username ed email
// devono restare sincronizzati: aggiornare l'email senza lo username
// lascerebbe l'utente con un login (username) diverso dalla nuova email.
export async function updateUserProfile(userId: string, input: UpdateUserProfileInput): Promise<void> {
await keycloakAdminHttp.put(`/users/${userId}`, {
email: input.email,
username: input.email,
firstName: input.firstName,
lastName: input.lastName,
});
}
export async function resetUserPassword(userId: string, password: string): Promise<void> {
await keycloakAdminHttp.put(`/users/${userId}/reset-password`, {
type: 'password',
value: password,
temporary: false,
});
}