Browse Source

update: handling `access_token` event changes on multiple tabs

pull/22066/head
sumeyye 1 year ago
parent
commit
a6f5c1b6cd
  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