Files
community-rule/lib/server/env.ts
T
adilallo 46c34a6323 Delete unused login and invite tokens on a daily job, and keep their URLs out of logs.
Expired sign-in, save-progress, email-change, and invitation tokens (and any draft they carry) are cleared by a Cloudron scheduler task. Page timing logs record the path without the query string, and mail failures log a request id instead of an address.
2026-11-10 15:34:33 -07:00

48 lines
1.5 KiB
TypeScript

export function getSessionPepper(): string {
const secret = process.env.SESSION_SECRET;
if (!secret || secret.length < 16) {
throw new Error(
"SESSION_SECRET must be set (min 16 characters) for auth routes.",
);
}
return secret;
}
export function getDatabaseUrl(): string | undefined {
return process.env.CLOUDRON_POSTGRESQL_URL?.trim() || undefined;
}
export function getSmtpUrl(): string | undefined {
const server = process.env.CLOUDRON_MAIL_SMTP_SERVER?.trim();
const port = process.env.CLOUDRON_MAIL_SMTP_PORT?.trim();
if (!server || !port) return undefined;
const username = process.env.CLOUDRON_MAIL_SMTP_USERNAME?.trim() ?? "";
const password = process.env.CLOUDRON_MAIL_SMTP_PASSWORD?.trim() ?? "";
if (username || password) {
const auth = `${encodeURIComponent(username)}:${encodeURIComponent(password)}@`;
return `smtp://${auth}${server}:${port}`;
}
return `smtp://${server}:${port}`;
}
export function isDatabaseConfigured(): boolean {
return Boolean(getDatabaseUrl());
}
/** Bearer token for POST /api/ops/prune. Unset hides the route. */
export function getOpsPruneToken(): string | null {
const raw = process.env.OPS_PRUNE_TOKEN?.trim();
return raw && raw.length > 0 ? raw : null;
}
/** Named admins who may open a private Rule. Comma-separated emails. */
export function getRuleAdminEmails(): string[] {
const raw = process.env.RULE_ADMIN_EMAILS?.trim();
if (!raw) return [];
return raw
.split(",")
.map((item) => item.trim().toLowerCase())
.filter((item) => item.length > 0);
}