Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/http/mod.ts>signCookie

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function signCookie
import { signCookie } from "https://deno.land/std@0.212.0/http/mod.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.212.0/http/unstable_signed_cookie.ts";
import { setCookie } from "https://deno.land/std@0.212.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>