Permalink
Browse files

feat(authService): Add focus handler to check token expiration

  • Loading branch information...
pfurini committed Oct 27, 2016
1 parent 7ff8978 commit 38381c341cf5174c9e739d96a76c3c0e189cb439
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/authService.js
@@ -142,7 +142,7 @@ export class AuthService {
setTimeout(ttl: number) {
this.clearTimeout();
this.timeoutID = PLATFORM.global.setTimeout(() => {
const expiredTokenHandler = () => {
if (this.config.autoUpdateToken
&& this.authentication.getAccessToken()
&& this.authentication.getRefreshToken()) {
@@ -156,7 +156,14 @@ export class AuthService {
if (this.config.expiredRedirect) {
PLATFORM.location.assign(this.config.expiredRedirect);
}
}, ttl);
};
this.timeoutID = PLATFORM.global.setTimeout(expiredTokenHandler, ttl);
PLATFORM.addEventListener('focus', () => {
if (this.isTokenExpired()) {
expiredTokenHandler();
}
});
}
/**

0 comments on commit 38381c3

Please sign in to comment.