toApiAudience (api/principal.ts)

cloudflare-workers-nextjs-saas-template · src/lib/api/principal.ts · typescript · MIT
auth, Auth / Identity

Auth utilities for API principals, audience, scopes, and request context.

// Source: https://github.com/LubomirGeorgiev/cloudflare-workers-nextjs-saas-template | License: MIT | Copyright 2025 Lubomir Georgiev (Любомир Георгиев)
// Provided via justclaw.it.com; keep this notice with the code.
import "server-only";

import { AsyncLocalStorage } from "node:async_hooks";

import { ActionError } from "@/lib/action-error";
import type { GrantedScope } from "@/lib/api/admin-scopes";
import type { CurrentSession } from "@/types";
import type { KVSession } from "@/utils/kv-session";
import { getInitials } from "@/utils/name-initials";

// Prose, not catalog keys: these reach machine clients as an RFC 9457 `detail` and an MCP agent
// reads them verbatim. Naming the scope is what lets an agent ask for the right one.
const NO_PRINCIPAL_DETAIL = "This request carries no aut

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

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

Get a free API key