wip
This commit is contained in:
parent
33683f565f
commit
f547d05f64
8 changed files with 78 additions and 104 deletions
|
@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue