Browse Source

remove `LocalStorageListenerService` service from `oauth package` and move to the `core package`

pull/19489/head
Sinan997 2 years ago
parent
commit
1dfe79b8bd
  1. 7
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 3
      npm/ng-packs/packages/core/src/lib/services/index.ts
  3. 4
      npm/ng-packs/packages/core/src/lib/services/local-storage-listener.service.ts
  4. 8
      npm/ng-packs/packages/oauth/src/lib/oauth.module.ts
  5. 1
      npm/ng-packs/packages/oauth/src/lib/services/index.ts

7
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -43,6 +43,7 @@ import { AuthErrorFilterService } from './abstracts';
import { DYNAMIC_LAYOUTS_TOKEN } from "./tokens/dynamic-layout.token"; import { DYNAMIC_LAYOUTS_TOKEN } from "./tokens/dynamic-layout.token";
import { DEFAULT_DYNAMIC_LAYOUTS } from "./constants"; import { DEFAULT_DYNAMIC_LAYOUTS } from "./constants";
import { AbpTitleStrategy } from './services/title-strategy.service'; import { AbpTitleStrategy } from './services/title-strategy.service';
import { LocalStorageListenerService } from './services/local-storage-listener.service';
const standaloneDirectives = [ const standaloneDirectives = [
@ -164,6 +165,12 @@ export class CoreModule {
deps: [LocalizationService], deps: [LocalizationService],
useFactory: noop, useFactory: noop,
}, },
{
provide: APP_INITIALIZER,
multi: true,
deps: [LocalStorageListenerService],
useFactory: noop,
},
{ {
provide: APP_INITIALIZER, provide: APP_INITIALIZER,
multi: true, multi: true,

3
npm/ng-packs/packages/core/src/lib/services/index.ts

@ -20,4 +20,5 @@ export * from './subscription.service';
export * from './track-by.service'; export * from './track-by.service';
export * from './local-storage.service'; export * from './local-storage.service';
export * from './window.service'; export * from './window.service';
export * from './internet-connection-service' export * from './internet-connection-service'
export * from './local-storage-listener.service'

4
npm/ng-packs/packages/oauth/src/lib/services/local-storage-listener.service.ts → npm/ng-packs/packages/core/src/lib/services/local-storage-listener.service.ts

@ -1,18 +1,16 @@
import { DOCUMENT } from '@angular/common'; import { DOCUMENT } from '@angular/common';
import { Injectable, inject } from '@angular/core'; import { Injectable, inject } from '@angular/core';
import { OAuthService } from 'angular-oauth2-oidc';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class LocalStorageListenerService { export class LocalStorageListenerService {
protected readonly window = inject(DOCUMENT).defaultView; protected readonly window = inject(DOCUMENT).defaultView;
protected readonly authService = inject(OAuthService);
constructor() { constructor() {
this.window.addEventListener('storage', event => { this.window.addEventListener('storage', event => {
if (event.key === 'access_token' && event.newValue === null) { if (event.key === 'access_token' && event.newValue === null) {
this.authService.logOut(); this.window.location.reload();
} }
}); });
} }

8
npm/ng-packs/packages/oauth/src/lib/oauth.module.ts

@ -13,7 +13,7 @@ import {
noop, noop,
PIPE_TO_LOGIN_FN_KEY, PIPE_TO_LOGIN_FN_KEY,
} from '@abp/ng.core'; } from '@abp/ng.core';
import { AbpOAuthService, LocalStorageListenerService, OAuthErrorFilterService } from './services'; import { AbpOAuthService, OAuthErrorFilterService } from './services';
import { OAuthConfigurationHandler } from './handlers/oauth-configuration.handler'; import { OAuthConfigurationHandler } from './handlers/oauth-configuration.handler';
import { OAuthApiInterceptor } from './interceptors/api.interceptor'; import { OAuthApiInterceptor } from './interceptors/api.interceptor';
import { AbpOAuthGuard, abpOAuthGuard } from './guards/oauth.guard'; import { AbpOAuthGuard, abpOAuthGuard } from './guards/oauth.guard';
@ -64,12 +64,6 @@ export class AbpOAuthModule {
deps: [OAuthConfigurationHandler], deps: [OAuthConfigurationHandler],
useFactory: noop, useFactory: noop,
}, },
{
provide: APP_INITIALIZER,
multi: true,
deps: [LocalStorageListenerService],
useFactory: noop,
},
OAuthModule.forRoot().providers as Provider[], OAuthModule.forRoot().providers as Provider[],
{ provide: OAuthStorage, useClass: AbpLocalStorageService }, { provide: OAuthStorage, useClass: AbpLocalStorageService },
{ provide: AuthErrorFilterService, useExisting: OAuthErrorFilterService }, { provide: AuthErrorFilterService, useExisting: OAuthErrorFilterService },

1
npm/ng-packs/packages/oauth/src/lib/services/index.ts

@ -1,3 +1,2 @@
export * from './oauth.service'; export * from './oauth.service';
export * from './oauth-error-filter.service'; export * from './oauth-error-filter.service';
export * from './local-storage-listener.service';

Loading…
Cancel
Save