SDK provides several storages implementation in a single interface that can be used to store temporary token and states.
The following storages are currently available in the SDK by default.
Storage | Browser | Node.js |
---|---|---|
NullStorage | ✔️ | ✔️ |
MemoryStorage | ✔️ | ✔️ |
LocalStorage | ✔️ | ❌ |
FileStorage | ❌ | ✔️ |
CookieStorage | ✔️ | ❌ |
const storage = new SSOfy.LocalStorage();
import { Storage, FileStorage } from "@ssofy/javascript-sdk";
import fs from "fs";
const storagePath = fs.mkdtempSync('/tmp/');
const storage = new FileStorage(storagePath);
// write data
await storage.put(
'my-key',
'some value',
60 // ttl in seconds
);
// read data
const value = await storage.get('my-key');
// delete data
await storage.delete('my-key');
// delete all data
await storage.flushAll();
// cleanup
await storage.cleanup();
Unlike flushAll()
, the cleanup()
function call does not completely remove all data. Instead, it deletes old and expired data from storages that don't have built-in functionality for addressing key expiry cycles (i.e. FileStorage).
You may also build your own custom storage by implementing the Storage Interface.