MCPcopy
hub / github.com/authts/oidc-client-ts / WebStorageStateStore

Class WebStorageStateStore

src/WebStorageStateStore.ts:11–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9 * @public
10 */
11export class WebStorageStateStore implements StateStore {
12 private readonly _logger = new Logger("WebStorageStateStore");
13
14 private readonly _store: AsyncStorage | Storage;
15 private readonly _prefix: string;
16
17 public constructor({
18 prefix = "oidc.",
19 store = localStorage,
20 }: { prefix?: string; store?: AsyncStorage | Storage } = {}) {
21 this._store = store;
22 this._prefix = prefix;
23 }
24
25 public async set(key: string, value: string): Promise<void> {
26 this._logger.create(`set('${key}')`);
27
28 key = this._prefix + key;
29 await this._store.setItem(key, value);
30 }
31
32 public async get(key: string): Promise<string | null> {
33 this._logger.create(`get('${key}')`);
34
35 key = this._prefix + key;
36 const item = await this._store.getItem(key);
37 return item;
38 }
39
40 public async remove(key: string): Promise<string | null> {
41 this._logger.create(`remove('${key}')`);
42
43 key = this._prefix + key;
44 const item = await this._store.getItem(key);
45 await this._store.removeItem(key);
46 return item;
47 }
48
49 public async getAllKeys(): Promise<string[]> {
50 this._logger.create("getAllKeys");
51 const len = await this._store.length;
52
53 const keys = [];
54 for (let index = 0; index < len; index++) {
55 const key = await this._store.key(index);
56 if (key && key.indexOf(this._prefix) === 0) {
57 keys.push(key.substr(this._prefix.length));
58 }
59 }
60 return keys;
61 }
62}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…