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

Commit

Permalink
feat(authService): Add focus handler to check token expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurini committed Oct 27, 2016
1 parent 7ff8978 commit 38381c3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/authService.js
Expand Up @@ -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()) {
Expand All @@ -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();
}
});
}

/**
Expand Down

0 comments on commit 38381c3

Please sign in to comment.