apps/web/lib/operator-session.ts
Metadata
- Purpose: Frontend data/service utility module.
- Domain:
applications - Language:
ts - Bytes: 3749
- Lines: 127
- Content hash (short):
15da4e58 - Source (start): apps/web/lib/operator-session.ts:1
- Source (end): apps/web/lib/operator-session.ts:127
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");