Last active
March 22, 2023 20:55
-
-
Save omar2205/80d815b9cd5e01ba4989a233812887a1 to your computer and use it in GitHub Desktop.
More than one cookie
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fast, { type Context } from 'https://deno.land/x/[email protected]/mod.ts' | |
import { | |
verifySignedCookie, | |
} from 'https://deno.land/x/[email protected]/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