Revert on router change check AccessToken

This commit is contained in:
Konstantinos Triantafyllou 2022-04-13 14:20:07 +03:00
parent d9a2f3b0ee
commit bedc28384b
1 changed files with 13 additions and 1 deletions

View File

@ -18,17 +18,29 @@ export class UserManagementService {
private redirectUrl: string = null;
private readonly promise: Promise<User>;
private subscription;
private readonly routerSubscription;
constructor(private http: HttpClient) {
constructor(private http: HttpClient, private router: Router) {
this.promise = new Promise<any>((resolve => {
this.updateUserInfo(resolve);
}));
this.routerSubscription = this.router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
const token = COOKIE.getCookie('AccessToken');
if (!token && this.getUserInfoSubject.getValue() !== null) {
this.getUserInfoSubject.next(null);
}
}
});
}
clearSubscriptions() {
if (this.subscription) {
this.subscription.unsubscribe();
}
if (this.routerSubscription) {
this.routerSubscription.unsubscribe();
}
}
public getUserInfo(subject: boolean = true): Observable<User> {