Permalink
Browse files

fix(authService): actually clear timeout

  • Loading branch information...
doktordirk committed Jun 5, 2016
1 parent d4e4c28 commit 1a887abf9630848386e13e43bd6af21bc903e220
Showing with 22 additions and 17 deletions.
  1. +22 −17 src/authService.js
@@ -28,6 +28,13 @@ export class AuthService {
*/
authenticated = false;
/**
* The currently set timeout id
*
* @param {Number}
*/
timeout = 0;
/**
* Create an AuthService instance
*
@@ -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

0 comments on commit 1a887ab

Please sign in to comment.