Qwik Router Cookie Utility (request-handler/cookie.ts)

qwik · packages/qwik-router/src/middleware/request-handler/cookie.ts · typescript · MIT
infra, auth, integration, fw:qwik, tag:router

Parses, merges, and formats HTTP cookies for Qwik router middleware, handling SameSite, expiration, domain, and encoding concerns. Reuse for server‑side request handling that needs robust cookie management.

// Source: https://github.com/QwikDev/qwik | License: MIT | Copyright 2024 QwikDev
// Provided via justclaw.it.com; keep this notice with the code.
import type { Cookie as CookieInterface, CookieOptions, CookieValue } from './types';

const SAMESITE = {
  lax: 'Lax',
  Lax: 'Lax',
  None: 'None',
  none: 'None',
  strict: 'Strict',
  Strict: 'Strict',
} as const;

const UNIT = {
  seconds: 1,
  minutes: 1 * 60,
  hours: 1 * 60 * 60,
  days: 1 * 60 * 60 * 24,
  weeks: 1 * 60 * 60 * 24 * 7,
};

const createSetCookieValue = (cookieName: string, cookieValue: string, options: CookieOptions) => {
  const c = [`${cookieName}=${cookieValue}`];

  if (typeof options.domain === 'string') {
    c.push(`Domain=${options.domain}`);
  }

  // If both Expires and Max-Age are set, Max-Age has precedence.


... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key