Skip to content

Instantly share code, notes, and snippets.

@omar2205
Last active March 22, 2023 20:55
Show Gist options
  • Save omar2205/80d815b9cd5e01ba4989a233812887a1 to your computer and use it in GitHub Desktop.
Save omar2205/80d815b9cd5e01ba4989a233812887a1 to your computer and use it in GitHub Desktop.
More than one cookie
import fast, { type Context } from 'https://deno.land/x/fast@3.8.0/mod.ts'
import {
verifySignedCookie,
} from 'https://deno.land/x/squishy_cookies@v1.0.0/mod.ts'
const COOKIE_SECRET = 'super_secret'
const app = fast()
/*
my cookies are like this:
id=1001.KGVXZWNFmmBcGqe0Jobh1kIAtCoMP7ZGCRN03ZHU344.
name=alice.rDHG85KSNLXOwHLWKuK2Oqp1QKSJih36VxEDH8S1Abg.
*/
app.get('/', async (ctx: Context) => {
const h = ctx.request.headers
const id = await verifySignedCookie(h, 'id', COOKIE_SECRET)
const name = await verifySignedCookie(h, 'name', COOKIE_SECRET)
if(!id || !name) return 'no cookies?'
return `You're ${name.split('.')[0]} with ID: ${id.split('.')[0]}`
})
await app.serve({port: 8000})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment