Sistemato home e keycloak
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user