Skip to main content

Session Storage

This guide covers session persistence so users don’t need to re-authenticate on every visit. For the conceptual overview of key sources and persistence, see Key Management. Session State Machine

Built-In Persistence

Configure at SDK initialization. The SDK handles encryption, storage, and retrieval automatically:
const sdk = await PrivacyBoost.create({
  // ... required fields
  persistence: {
    storage: 'localStorage',  // 'localStorage' | 'indexedDb'
    unlock: 'pin',            // 'none' | 'pin' | 'password'
  },
});
With persistence enabled, returning users don’t see wallet popups — the SDK loads stored keys. If unlock is pin or password, authenticate() returns credentialRequired so you can prompt the user. See Authentication — PIN / Password Unlock.

Session State

Check current auth state locally:
if (sdk.auth.isAuthenticated()) {
  console.log('Current MPK:', sdk.auth.getMpk());
} else {
  console.log('No active session');
}

Logout

MethodWhat it doesNext login
clearSession()Clears the auth token but keeps keys in memoryFast — no wallet popups
logout()Clears everything (keys, token, connection)Full re-auth with wallet popups
// Quick re-login (e.g., switching server accounts)
sdk.auth.clearSession();

// Full sign-out
sdk.auth.logout();

Next Steps