Skip to main content

apps/web/lib/operator-session.ts

Metadata

Indexed Symbols

  • decodeBase64Url (line 22, function) - Implements decode base64 url for module behavior.
  • parseOperatorSessionClaims (line 28, function) - Implements parse operator session claims for module behavior.
  • readOperatorSession (line 70, function) - Implements read operator session for module behavior.
  • setOperatorSessionToken (line 85, function) - Implements set operator session token for module behavior.
  • clearOperatorSessionToken (line 103, function) - Implements clear operator session token for module behavior.
  • resolveOperatorAuthToken (line 108, function) - Implements resolve operator auth token for module behavior.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import "server-only";

import { cookies } from "next/headers";
import { assertOperatorAccess } from "./operator-auth";
import { isWorkspaceId } from "./workspace-context";

type OperatorSessionClaims = {
sub: string;
roles: string[];
workspaceIds: string[];
exp?: number;
jti?: string;
};

export type OperatorSession = {
token: string;
claims: OperatorSessionClaims;
};

const operatorSessionCookieName = "anchor_operator_session";

function decodeBase64Url(value: string): string {
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
const padded = normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "=");
return Buffer.from(padded, "base64").toString("utf8");