https://github.com/toyamarinyon/webcrypt-session
WebCrypt stateless session utility using signed and encrypted cookies to store data greatly influenced from @vvo/iron-session.
https://github.com/toyamarinyon/webcrypt-session
cloudflare
Last synced: about 1 month ago
JSON representation
WebCrypt stateless session utility using signed and encrypted cookies to store data greatly influenced from @vvo/iron-session.
- Host: GitHub
- URL: https://github.com/toyamarinyon/webcrypt-session
- Owner: toyamarinyon
- Created: 2022-06-05T05:07:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-11T17:40:55.000Z (about 2 years ago)
- Last Synced: 2025-03-22T10:24:07.580Z (about 1 month ago)
- Topics: cloudflare
- Language: TypeScript
- Homepage: https://webcrypt-session.sat0shi.workers.dev/
- Size: 131 KB
- Stars: 37
- Watchers: 1
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# WebCrypt Session
demo: https://webcrypt-session.sat0shi.workers.dev/
_🛠 Stateless session utility using signed and encrypted cookies to store data. Works with WebCrypt API on Cloudflare Workers._
## Features
- 🧙♂️ **TypeSafe** - Written in 100% TypeScript.
- 📝 **With Scheme** - You can define the session scheme and you can use static typesafty & autocommpletion for the session.
- 🍃 **Light** - No database required. (You don't need to use CloudFlare R2 or CloudFlare DurableObjects)## How to use
See the ./examples for more practical examples.### Install
```bash
pnpm add webcrypt-session
```
```bash
npm i webcrypt-session
```
```bash
yarn add webcrypt-session
```
### Basic Usage
```ts
import { createWebCryptSession } from "webcrypt-session";
import { z } from "zod";const sessionScheme = z.object({
username: z.string(),
});
export default {
async fetch(request: Request): Promise {
const webCryptSession = await createWebCryptSession(
sessionScheme,
request,
{
password: "IF4B#t69!WlX$uS22blaxDvzJJ%$vEh%",
}
);
return new Response(`Hello ${webCryptSession.username}`, {
headers: {
"Set-Cookie": webCryptSession.toHeaderValue(),
},
});
},
};
```# Acknowledgment
This package is greatly influenced by [iron-session](https://github.com/vvo/iron-session) developed by [@vvoyer](https://twitter.com/vvoyer). iron-session is quite cool library that it allows to manage a stateless session.
I'd like to use iron-session on CloudFlare worker, but it could not run it because it requires Node.js runtime.
So, I started to develop a library that it allows to manage a stateless session on Cloudflare Worker, using iron-session's api design and implementation as a reference.