Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
fix(authService): actually clear timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
doktordirk committed Jun 5, 2016
1 parent d4e4c28 commit 1a887ab
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/authService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export class AuthService {
*/
authenticated = false;

/**
* The currently set timeout id
*
* @param {Number}
*/
timeout = 0;

/**
* Create an AuthService instance
*
Expand Down Expand Up @@ -76,30 +83,28 @@ export class AuthService {
* @param {Number} ttl Timeout time in ms
*/
setTimeout(ttl) {
PLATFORM.global.setTimeout(this.timeout, ttl);
this.clearTimeout();

this.timeout = PLATFORM.global.setTimeout(() => {
if (this.config.autoUpdateToken
&& this.authentication.getAccessToken()
&& this.authentication.getRefreshToken()) {
this.updateToken();
} else {
this.logout();
}
}, ttl);
}

/**
* Clears the login timeout
*/
clearTimeout() {
PLATFORM.global.clearTimeout(this.timeout);
}

/**
* Clear timout and refresh token or logout
*/
timeout = () => {
this.clearTimeout();

if (this.config.autoUpdateToken
&& this.authentication.getAccessToken()
&& this.authentication.getRefreshToken()) {
this.updateToken();
} else {
this.logout();
if (this.timeout) {
PLATFORM.global.clearTimeout(this.timeout);
}
};
this.timeout = 0;
}

/**
* Stores and analyses the servers responseObject. Sets login status and timeout
Expand Down

0 comments on commit 1a887ab

Please sign in to comment.