KvSessionStore
@atiproto/kv-oauth-state-store
Implements the SessionStore interface from @atproto/oauth-client using a Cloudflare KV namespace. Persists authenticated sessions so they can be restored across Worker isolate restarts. Serializes DPoP private keys to JWK for storage.
Constructor
typescript
new KvSessionStore(kv: KVNamespace, options?: KvSessionStoreOptions)
| Parameter | Type | Description |
|---|---|---|
| kv | KVNamespace | The Cloudflare KV namespace binding. Bind this in wrangler.jsonc as OAUTH_SESSION_KV. |
| options | KvSessionStoreOptions | See options table below. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
| prefix | string | "oauth_session:" | Key prefix for all KV entries. Change this if you share a KV namespace with other data. |
| ttlSeconds | number | 604800 | Time-to-live in seconds (default: 7 days). Sessions are automatically refreshed on restore(), so the TTL is reset each time a session is accessed. |
Example
typescript
import { KvSessionStore } from "@atiproto/kv-oauth-state-store";new KvSessionStore(env.OAUTH_SESSION_KV, {prefix: "oauth_session:", // defaultttlSeconds: 604800, // default: 7 days});