Revert on router change check AccessToken
This commit is contained in:
parent
d9a2f3b0ee
commit
bedc28384b
|
@ -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> {
|
||||
|
|
Loading…
Reference in New Issue