> ## Documentation Index
> Fetch the complete documentation index at: https://docs.privacyboost.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Session Storage

> Session persistence and secure storage patterns

# 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](/sdk/concepts/key-management).

<img className="block dark:hidden" src="https://mintcdn.com/sunnysidelabs/npTSPV0krdyxjvTn/images/sdk/session-state.svg?fit=max&auto=format&n=npTSPV0krdyxjvTn&q=85&s=e33055a8cbeeaac59eec3dd34f72e18e" alt="Session State Machine" width="640" height="320" data-path="images/sdk/session-state.svg" />

<img className="hidden dark:block" src="https://mintcdn.com/sunnysidelabs/npTSPV0krdyxjvTn/images/sdk/session-state-dark.svg?fit=max&auto=format&n=npTSPV0krdyxjvTn&q=85&s=a33b1d8352992c2397a58ffefd9663d6" alt="Session State Machine" width="640" height="320" data-path="images/sdk/session-state-dark.svg" />

## Built-In Persistence

Configure at SDK initialization. The SDK handles encryption, storage, and retrieval automatically:

```typescript theme={null}
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](/sdk/concepts/authentication#pin--password-unlock).

## Session State

Check current auth state locally:

```typescript theme={null}
if (sdk.auth.isAuthenticated()) {
  console.log('Current MPK:', sdk.auth.getMpk());
} else {
  console.log('No active session');
}
```

## Logout

| Method           | What it does                                   | Next login                      |
| ---------------- | ---------------------------------------------- | ------------------------------- |
| `clearSession()` | Clears the auth token but keeps keys in memory | Fast — no wallet popups         |
| `logout()`       | Clears everything (keys, token, connection)    | Full re-auth with wallet popups |

```typescript theme={null}
// Quick re-login (e.g., switching server accounts)
sdk.auth.clearSession();

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

## Next Steps

* [Error Handling](./error-handling) — Error codes, retry patterns, and performance
* [Key Management](/sdk/concepts/key-management) — Key sources, persistence options, and recovery
* [Authentication](/sdk/concepts/authentication) — Auth flow, token providers, and login methods
