0.0.4 • Published 10 months ago
edgesession v0.0.4
edgesession
A session manager for edge runtime.
Features
- ✅ Strong type safe
- ✅ Support flash (one-time) session
- ✅ Built on the native Web API
- ✅ Minimal implementation
- ✅ Low overhead
- ✅ Framework-agnostic
- ✅ Zero dependency
- ✅ Edge runtime ready
- ✅ Built with Bun
Supported framework/storage
- Next.js (App router) / Vercel KV
- Sveltekit / Cloudflare KV
- Work in progress
- Remix
- Planning. Or you can use Official session manager without type safe future.
- Other framework
- You can write your own adapter by implementing
SessionStore
interface in few minutes (see source code).
- You can write your own adapter by implementing
Basic usage
This library is always used in combination with an adapter. Please refer to each adapter for specific usage.
// session.ts
export const session = new EdgeSession(
new Signature(process.env.SESSION_SECRET as string),
new ADAPTER_SESSIONSTORE_HERE()
);
// session-state.ts
import { SessionState } from "edgesession";
// Persistent session state
export interface UserId extends SessionState<"user_id"> {}
// Flash (one-time) session state
export interface SubmissionResult extends SessionState<"submission_result", "success" | "failed", true> {}
// your-entrypoint.ts
import { session } from "./session";
import { UserId, SubmissionResult } from "./session-state";
export async function getSessionData() {
const res = await session.get<UserId>(cookies(), "user_id");
if (!res.success) return res;
console.log(`user_id => ${res.data}`) // => user_id => xxx-yyy-zzz
// Flash data will be volatile once it's fetched.
const res2 = await session.getFlash<SubmissionResult>(cookies(), "submission_result");
if (!res2.success) return res;
console.log(`submission_result => ${res2.data}`) // => submission_result => success
return { success: true, userId: res.data, submtResult: res2.data }
}
0.0.1-alpha.12
10 months ago
0.0.1-alpha.11
10 months ago
0.0.1-alpha.13
10 months ago
0.0.1-alpha.8
11 months ago
0.0.1-alpha.9
11 months ago
0.0.2-alpha.0
10 months ago
0.0.1
10 months ago
0.0.1-alpha.6
11 months ago
0.0.3
10 months ago
0.0.1-alpha.4
11 months ago
0.0.2
10 months ago
0.0.1-alpha.5
11 months ago
0.0.4-alpha.0
10 months ago
0.0.4
10 months ago
0.0.1-alpha.3
11 months ago
0.0.1-alpha.1
11 months ago
0.0.1-alpha.0
11 months ago