akveo / akveo/nebular

Token payload returned by onTokenChange is different in getRole of AdminGuard

未关闭
#2,685 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
8.1k
派生
1.5k
PR 合并指标
30 天内没有已合并 PR

描述

### Issue type

**I'm submitting a ...**

* [x] bug report
* [ ] feature request

### Issue description

**Current behavior:**
Whenever i logout from my app and then login with a different user in the same browser session, the token payload returned inside the login component differs from the token payload returned in getRole() of the admin guard. In particular, the token in the getRole() calls still holds the value of the previous user token, making the process of implementation of the ACL system impossible.

**Expected behavior:**
The token payload is the same in both login component and getRole() call.

**Steps to reproduce:**
Logout from the app, then login with a different user.

**Related code:**

```
// login.component.ts
this.authService.authenticate(this.strategy, this.user).pipe(
takeUntil(this.unsubscribe$)).subscribe((result: NbAuthResult) => {
this.submitted = false;
if (result.isSuccess()) {
this.messages = result.getMessages();
this.authService.onTokenChange().pipe(
takeUntil(this.unsubscribe$))
.subscribe((token: NbAuthJWTToken) => {
if (token.isValid()) {
let payload: any;
payload = token.getPayload(); // here i get the correct token
this.store.dispatch(AuthActions.loginSuccess());
this.initUserService.initCurrentUser().subscribe();
}
});

// role.provider.ts
getRole(): Observable {
return this.authService.onTokenChange()
.pipe(
map((token: NbAuthJWTToken) => {
const payload = token.getPayload(); // here i get the old value of the token payload
return !!( payload && payload ['role']) ? this.getLowerCaseRoles(payload ['role']) : 'guest';
}),
);
}

```

### Other information:

**npm, node, OS, Browser**
```
OS: Windows (10)
Browser: Chrome/Brave
npm: 6.10.1
node: 12.9.1
```

**Angular, Nebular**
```
Angular: 10.2.3
Nebular: 6.2.1

```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。