Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Go to Latest
function signCookie
import { signCookie } from "https://deno.land/std@0.223.0/http/unstable_signed_cookie.ts";

Returns a promise with the signed cookie value from the given cryptographic key.

Examples

Example 1

import { signCookie } from "https://deno.land/std@0.223.0/http/unstable_signed_cookie.ts";
import { setCookie } from "https://deno.land/std@0.223.0/http/cookie.ts";

const key = await crypto.subtle.generateKey(
  { name: "HMAC", hash: "SHA-256" },
  true,
  ["sign", "verify"],
);
const value = await signCookie("my-cookie-value", key);

const headers = new Headers();
setCookie(headers, {
  name: "my-cookie-name",
  value,
});

const cookieHeader = headers.get("set-cookie");

Parameters

value: string

Returns

Promise<string>