chore: Projektbasis und PostgreSQL-Migrationen einrichten

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul SchoeneckandCopilot committed 2026-11-03 08:01:24 +01:00
commit 10af6159b4
14 files changed
+2214

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import { Pool } from "pg";
const globalDb = globalThis as typeof globalThis & { kibuPool?: Pool };
function createPool() {
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
max: 10,
connectionTimeoutMillis: 5000,
});
pool.on("error", (error) => console.error("PostgreSQL-Verbindung im Pool unterbrochen:", error));
return pool;
}
export const db = globalDb.kibuPool ?? createPool();
if (process.env.NODE_ENV !== "production") globalDb.kibuPool = db;
+18
View File
@@ -0,0 +1,18 @@
import { randomBytes, scrypt as scryptCallback, timingSafeEqual } from "node:crypto";
import { promisify } from "node:util";
const scrypt = promisify(scryptCallback);
export async function hashPassword(password: string): Promise<string> {
const salt = randomBytes(16).toString("hex");
const hash = await scrypt(password, salt, 64) as Buffer;
return `${salt}:${hash.toString("hex")}`;
}
export async function verifyPassword(password: string, stored: string): Promise<boolean> {
const [salt, hex] = stored.split(":");
if (!salt || !hex) return false;
const expected = Buffer.from(hex, "hex");
const actual = await scrypt(password, salt, 64) as Buffer;
return expected.length === actual.length && timingSafeEqual(expected, actual);
}