This is an interface to give the SDK the ability to persist authentication data.
StorageAdapter
Provides functions to read and write to a persistent storage medium.
type
enum
Type of storage.
"standard"
: General-purpose storage."secure"
: Storage suitable for sensitive data.getString(key: key)
: Promise<string | undefined>
Read a string value from persistent storage for the given key.
Returns undefined
if no value could be found.
setString(key: key, value: key)
: Promise
Store a string value to persistent storage for the given key.
If a value already exists for this key, the new value overwrites it.
removeString(key: key)
: Promise
Remove a string value from persistent storage for the given key.
Does not fail if no key to remove was found.
localStorageAdapter
A StorageAdapter
implementation that uses the browser’s localStorage
API.
Available in the @baqhub/sdk-react-dom
package.
import {localStorageAdapter} from "@baqhub/sdk-react-dom";
asyncStorageAdapter
A StorageAdapter
implementation that uses React Native’s AsyncStorage
.
Available in the @baqhub/sdk-react-native
or @baqhub/sdk-expo
packages.
import {asyncStorageAdapter} from "@baqhub/sdk-react-native";
secureStorageAdapter
A secure StorageAdapter
implementation that uses Expo SecureStore.
Available in the @baqhub/sdk-expo
package.
import {secureStorageAdapter} from "@baqhub/sdk-expo";
To use the SDK’s built-in authentication flow, a storage adapter is necessary to persist the user’s entity record, application record, and private key. The various StorageAdapter
implementations make it possible to adapt to different platforms and requirements.
In this example of an Expo React Native app we provide a storage adapter for the SDK to store the records it needs to persist, and a different one to store the user’s private key.
import {buildAuthentication} from "../baq/authentication.js";
import {
asyncStorageAdapter,
secureStorageAdapter,
} from "@baqhub/sdk-expo";
const {useAuthentication} = buildAuthentication({
storage: asyncStorageAdapter,
secureStorage: secureStorageAdapter,
});