Skip to content

Commit 6f25ccc

Browse files
author
Jussi Vatjus-Anttila
authored
change logic when token refresh is done (#76)
if token is expired or token not found along with 401 * do not refresh token when /auth/* is url NOTE: This is not yet robust - server should send more clear indicate that token is invalid so it would be more clear for client side what to do. Now client have to decide based on decoded token time (expiration) and statusCode 401 (Unauthorized) .
1 parent de63359 commit 6f25ccc

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "opentmi-jsclient",
3-
"version": "0.8.2",
3+
"version": "0.8.3",
44
"description": "OpenTMI javascript client",
55
"main": "src/index.js",
66
"authors": [

src/transports/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,16 @@ class Transport {
291291
.delay(retryAfterSeconds * 1000)
292292
.then(() => this.request(req));
293293
}
294-
} else if (status === 401 && this._token) {
294+
} else if (status === 401) {
295295
// Unauthorized
296-
if (this._hasTokenExpired()) {
296+
let requireRefresh = false;
297+
if (this._token) {
298+
requireRefresh = this._hasTokenExpired();
299+
} else if (!(_.get(req, 'url', '').startsWith('/auth/'))) {
300+
// @todo server should send some indication that token has expired
301+
requireRefresh = true;
302+
}
303+
if (requireRefresh) {
297304
return this._refreshToken()
298305
.then(() => this.request(req));
299306
}

0 commit comments

Comments
 (0)