Skip to main content

App Local Storage Service

This service allows an app to store data in the browser's localstore.

The local store is treated as a key-value store, with generic method calls, that will serialize and deserialize data as needed.

Code Location

This service is located in library: lib-oga-webui-sharedkernel.

Usage

Below are usage example for the call surface of this service.

Saving Data

Storing a value to the local store, like this:

const _als = inject(AppLocalStorageService);
const keyname = 'auth-token';

const tokenvalue = 'ssdfjhsldfjhlsakjdfslakjdfhslkdjfhszdlkjfhszdjkl';
this._als.SaveValue(keyname, tokenvalue);

The above injects the local store service, and saves a string to it.

Loading Data

Retrieving a value from the store, like this:

const _als = inject(AppLocalStorageService);

const keyname = 'auth-token';

let rr = this._als.GetValue<string>(keyname);

if(!rr || rr === null)
{
  console.log("TokenStorageService-" + this.instanceId + ":getRefreshToken - no token stored.");
}
Deleting Data

Entries are deleted by key name.

const _als = inject(AppLocalStorageService);

const keyname = 'auth-token';

this._als.RemoveKey(keyname);
Get Key List

This will retrieve the list of keys of stored things.

const _als = inject(AppLocalStorageService);

let kl = service.GetKeys();

console.log("Key list is: " + JSON.stringify(kl));