Secure Sakani portal and show full album titles

This commit is contained in:
Leon Tonhäuser committed 2026-11-30 19:14:57 +01:00
1 parent c40ccf77cf
commit 69264ce165
49 files changed
+1362 -601

No files matched your search

+17 -37
View File
@@ -1,44 +1,24 @@
import { eq } from "drizzle-orm";
import { auth } from "../src/modules/auth/auth";
import { db } from "../src/db/client";
import { users } from "../src/db/schema";
import { text } from "node:stream/consumers";
import { insertAdminCredential, seedAdmin } from "../src/modules/auth/admin-bootstrap";
async function main() {
const email = process.argv[2] || "mail@leon-tonhaeuser.de";
const password = process.argv[3] || "AdminPassword123!";
const name = process.argv[4] || "Leon Tonhäuser";
console.log(`Creating Admin user: ${email}...`);
try {
const res = await auth.api.signUpEmail({
body: {
email,
name,
password,
},
});
const userId = res.user.id;
await db.update(users).set({ role: "ADMIN", emailVerified: true }).where(eq(users.id, userId));
console.log(`Successfully created Admin account!`);
console.log(`Email: ${email}`);
console.log(`Password: ${password}`);
} catch (error) {
console.error("Error creating admin user:", error);
// If user already exists, update to admin
const [existing] = await db.select().from(users).where(eq(users.email, email));
if (existing) {
await db.update(users).set({ role: "ADMIN", emailVerified: true }).where(eq(users.id, existing.id));
console.log(`Updated existing user ${email} to ADMIN role.`);
}
const [email, name, ...extra] = process.argv.slice(2);
if (!email || !name || extra.length > 0 || process.stdin.isTTY) {
throw new Error("Supply email and name as arguments and the password on stdin");
}
process.exit(0);
const password = (await text(process.stdin)).replace(/\r?\n$/, "");
const { db, pool } = await import("../src/db/client");
try {
await seedAdmin({ email, name, password }, (credential) => insertAdminCredential(db, credential));
} finally {
await pool.end();
}
console.log("Admin account created.");
}
main().catch((err) => {
console.error("Fatal error:", err);
process.exit(1);
main().catch(() => {
console.error("Admin seed failed. Check the input, database connectivity and whether the email is already registered.");
process.exitCode = 1;
});