@stacksjs/router
Version:
The Stacks framework router.
27 lines (26 loc) • 1.05 kB
JavaScript
import process from "node:process";
import { createSessionStore } from "@stacksjs/bun-router";
import { EncryptedSessionStore } from "./encrypted-session-store";
export function createStacksSessionStore(config) {
const base = createSessionStore(config);
if (!resolveEncryptionMode(config.encrypt))
return base;
const appKey = config.appKey ?? process.env.APP_KEY;
if (!appKey || appKey.length < 16)
throw Error("[session] createStacksSessionStore: encryption requested but APP_KEY is missing or too short " + "(need \u226516 chars). Either set APP_KEY in env, pass `appKey` in config, or set `encrypt: false` to opt out.");
return new EncryptedSessionStore(base, { appKey });
}
function resolveEncryptionMode(mode) {
if (mode === !0)
return !0;
if (mode === !1)
return !1;
return (process.env.APP_ENV ?? process.env.NODE_ENV ?? "").toLowerCase() === "production";
}
export {
DatabaseSessionStore,
FileSessionStore,
MemorySessionStore,
RedisSessionStore,
createSessionStore
} from "@stacksjs/bun-router";