This commit is contained in:
Constantin Simonis 2025-03-06 11:01:59 +01:00
parent 8b2d8f7e05
commit f797092d38
11 changed files with 226 additions and 216 deletions

View file

@ -1,6 +1,5 @@
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { KeycloakProfile } from 'keycloak-js';
import { catchError, EMPTY, Observable } from 'rxjs';
import { User } from '../model/User';
@ -20,23 +19,8 @@ export class UserService {
public createUser(id: string, username: string): Observable<User> {
return this.http.post<User>('/backend/user', {
keycloakId: id,
authentikId: id,
username: username,
});
}
public async getOrCreateUser(userProfile: KeycloakProfile) {
if (userProfile.id == null) {
return;
}
return await this.getUser(userProfile.id)
.toPromise()
.then(async (user) => {
if (user) {
return user;
}
return await this.createUser(userProfile.id ?? '', userProfile.username ?? '').toPromise();
});
}
}