From 625cd089a1ffc9471584af068080ef2cea53f0f8 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 1 Sep 2020 12:25:50 +0300 Subject: [PATCH] fix: change configuration of setupAutomaticSilentRefresh method --- .../core/src/lib/strategies/auth-flow.strategy.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts b/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts index 19fa4f509c..eb8dd5b3a2 100644 --- a/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts +++ b/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts @@ -25,7 +25,7 @@ export abstract class AuthFlowStrategy { constructor(protected injector: Injector) { this.store = injector.get(Store); this.oAuthService = injector.get(OAuthService); - this.oAuthConfig = injector.get(Store).selectSnapshot(ConfigState.getDeep('environment.oAuthConfig')); + this.oAuthConfig = this.store.selectSnapshot(ConfigState.getDeep('environment.oAuthConfig')); } async init(): Promise { @@ -41,7 +41,14 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { return super .init() .then(() => this.oAuthService.tryLogin()) - .then(() => this.oAuthService.setupAutomaticSilentRefresh()); + .then(() => { + if (this.oAuthService.hasValidAccessToken() || !this.oAuthService.getRefreshToken()) { + return Promise.resolve(); + } + + return this.oAuthService.refreshToken() as Promise; + }) + .then(() => this.oAuthService.setupAutomaticSilentRefresh({}, 'access_token')); } login() { @@ -88,7 +95,7 @@ export class AuthPasswordFlowStrategy extends AuthFlowStrategy { ) .pipe( tap(() => this.oAuthService.logOut()), - switchMap(() => this.store.dispatch(new GetAppConfiguration())), + switchMap(() => this.store.dispatch(new GetAppConfiguration())), ); }