【发布时间】:2019-05-28 10:34:23
【问题描述】:
我使用 ngx-cookie-service 来存储我的令牌,但是当我单击断开连接时,不会每次都删除 cookie。有时它可以工作,但有时却不行。
有时我只需要重新加载页面以确保删除 cookie,有时它可以正常工作,但它不会将我重定向到登录页面。 我在 localhost 和构建相同的东西中对其进行了测试。 对于我使用 chrome 的浏览器
要设置我的令牌,我使用这个:
setAuth(value, expireTime): void {
this.cookieService.set('id_token', value, expireTime, '../');
}
我正在使用以下代码删除 cookie:
clearCookies(){this.cookieService.deleteAll('../');}
这是我的注销功能:
logOut() {
let path = location.pathname;
if (path.indexOf('/panier') > -1 || path.indexOf('/store') > -1) {
this.setLogout({ value: true });
} else {
this.disconnect().subscribe(res => {
if (res.status == 'success') {
this.setLogout({ value: false })
this.clearCookies();
this.router.navigate(['/login'])
}
})
}
}
【问题讨论】: