akveo / akveo/nebular

Token payload returned by onTokenChange is different in getRole of AdminGuard

Đang mở
#2,685 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
8.1k
Fork
1.5k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

### 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

```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.