diff --git a/projects/common/src/fm/components/app/app.component.ts b/projects/common/src/fm/components/app/app.component.ts index bd0cf8b..6d27f74 100644 --- a/projects/common/src/fm/components/app/app.component.ts +++ b/projects/common/src/fm/components/app/app.component.ts @@ -137,7 +137,17 @@ export class AppComponent implements OnInit, OnDestroy { this.router.navigate(['loggedout'], { queryParams: { redirectTo: this.router.url } }); } } + if(event.type == 'token_received') { + this.store$.dispatch(new commonActions.InitUser()); + } }); + if(this.oauthService$.hasValidAccessToken) { + this.store$.dispatch(new commonActions.InitUser()); + } else { + if(this.oauthService$.getRefreshToken() !=null) { + this.oauthService$.refreshToken(); + } + } } private InstallRouteEventHandler() { diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index 7ae5d46..9daab8f 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -202,12 +202,10 @@ export class AppCommonEffects { console.debug("No valid token, try to refresh"); if(this.oauthService$.getRefreshToken() != null ) { console.debug("We have a refresh token"); - this.oauthService$.refreshToken().then(() => { - this.store$.dispatch(new appCommonActions.InitUser()); - }); + this.oauthService$.refreshToken(); } - } - return of(undefined); + } + return of(undefined); })); diff --git a/projects/common/src/fm/services/auth-guard.service.ts b/projects/common/src/fm/services/auth-guard.service.ts index ccf160b..a8ed09b 100644 --- a/projects/common/src/fm/services/auth-guard.service.ts +++ b/projects/common/src/fm/services/auth-guard.service.ts @@ -41,24 +41,9 @@ export class AuthGuard implements CanActivate, CanLoad, CanActivateChild { return new Promise((resolve) => { if (!this.oauthService.hasValidAccessToken()) { console.debug("No valid token"); - if(this.oauthService.getRefreshToken() != null ) { - console.debug("We have a refresh token"); - this.oauthService.refreshToken().then(() => { - this.store.dispatch(new appCommonActions.InitUser()); - resolve(true); - }).catch(() => { - console.debug("Error refreshing"); - this.oauthService.initCodeFlow(url); - resolve(false); - }) - } else { - console.debug("No refresh token"); - this.oauthService.initCodeFlow(url); - resolve(false); - } - } else { - console.debug("Valid token init user"); - this.store.dispatch(new appCommonActions.InitUser()); + this.oauthService.initCodeFlow(url); + resolve(false); + } else { resolve(true); } }); diff --git a/projects/common/src/fm/services/itemtype.service.ts b/projects/common/src/fm/services/itemtype.service.ts index 96f04c5..598bb96 100644 --- a/projects/common/src/fm/services/itemtype.service.ts +++ b/projects/common/src/fm/services/itemtype.service.ts @@ -55,14 +55,17 @@ export class ItemTypeService { } public load(config:AppConfig): Promise { - - var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/` - return this.httpClient.get(url) - .toPromise() - .then((itemTypes:IItemTypes) => { - this.itemTypes = itemTypes; - //return data; - }) - .catch(error => this.itemTypes = null); + if(this.itemTypes==null) { + var url = `${ config.getConfig("apiEndPoint")}/api/v1/itemtypes/` + return this.httpClient.get(url) + .toPromise() + .then((itemTypes:IItemTypes) => { + this.itemTypes = itemTypes; + //return data; + }) + .catch(error => this.itemTypes = null); + } else { + return new Promise((resolve) => {resolve()}); + } }; }