diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index 0d57399..1553140 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -162,6 +162,25 @@ export class AppCommonEffects { return null; })); + @Effect({ dispatch: false }) + online$: Observable = this.actions$.pipe( + ofType(appCommonActions.ONLINE), + map((action) => { + console.debug("Online: Check token"); + if(!this.oauthService$.hasValidAccessToken()) { + 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()); + }); + } + } + return null; + })); + + + constructor(private actions$: Actions, private store$: Store, private oauthService$: OAuthService, private itemService$: ItemService, private folderService$:FolderService, private userService$: UserService, private router$: Router, private stateSerializerService$:StateSerializerService) { store$.dispatch(new appCommonActions.LoadItemTypes()); }