Skip to content

ant-aja/edge-iron

 
 

Repository files navigation

@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;
}

About

A fork of @wunderwerk/edge-iron Edge-Runtime compatible port of @hapi/iron

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%