Skip to content

Commit

Permalink
fix: refresh token expired check issue (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux committed Jul 10, 2020
1 parent 2a70eaf commit c760c08
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sdk/mocha.opts
Expand Up @@ -3,4 +3,5 @@
--require src/index.ts
--recursive
--full-trace
./src/**/*-spec.ts
--timeout 20000
./src/**/*-spec.ts
7 changes: 5 additions & 2 deletions sdk/src/platform/Auth.ts
Expand Up @@ -41,12 +41,15 @@ export default class Auth {

public async setData(newData: AuthData = {}) {
const data = await this.data();

let refreshTokenExpireTime = data.refresh_token_expire_time;
if (newData.refresh_token_expires_in) {
refreshTokenExpireTime = Date.now() + parseInt(newData.refresh_token_expires_in, 10) * 1000;
}
await this._cache.setItem(this._cacheId, {
...data,
...newData,
expire_time: Date.now() + parseInt(newData.expires_in, 10) * 1000,
refresh_token_expire_time: Date.now() + parseInt(newData.refresh_token_expires_in, 10) * 1000,
refresh_token_expire_time: refreshTokenExpireTime,
});
}

Expand Down
3 changes: 2 additions & 1 deletion sdk/src/platform/Platform.ts
Expand Up @@ -401,7 +401,8 @@ export default class Platform extends EventEmitter {

// Perform sanity checks
if (!authData.refresh_token) throw new Error('Refresh token is missing');
if (!this._auth.refreshTokenValid()) throw new Error('Refresh token has expired');
const refreshTokenValid = await this._auth.refreshTokenValid();
if (!refreshTokenValid) throw new Error('Refresh token has expired');
const body: RefreshTokenBody = {
grant_type: 'refresh_token',
refresh_token: authData.refresh_token,
Expand Down

0 comments on commit c760c08

Please sign in to comment.