akveo / akveo/ngx-admin-bundle-support

After Refresh token request new token doesn't saved/updated in local storage

Open
#79 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
56
Forks
30
PR merge metrics
No merged PRs in 30d

Description

I have Node.js MongoDB Starter Bundle (v04-03-2020)
It use by default NbPasswordAuthStrategy
and
token: {
class: NbAuthOAuth2JWTToken,
key: 'token',
},

For the sake of simlicity i don't write tokens. I think it doesn't matter

Current behavior:
After succesful login, access & refresh tokens successfully stored in local storage in such format:

```
{
createdAt: 1591249154000
name: "nb:auth:oauth2:jwt:token"
ownerStrategyName: "email"
value: "{"expires_in":36,"access_token":"...","refresh_token":"..."}"
}
```
After expiration period i see request to backend (endpoint '/refresh-token')
In backend AuthService.js -> refreshToken(token)
i write console.log(token)

```
{
payload: {
expires_in: 60,
access_token: '...',
refresh_token: '...'
},
token: {
expires_in: 60,
access_token: '...',
refresh_token: '...'
},
ownerStrategyName: 'email',
createdAt: '2020-06-20T05:39:14.000Z',
accessTokenPayload: {
id: '5ed887b084294d5fa87dc6f3',
role: 'user',
iat: 1591249154,
exp: 1591249190
}
}
```
First of all it check token format:

```
if (!token.access_token || !token.refresh_token) {
throw new Error('Invalid token format');
}
```
**And of course it throw Error** (because need to check token.token.access_token)!!!
Ok. I made a little change

```
refreshToken(token) {
token = token.token
if (!token.access_token || !token.refresh_token) {
throw new Error('Invalid token format');
}
```
... **and it's ok**

New token sended to a frontend and I see in a browser console response:

```
{ access_token: "..."
expires_in: 60
refresh_token: "..."}
```
**But in local storage tokens left unchanged!**

_Expected behavior:_
After refresh token request local storage tokens should be updated and this.tokenService.tokenChange() should fired, but its not happend

_Steps to reproduce:_
Just login as user@user.user and after expiration period of time tokens should be updated in local storage

_Other information:_
Ubuntu Server 18.04
npm 6.14.4
node v12.17.0
Chrome 83.0.4103.61 (64)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.