This commit is contained in:
Constantin Simonis 2025-03-06 12:52:15 +01:00
commit f547d05f64
No known key found for this signature in database
GPG key ID: 3878FF77C24AF4D2
8 changed files with 78 additions and 104 deletions

View file

@ -1,6 +1,6 @@
import { inject, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { catchError, EMPTY, Observable } from 'rxjs';
import { catchError, EMPTY, Observable, of, switchMap } from 'rxjs';
import { User } from '../model/User';
@Injectable({
@ -23,4 +23,21 @@ export class UserService {
username: username,
});
}
public getOrCreateUser(profile: any): Observable<User> {
console.log(profile);
const id = profile.info.sub;
const username = profile.info.preferred_username;
return this.getUser(id).pipe(
switchMap((user) => {
if (user) {
return of(user);
} else {
return this.createUser(id, username);
}
}),
catchError(() => EMPTY)
);
}
}