diff --git a/src/app.js b/src/app.js index ddbdda3..fc0c242 100644 --- a/src/app.js +++ b/src/app.js @@ -23,12 +23,8 @@ export class App { loginToggled = false; landingMessage = 'Silakan login untuk mengakses peta'; - constructor(api, i18n, router) { - this.api = api; - this.i18n = i18n; - this.router = router; - let self = this; + checkIfLoggedIn(){ // If the token has expired log the user out if (tokenIsExpired()) { this.isAuthenticated = false; @@ -42,6 +38,19 @@ export class App { this.username = profile.email; } } + } + + constructor(api, i18n, router) { + this.api = api; + this.i18n = i18n; + this.router = router; + let self = this; + self.checkIfLoggedIn(); + document.addEventListener('auth-changed',function(){ + self.checkIfLoggedIn(); + }); + + } diff --git a/src/utils.js b/src/utils.js index 5309bcf..750bc41 100644 --- a/src/utils.js +++ b/src/utils.js @@ -60,6 +60,7 @@ export function handleAuthentication(router) { localStorage.setItem('id_token', authResult.idToken); localStorage.setItem('profile', JSON.stringify(profile)); router.navigate('map'); + document.dispatchEvent(new Event('auth-changed')); }); } else if (err) {