akveo / akveo/nebular

Token payload returned by onTokenChange is different in getRole of AdminGuard

Aberta
#2,685 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
TypeScript
Estrelas
8.1k
Forks
1.5k
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

```

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.