BrowserLocalStorage

The BrowserLocalStorage is the default SessionStorage adapter used by the SessionKit. It is used to persist Session data in the application and utilizes localStorage as the storage medium.

Usage

By default no action is needed to use BrowserLocalStorage, as it is included as the default storage value on the SessionKit.

Anatomy

The entire implementation for this storage adapter is shown below and can be found here in the source code.

export class BrowserLocalStorage implements SessionStorage {
  constructor(readonly keyPrefix: string = "") {}
  async write(key: string, data: string): Promise<void> {
    localStorage.setItem(this.storageKey(key), data)
  }
  async read(key: string): Promise<string | null> {
    return localStorage.getItem(this.storageKey(key))
  }
  async remove(key: string): Promise<void> {
    localStorage.removeItem(this.storageKey(key))
  }
  storageKey(key: string) {
    return `wharf-${this.keyPrefix}-${key}`
  }
}