Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

std/http/mod.ts>verifyCookie

The Deno Standard Library
Go to Latest
function verifyCookie
import { verifyCookie } from "https://deno.land/std@0.222.1/http/mod.ts";

Returns a promise of a boolean indicating whether the signed cookie is valid.

Examples

Example 1

import { verifyCookie } from "https://deno.land/std@0.222.1/http/unstable_signed_cookie.ts";
import { getCookies } from "https://deno.land/std@0.222.1/http/cookie.ts";

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 verifyCookie(signedCookie, key);

Parameters

signedCookie: string

Returns

Promise<boolean>