Skip to content

Commit

Permalink
fix issue of browserStorage to support multiple storeKey
Browse files Browse the repository at this point in the history
  • Loading branch information
tanguyenvn committed Jan 31, 2024
1 parent 1741ef5 commit 6b97b08
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/openlogin-utils/src/browserStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export class MemoryStore implements IStorage {
}

export class BrowserStorage {
// eslint-disable-next-line no-use-before-define
private static instance: BrowserStorage;
private static instanceMap = new Map<string, BrowserStorage>();

public storage: IStorage;

Expand All @@ -33,7 +32,7 @@ export class BrowserStorage {
}

static getInstance(key: string, storageKey: "session" | "local" = "local"): BrowserStorage {
if (!this.instance) {
if (!this.instanceMap.has(key)) {
let storage: IStorage;
if (storageKey === "local" && storageAvailable("localStorage")) {
storage = window.localStorage;
Expand All @@ -43,9 +42,9 @@ export class BrowserStorage {
storage = new MemoryStore();
}

this.instance = new this(key, storage);
this.instanceMap.set(key, new this(key, storage));
}
return this.instance;
return this.instanceMap.get(key);
}

toJSON(): string {
Expand Down

0 comments on commit 6b97b08

Please sign in to comment.