25 lines
869 B
TypeScript
25 lines
869 B
TypeScript
import { text } from "node:stream/consumers";
|
|
|
|
import { insertAdminCredential, seedAdmin } from "../src/modules/auth/admin-bootstrap";
|
|
|
|
async function main() {
|
|
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");
|
|
}
|
|
|
|
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(() => {
|
|
console.error("Admin seed failed. Check the input, database connectivity and whether the email is already registered.");
|
|
process.exitCode = 1;
|
|
});
|