From 7737db5778b442c14ea0bcf8ae10fea9eb79f019 Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 23 Dec 2019 10:18:57 +0000 Subject: [PATCH] [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 --- services/user-management.service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/user-management.service.ts b/services/user-management.service.ts index 6def7a5b..807b1743 100644 --- a/services/user-management.service.ts +++ b/services/user-management.service.ts @@ -11,6 +11,7 @@ import {NavigationEnd, Router} from "@angular/router"; export class UserManagementService { private getUserInfoSubject: BehaviorSubject = new BehaviorSubject(null); + private lock: boolean = false; constructor(private http: HttpClient, private router: Router) { @@ -29,7 +30,8 @@ export class UserManagementService { if (!token) { this.getUserInfoSubject.next(null); } else { - if (this.getUserInfoSubject.getValue() === null) { + if (this.getUserInfoSubject.getValue() === null && !this.lock) { + this.lock = true; this.http.get(url + token).pipe(map(userInfo => { return this.parseUserInfo(userInfo); })).pipe(timeout(2000), catchError(() => { @@ -37,6 +39,7 @@ export class UserManagementService { })).subscribe(user => { if (this.getUserInfoSubject.getValue() === null) { this.getUserInfoSubject.next(user); + this.lock = false; } }); }