diff --git a/services/userProfile.service.ts b/services/userProfile.service.ts index 56c13c3e..f16bd788 100644 --- a/services/userProfile.service.ts +++ b/services/userProfile.service.ts @@ -21,9 +21,8 @@ export class UserProfile{ }) export class UserProfileService { private subscription; - private readonly getUserProfileSubject: AdvancedAsyncSubject = new AdvancedAsyncSubject(); + private readonly userProfileSubject: AdvancedAsyncSubject = new AdvancedAsyncSubject(); constructor(private http: HttpClient) { - this.updateUserProfile(); } clearSubscriptions() { @@ -34,26 +33,27 @@ export class UserProfileService { } public get user(): UserProfile { - return this.getUserProfileSubject.getValue(); + return this.userProfileSubject.getValue(); } public getUserProfile(): Observable { - return this.getUserProfileSubject.asObservable(); + return this.userProfileSubject.asObservable(); } public setUserProfile(userProfile:UserProfile) { - this.getUserProfileSubject.next(userProfile); + this.userProfileSubject.next(userProfile?userProfile:new UserProfile(false)); } - public updateUserProfile(resolve: Function = null) { + public initUserProfile(resolve: Function = null) { + this.subscription = this.http.get(properties.monitorServiceAPIURL + 'user', CustomOptions.registryOptions()).pipe(map(userProfile => { return userProfile; })).subscribe(user => { - this.getUserProfileSubject.next(user); + this.userProfileSubject.next(user); if (resolve) { resolve(); } }, error => { - this.getUserProfileSubject.next(null); + this.userProfileSubject.next(new UserProfile(false)); if (resolve) { resolve(); }