[Library | Trunk]: User Management service: Add a lock to allow only one call for get user info.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57933 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
80a5c6e489
commit
7737db5778
|
@ -11,6 +11,7 @@ import {NavigationEnd, Router} from "@angular/router";
|
||||||
export class UserManagementService {
|
export class UserManagementService {
|
||||||
|
|
||||||
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
||||||
|
private lock: boolean = false;
|
||||||
|
|
||||||
constructor(private http: HttpClient,
|
constructor(private http: HttpClient,
|
||||||
private router: Router) {
|
private router: Router) {
|
||||||
|
@ -29,7 +30,8 @@ export class UserManagementService {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
this.getUserInfoSubject.next(null);
|
this.getUserInfoSubject.next(null);
|
||||||
} else {
|
} else {
|
||||||
if (this.getUserInfoSubject.getValue() === null) {
|
if (this.getUserInfoSubject.getValue() === null && !this.lock) {
|
||||||
|
this.lock = true;
|
||||||
this.http.get<User>(url + token).pipe(map(userInfo => {
|
this.http.get<User>(url + token).pipe(map(userInfo => {
|
||||||
return this.parseUserInfo(userInfo);
|
return this.parseUserInfo(userInfo);
|
||||||
})).pipe(timeout(2000), catchError(() => {
|
})).pipe(timeout(2000), catchError(() => {
|
||||||
|
@ -37,6 +39,7 @@ export class UserManagementService {
|
||||||
})).subscribe(user => {
|
})).subscribe(user => {
|
||||||
if (this.getUserInfoSubject.getValue() === null) {
|
if (this.getUserInfoSubject.getValue() === null) {
|
||||||
this.getUserInfoSubject.next(user);
|
this.getUserInfoSubject.next(user);
|
||||||
|
this.lock = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue