Track authenticated requests
A server-rendered or backend TypeScript application needs authentication state retained between HTTP requests.
Kinde · Type Alias
SessionManager is the Kinde TypeScript SDK interface for storing authentication-session data. Implement it with a key-value store and pass the adapter to SDK authentication methods.
SessionManager is an application-provided storage adapter for the Kinde TypeScript SDK. Implement its asynchronous operations with a key-value store so the SDK can preserve authenticated-session data between requests.
interface SessionManager { getSessionItem(key: string): Promise<unknown>; setSessionItem(key: string, value: unknown): Promise<void>; removeSessionItem(key: string): Promise<void>; destroySession(): Promise<void>; }| Name | Type | Description |
|---|---|---|
key | string | The key used to retrieve, store, or remove session data. |
value | unknown | The session value to store. |
The page specifies asynchronous methods but does not state explicit return types.
import type { SessionManager } from "@kinde/js-utils";
const sessions = new Map<string, unknown>();
const sessionManager: SessionManager = {
async getSessionItem(key) {
return sessions.get(key);
},
async setSessionItem(key, value) {
sessions.set(key, value);
},
async removeSessionItem(key) {
sessions.delete(key);
},
async destroySession() {
sessions.clear();
},
};This in-memory implementation satisfies the SDK contract for reading, writing, deleting, and clearing session data.
A server-rendered or backend TypeScript application needs authentication state retained between HTTP requests.
An application uses Redis, a database, or another external key-value system for session storage.
A small local prototype needs a minimal working adapter without adding an external dependency.
SessionManager is the storage abstraction that lets the SDK track an authenticated session between requests. The application supplies implementations for reading, writing, removing one item, and destroying the session.
Follow-up: What storage can back it? Any key-value store is suitable, provided it implements the required interface methods.
getSessionItem reads a value by key, setSessionItem writes a value, removeSessionItem deletes one key, and destroySession clears the session store. Each operation is asynchronous.
Follow-up: Why make the methods asynchronous? The contract can support remote or otherwise asynchronous session stores instead of only in-memory objects.
The SDK receives the adapter when authentication operations such as login are invoked. For example, the documentation shows kindeClient.login(sessionManager) and uses the adapter to retain session state.
Follow-up: What changes when using a persistent store? The method behavior remains the same, but data can survive process restarts and be shared across application instances.
kindeClient.loginkindeClient.registersession storeSessionManager interface