Accounts 1.0.0 backend: OIDC provider, sign-in steps, account and admin API

oidc-provider 9.13.3 with PKCE, ES256, crosscode.identity/1 claims and
back-channel logout; clients are the linked products (Connect). Sign-in
steps (password, sign-up, email check, 2FA and its setup, privacy notice,
news question, password reset) survive to the product. Account page and
admin API, church profile, export and deletion fan-out, Hub v2 client,
jobs. End-to-end tests with a test product on openid-client.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 13:33:49 +02:00
co-authored by Claude Opus 5.5
parent 45c6539bf1
commit 069b66fd30
51 changed files with 4863 additions and 9 deletions
+51
View File
@@ -0,0 +1,51 @@
/**
* The server's settings, from the environment (`.env`, built from `env.template.json`). Read once;
* tests pass their own with `loadConfig({...})`.
*/
export type Config = {
/** The public address, e.g. https://accounts.hopefamily.co.za (no trailing slash). */
publicUrl: string;
port: number;
/** Encrypts secrets at rest and signs cookies. Generated on the server, never sent anywhere. */
secret: string;
production: boolean;
/** Behind nginx/frp: trust X-Forwarded-* (as Events' TRUST_PROXY). */
trustProxy: boolean;
hubUrl: string;
hubLicenceKey: string | null;
hubPublicKey: string | null;
hubAdminName: string | null;
hubAdminEmail: string | null;
timezone: string;
smtp: { host: string; port: number; user: string; pass: string; from: string; secure: boolean } | null;
/** Local testing only: linked products on http or private addresses. */
allowPrivateLinks: boolean;
jobsEnabled: boolean;
};
const bool = (v: string | undefined, def: boolean) => (v === undefined || v === '' ? def : String(v).toLowerCase() === 'true');
export function loadConfig(env: Record<string, string | undefined> = process.env): Config {
const publicUrl = String(env.ACCOUNTS_URL || env.PUBLIC_URL || 'http://localhost:3200').replace(/\/+$/, '');
const production = env.NODE_ENV === 'production';
const secret = env.ACCOUNTS_SECRET || '';
if (production && secret.length < 32) throw new Error('ACCOUNTS_SECRET must be set (at least 32 characters) in production.');
return {
publicUrl,
port: Number(env.PORT || 5200),
secret: secret || 'development-only-secret-change-me-0123456789',
production,
trustProxy: bool(env.TRUST_PROXY, production),
hubUrl: String(env.HUB_URL || 'https://hub.crosscode.co.za').replace(/\/+$/, ''),
hubLicenceKey: env.HUB_LICENCE_KEY?.trim() || null,
hubPublicKey: env.HUB_PUBLIC_KEY?.trim() || null,
hubAdminName: env.HUB_ADMIN_NAME?.trim() || null,
hubAdminEmail: env.HUB_ADMIN_EMAIL?.trim() || null,
timezone: env.APP_TIMEZONE || 'Africa/Johannesburg',
smtp: env.SMTP_HOST
? { host: env.SMTP_HOST, port: Number(env.SMTP_PORT || 587), user: env.SMTP_USER || '', pass: env.SMTP_PASS || '', from: env.SMTP_FROM || env.SMTP_USER || '', secure: bool(env.SMTP_SECURE, Number(env.SMTP_PORT) === 465) }
: null,
allowPrivateLinks: bool(env.LINKS_ALLOW_PRIVATE, false),
jobsEnabled: bool(env.JOBS_ENABLED, true),
};
}