From 38381c341cf5174c9e739d96a76c3c0e189cb439 Mon Sep 17 00:00:00 2001 From: Paolo Furini Date: Thu, 27 Oct 2016 20:07:01 +0200 Subject: [PATCH] feat(authService): Add focus handler to check token expiration --- src/authService.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/authService.js b/src/authService.js index c65190a..5b574b0 100644 --- a/src/authService.js +++ b/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(); + } + }); } /**