Browse Source

Merge pull request #19489 from abpframework/issue-19488

Add `LocalStorageListenerService` to logout from other tabs
pull/19565/head
oykuermann 2 years ago
committed by GitHub
parent
commit
26fd3d164d
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  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. 17
      npm/ng-packs/packages/core/src/lib/services/local-storage-listener.service.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 { DEFAULT_DYNAMIC_LAYOUTS } from "./constants";
import { AbpTitleStrategy } from './services/title-strategy.service';
import { LocalStorageListenerService } from './services/local-storage-listener.service';
const standaloneDirectives = [
@ -164,6 +165,12 @@ export class CoreModule {
deps: [LocalizationService],
useFactory: noop,
},
{
provide: APP_INITIALIZER,
multi: true,
deps: [LocalStorageListenerService],
useFactory: noop,
},
{
provide: APP_INITIALIZER,
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 './local-storage.service';
export * from './window.service';
export * from './internet-connection-service'
export * from './internet-connection-service';
export * from './local-storage-listener.service';

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

@ -0,0 +1,17 @@
import { DOCUMENT } from '@angular/common';
import { Injectable, inject } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class LocalStorageListenerService {
protected readonly window = inject(DOCUMENT).defaultView;
constructor() {
this.window.addEventListener('storage', event => {
if (event.key === 'access_token' && event.newValue === null) {
this.window.location.reload();
}
});
}
}
Loading…
Cancel
Save