Giter Club home page Giter Club logo

webcrypt-session's Introduction

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

pnpm add webcrypt-session
npm i webcrypt-session
yarn add webcrypt-session

Basic Usage

import { createWebCryptSession } from "webcrypt-session";
import { z } from "zod";

const sessionScheme = z.object({
  username: z.string(),
});
export default {
  async fetch(request: Request): Promise<Response> {
    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 developed by @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.

webcrypt-session's People

Contributors

toyamarinyon avatar github-actions[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.