我正在将keycloak-angular库与Angular 6项目一起使用。
我正在尝试将keycloakLogout(): void {
defer(() => this.keycloakService.logout(config.frontUrl + '/home')).subscribe(() => {
localStorage.removeItem('authenticationToken');
this.accountService.authenticate(null)
});
}
的承诺转换为可观察的结果:
authenticationToken
我的问题是,每当我调用此方法时,{{1}}都不会从localStorage中删除。
有什么主意吗?
正如Trincot所提到的,logout()
重定向,因此在当前页面上不再执行JavaScript代码。
解决方案是删除订阅模式并改用.then()
或async / await模式。
async keycloakLogout() {
await this.keycloakService.logout(config.frontUrl + '/home');
}
onLogout() {
localStorage.removeItem('authenticationToken');
this.accountService.authenticate(null);
this.loginService.keycloakLogout(); // ----> here is the call of the previous method.
}