Browse Source

Merge pull request #22066 from abpframework/issue-18890

Angular - Access token management fixes
pull/22123/head
Yağmur Çelik 1 year ago
committed by GitHub
parent
commit
8097cf7dd2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 10
      npm/ng-packs/packages/core/src/lib/services/local-storage-listener.service.ts

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

@ -1,6 +1,5 @@
import { DOCUMENT } from '@angular/common';
import { Injectable, inject } from '@angular/core';
@Injectable({
providedIn: 'root',
})
@ -9,8 +8,13 @@ export class LocalStorageListenerService {
constructor() {
this.window.addEventListener('storage', event => {
if (event.key === 'access_token' && event.newValue === null) {
this.window.location.reload();
if (event.key === 'access_token') {
const tokenRemoved = event.newValue === null;
const tokenAdded = event.oldValue === null && event.newValue !== null;
if (tokenRemoved || tokenAdded) {
this.window.location.assign('/');
}
}
});
}

Loading…
Cancel
Save