@antaja/edge-iron
v1.0.16
Published
CloudFlare Edge-Runtime compatible port of @hapi/iron based on a fork of @wunderwerk/edge-iron
Downloads
27
Maintainers
Readme
@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;
}