parseSignedCookie
import { parseSignedCookie } from "jsr:@ende/http/unstable-signed-cookie";function ยท experimental
function parseSignedCookie(signedCookie: string): stringParses a signed cookie to get its value.
Important: always verify the cookie using verifySignedCookie first.
signedCookie: stringThe signed cookie to parse the value from.
Returns
The parsed cookie.
Example: Usage
import { verifySignedCookie, parseSignedCookie } from "@ende/http/unstable-signed-cookie";
import { getCookies } from "@ende/http/cookie";
const key = await crypto.subtle.generateKey(
{ name: "HMAC", hash: "SHA-256" },
true,
["sign", "verify"],
);
const headers = new Headers({
Cookie: "location=tokyo.37f7481039762eef5cd46669f93c0a3214dfecba7d0cdc0b0dc40036063fb22e",
});
const signedCookie = getCookies(headers)["location"];
if (signedCookie === undefined) throw new Error("Cookie not found");
await verifySignedCookie(signedCookie, key);
const cookie = parseSignedCookie(signedCookie);