@stacksjs/router
Version:
The Stacks framework router.
58 lines (57 loc) • 1.9 kB
TypeScript
import { createSessionStore } from '@stacksjs/bun-router';
import type { RedisClient, SessionConfig, SessionData, SessionStore } from '@stacksjs/bun-router';
// Re-export bun-router's session types so app code only has to
// import from `@stacksjs/router` (one less package boundary to
// learn). Drivers stay accessible by name for callers that want
// to assemble a custom store manually.
export type {
RedisClient,
SessionConfig,
SessionData,
SessionStore,
};
/**
* Build a session store from the Stacks config. Mirrors what
* `mail` / `Jobs` do for their driver registries — call once at
* boot, pass the result into the session middleware.
*
* @example
* ```ts
* // config/session.ts (typical)
* export const session = {
* driver: 'redis',
* ttl: 60 * 60 * 24, // 24h
* cookie: { name: 'sid', httpOnly: true, sameSite: 'lax' },
* redis: { client: useRedis() },
* } satisfies StacksSessionConfig
*
* // Then at boot:
* const store = createStacksSessionStore(session)
* app.use(sessionMiddleware({ store }))
* ```
*/
export declare function createStacksSessionStore(config: StacksSessionConfig): SessionStore<SessionData>;
/**
* Stacks-level session configuration. Extends bun-router's
* {@link SessionConfig} with:
*
* - `encrypt`: opt-in/out of {@link EncryptedSessionStore}
* wrapping (default: `'auto'` — on in production, off in
* dev/test where readability matters more than encryption-
* at-rest)
* - `appKey`: override key for the encryption (defaults to
* `process.env.APP_KEY`)
*
* All other fields pass through to bun-router unchanged.
*/
export declare interface StacksSessionConfig extends SessionConfig {
encrypt?: boolean | 'auto'
appKey?: string
}
export {
DatabaseSessionStore,
FileSessionStore,
MemorySessionStore,
RedisSessionStore,
createSessionStore,
} from '@stacksjs/bun-router';