diff --git a/src/components/app-main/AppMainElement.ts b/src/components/app-main/AppMainElement.ts index e1e3a68..d1078b6 100644 --- a/src/components/app-main/AppMainElement.ts +++ b/src/components/app-main/AppMainElement.ts @@ -124,11 +124,8 @@ class AppMainElement extends HTMLElement { const _modalElement = document.createElement(element); const _divEl = document.createElement("div"); _modalElement.setAttribute("data-target", "app-modal.modalElement"); - _modalElement.setAttribute( - "data-action", - "click:app-main#preventClosing" - ); _divEl.setAttribute("data-target", "app-modal.modalContent"); + _divEl.setAttribute("data-action", "click:app-main#preventClosing"); _divEl.appendChild(_modalElement); return _divEl; }; diff --git a/src/core/store/AuthStore.ts b/src/core/store/AuthStore.ts index af8edf7..fcb84d4 100644 --- a/src/core/store/AuthStore.ts +++ b/src/core/store/AuthStore.ts @@ -1,5 +1,6 @@ import { AppMainElement } from "components/"; import { AppService } from "core/services"; +import { isTrue } from "core/utils"; import { AuthService } from "services/"; class AuthStore { @@ -13,8 +14,10 @@ class AuthStore { private appMain: AppMainElement, private appService: AppService ) { - this.token = localStorage.getItem("token"); + const _token = localStorage.getItem("token"); + if (_token) this.token = _token; this.authService = new AuthService(this.appService); + this.checkToken(_token); } get token(): string { @@ -26,6 +29,7 @@ class AuthStore { set token(token: string) { const { _token } = this; const _changed = token != _token; + console.log(token); if (_changed) { this._token = token; localStorage.setItem("token", token); @@ -41,6 +45,19 @@ class AuthStore { this._userDetails = userDetails; } + checkToken = async (token: string) => { + try { + const response = await this.authService.checkToken({ token }); + if (!(response && response.valid)) { + this.token = null; + this.appMain.routerService.goTo("/token-expired"); + } + } catch (err) { + this.token = null; + this.appMain.routerService.goTo("/token-expired"); + } + }; + userLogin = async (formObject) => { try { const response = await this.authService.login(formObject); diff --git a/src/index.html b/src/index.html index 8cda3af..f3bc4ea 100644 --- a/src/index.html +++ b/src/index.html @@ -7,6 +7,15 @@