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 2c10ba4c99..e301ad19cb 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 @@ -119,7 +119,7 @@ export const AUTH_FLOW_STRATEGY = { }, }; -function clearOAuthStorage(storage: OAuthStorage) { +export function clearOAuthStorage(storage: OAuthStorage = oAuthStorage) { const keys = [ 'access_token', 'id_token', diff --git a/npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts index 07dfc84d67..53fba4ed06 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts @@ -4,6 +4,7 @@ import { Store } from '@ngxs/store'; import { OAuthService } from 'angular-oauth2-oidc'; import { of } from 'rxjs'; import { GetAppConfiguration } from '../actions'; +import * as AuthFlowStrategy from '../strategies/auth-flow.strategy'; import { CORE_OPTIONS } from '../tokens/options.token'; import { checkAccessToken, getInitialData, localeInitializer } from '../utils'; import * as environmentUtils from '../utils/environment-utils'; @@ -54,9 +55,9 @@ describe('InitialUtils', () => { test('should call logOut fn of OAuthService when token is valid and current user not found', async () => { const injector = spectator.inject(Injector); const injectorSpy = jest.spyOn(injector, 'get'); - const logOutFn = jest.fn(); + const clearOAuthStorageSpy = jest.spyOn(AuthFlowStrategy, 'clearOAuthStorage'); - injectorSpy.mockReturnValue({ hasValidAccessToken: () => true, logOut: logOutFn }); + injectorSpy.mockReturnValue({ hasValidAccessToken: () => true }); checkAccessToken( { @@ -64,7 +65,7 @@ describe('InitialUtils', () => { } as any, injector, ); - expect(logOutFn).toHaveBeenCalled(); + expect(clearOAuthStorageSpy).toHaveBeenCalled(); }); }); diff --git a/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts index 36e2c22bca..cf35cc3023 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts @@ -7,6 +7,7 @@ import { GetAppConfiguration } from '../actions/config.actions'; import { ABP } from '../models/common'; import { AuthService } from '../services/auth.service'; import { ConfigState } from '../states/config.state'; +import { clearOAuthStorage } from '../strategies/auth-flow.strategy'; import { CORE_OPTIONS } from '../tokens/options.token'; import { getRemoteEnv } from './environment-utils'; import { parseTenantFromUrl } from './multi-tenancy-utils'; @@ -34,7 +35,7 @@ export function getInitialData(injector: Injector) { export function checkAccessToken(store: Store, injector: Injector) { const oAuth = injector.get(OAuthService); if (oAuth.hasValidAccessToken() && !store.selectSnapshot(ConfigState.getDeep('currentUser.id'))) { - oAuth.logOut(); + clearOAuthStorage(); } }