@antaja/edge-iron

1.0.16 • Public • Published

@antaja/edge-iron

A fork from @wunderwerk/edge-iron with merge code to reduce dependencies.

Edge-Runtime compatible port of @hapi/iron. Run well on Cloudflare Pages/Workers, Vercel and browser.

License

MIT license

  • Credits to hapi.dev for the initial implementation and
  • Credits to @wunderwerk/edge-iron for porting to Edge-runtime.
  • Credit to Timkieu for fixing bugs by nodejs runtime.

Install

pnpm i @antaja/edge-iron

npm i @antaja/edge-iron

yarn add @antaja/edge-iron

Example

import {Iron} from '@antaja/edge-iron';

// ironPassword must only live on the server-side: Sveltkit/Remix/Nextjs or Backend API
// ironPassword should be changed after a period to reduce leakage.
export async function session2cookie(session: SessionSandbox, ironPassword: string): Promise<string | undefined> {
  const sealed = await Iron.seal(session, ironPassword, Iron.defaults);
  return sealed;
}

export async function cookie2session(cookie: string, ironPassword: string): Promise<SessionSandbox | undefined> {
  const unsealed = await Iron.unseal(cookie, ironPassword, Iron.defaults);
  return unsealed;
}

/@antaja/edge-iron/

    Package Sidebar

    Install

    npm i @antaja/edge-iron

    Weekly Downloads

    3

    Version

    1.0.16

    License

    MIT

    Unpacked Size

    17.9 kB

    Total Files

    5

    Last publish

    Collaborators

    • antaja