Squishy Cookies 🍪

Easily sign and verify cookies.

Be Careful out there, there are alpha software out there with no guarantee.

Usage

import {
  cookieSign, cookieVerify
  createSignedCookie, verifySignedCookie,
} from 'mod.ts'

const cookie = await cookieSign('hello', 'super_secret')
// hello.gsSaKanhysk-CuNkIJhUWsHItAOcFZbrNNTa95qCfAE.

await cookieVerify('hello.gsSaKanhysk-CuNkIJhUWsHItAOcFZbrNNTa95qCfAE.', 'super_secret')
// true



const { headers, cookie } = await createSignedCookie(
    'id', '1', 'super_secret',
    { httpOnly: true, path: '/' }
)
return new Response(page, { headers })

// or

const headers = new Headers()
headers.append('set-cookie', cookie)


// Verifying a cookie

headers.append('cookie', cookie) // verifySignedCookie will search for 'cookie' header
const userId = await verifySignedCookie(headers, 'id', 'super_secret')
// userId is false if the verification failed or the cookie value