Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445// Shared auth constants and small helpers.
// Metadata key marking a route/handler as reachable without a session.export const IS_PUBLIC_KEY = 'isAuthPublic';
// Name of the signed cookie carrying the session id.export const SESSION_COOKIE = 'revision_session';
// DI token for the ordered list of registered auth providers (see AuthModule).export const AUTH_PROVIDERS = Symbol('AUTH_PROVIDERS');
// Session id carried by the signed cookie, or by an Authorization bearer// header for clients that don't use cookies (native shells, sync peers).export function sessionIdFrom(req: { signedCookies?: Record<string, string>; headers: { authorization?: string };}): string | undefined { const cookie = req.signedCookies?.[SESSION_COOKIE]; if (cookie) return cookie; const header = req.headers.authorization; if (header?.startsWith('Bearer ')) return header.slice(7).trim() || undefined; return undefined;}
// Reads the session TTL (days) from env, defaulting to 30. Kept here so the// guard, service and cookie maxAge all agree.export function sessionTtlDays(): number { const raw = Number(process.env.AUTH_SESSION_TTL_DAYS); return Number.isFinite(raw) && raw > 0 ? raw : 30;}
// The whole gate can be disabled for a purely-local single-user deployment// (and for the existing integration tests, which predate auth). Never enable// this on a networked host.export function authDisabled(): boolean { return process.env.AUTH_DISABLED === 'true';}
// Open self-registration from the login screen. Off by default: after the// first-admin bootstrap, accounts are normally created by an admin, so the// operator has to opt in.export function allowSignup(): boolean { return process.env.AUTH_ALLOW_SIGNUP === 'true';}