Skip to content

API reference > @kontsedal/olas-persist > clearPersisted

clearPersisted() function ​

Clear persisted keys. Useful for "log out" flows that want to drop stored state without enumerating consumers. Errors — quota, security exceptions on delete — are routed through the optional onError; a failed enumeration reports under the key '<keys>'.

Scope is never implicit: pass a prefix, or pass all: true to accept that everything the adapter can see goes. With neither, it throws.

ts
await clearPersisted(localStorageAdapter(), { prefix: 'my-app/' })
await clearPersisted(sessionAdapter, { all: true })

An adapter without keys() cannot be enumerated, so the call reports'<keys>' through onError and deletes nothing.

Signature:

typescript
export declare function clearPersisted(storage?: StorageAdapter, options?: ClearPersistedOptions): Promise<void>;

Parameters ​

Parameter

Type

Description

storage

StorageAdapter

(Optional)

options

ClearPersistedOptions

(Optional)

Returns:

Promise<void>

Released under the MIT License.