ci / olares chart · sanity (pull_request) Successful in 3s
ci / app · types + tests + build (pull_request) Successful in 3m7s
markt / eintrag (pull_request) Successful in 29s
release / which version (pull_request) Successful in 3s
release / olares chart · sanity (pull_request) Successful in 4s
release / app (pull_request) Successful in 59s
release / tag and release (pull_request) Skipped
Setup with a code from /app/data, passkeys with required user verification, sessions as hashed cookies bound to the passkey they started with, single-use invitation and device links, removing a passkey or a member, and a recovery code for the owner. Cross-household lookups before sign-in run in withAuth() (app.auth), allowed only on the sign-in tables; a test pins that list. State-changing routes check the session and the Origin header. Security check with the login-sicherheit skill before the first invitation: docs/sicherheit/login-2026-11-06.md (no open findings above low). Entrance goes public now that the own sign-in exists; markt.yml creates the Lunch entry in aimighty-market and proves it with wrangler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
77 lines
2.6 KiB
TypeScript
77 lines
2.6 KiB
TypeScript
import "server-only";
|
|
import { Pool, type PoolClient } from "pg";
|
|
|
|
// Zugang zur Postgres von Olares. Die Werte injiziert das Chart aus
|
|
// .Values.postgres.* (CLAUDE.md, Olares-Regel 5) — nie hartkodieren.
|
|
// Lokal reicht DATABASE_URL.
|
|
function createPool(): Pool {
|
|
if (process.env.DATABASE_URL) return new Pool({ connectionString: process.env.DATABASE_URL, max: 10 });
|
|
return new Pool({
|
|
host: process.env.DB_HOST,
|
|
port: Number(process.env.DB_PORT ?? 5432),
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
max: 10,
|
|
});
|
|
}
|
|
|
|
const globalForPool = globalThis as unknown as { lunchPool?: Pool };
|
|
export const pool: Pool = globalForPool.lunchPool ?? createPool();
|
|
if (process.env.NODE_ENV !== "production") globalForPool.lunchPool = pool;
|
|
|
|
/**
|
|
* Führt `fn` in einer Transaktion im Namen eines Haushalts aus.
|
|
*
|
|
* Jede Fachtabelle hat RLS mit FORCE und die Policy „Mitglied des Haushalts“
|
|
* über `app.household_id`. Ohne diesen Aufruf sieht eine Abfrage nichts —
|
|
* die App verbindet als Tabelleneigentümerin, FORCE ist die einzige Wand.
|
|
* `set_config(…, true)` gilt nur bis zum Ende der Transaktion; ein Client,
|
|
* der in den Pool zurückgeht, trägt keinen Haushalt weiter.
|
|
*/
|
|
export async function withHousehold<T>(householdId: string, fn: (client: PoolClient) => Promise<T>): Promise<T> {
|
|
const client = await pool.connect();
|
|
try {
|
|
await client.query("begin");
|
|
await client.query("select set_config('app.household_id', $1, true)", [householdId]);
|
|
const result = await fn(client);
|
|
await client.query("commit");
|
|
return result;
|
|
} catch (error) {
|
|
await client.query("rollback").catch(() => undefined);
|
|
throw error;
|
|
} finally {
|
|
client.release();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Für die Anmeldung, bevor der Haushalt bekannt ist: setzt `app.auth = on`.
|
|
* Die Policies lassen das nur auf den Tabellen der Anmeldung zu (Migration
|
|
* 0002). Außerhalb von lib/auth/ nie benutzen.
|
|
*/
|
|
export async function withAuth<T>(fn: (client: PoolClient) => Promise<T>): Promise<T> {
|
|
const client = await pool.connect();
|
|
try {
|
|
await client.query("begin");
|
|
await client.query("select set_config('app.auth', 'on', true)");
|
|
const result = await fn(client);
|
|
await client.query("commit");
|
|
return result;
|
|
} catch (error) {
|
|
await client.query("rollback").catch(() => undefined);
|
|
throw error;
|
|
} finally {
|
|
client.release();
|
|
}
|
|
}
|
|
|
|
export async function databaseReachable(): Promise<boolean> {
|
|
try {
|
|
await pool.query("select 1");
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|