订阅 keycloak 的注销方法不会被调用
Subscription to keycloak's logout method does not get called
我在 Angular 6 项目中使用 keycloak-angular 库。
我正在尝试将 keycloakService.logout()
承诺转换为可观察的:
keycloakLogout(): void {
defer(() => this.keycloakService.logout(config.frontUrl + '/home')).subscribe(() => {
localStorage.removeItem('authenticationToken');
this.accountService.authenticate(null)
});
}
我的问题是,每当我调用此方法时,authenticationToken
都不会从 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.
}
我在 Angular 6 项目中使用 keycloak-angular 库。
我正在尝试将 keycloakService.logout()
承诺转换为可观察的:
keycloakLogout(): void {
defer(() => this.keycloakService.logout(config.frontUrl + '/home')).subscribe(() => {
localStorage.removeItem('authenticationToken');
this.accountService.authenticate(null)
});
}
我的问题是,每当我调用此方法时,authenticationToken
都不会从 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.
}