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)
ParameterTypeDescription
kvKVNamespaceThe Cloudflare KV namespace binding. Bind this in wrangler.jsonc as OAUTH_SESSION_KV.
optionsKvSessionStoreOptionsSee options table below.

Options

OptionTypeDefaultDescription
prefixstring"oauth_session:"Key prefix for all KV entries. Change this if you share a KV namespace with other data.
ttlSecondsnumber604800Time-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:", // default
ttlSeconds: 604800, // default: 7 days
});