Fix admin authorization and harden chat requests
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
/** Operator-only role assignment; never exposed through an HTTP endpoint. */
|
||||
import {createConfig} from "../src/config.js";
|
||||
import {createDatabase} from "../src/db/index.js";
|
||||
|
||||
const [username, role] = process.argv.slice(2);
|
||||
if (!username || !["user", "admin"].includes(role) || process.argv.length !== 4) {
|
||||
console.error("Usage: npm run user:role -- <existing-username> <user|admin>");
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
const db = createDatabase(createConfig());
|
||||
try {
|
||||
const result = db.prepare("UPDATE users SET role = ? WHERE username = ?").run(role, username);
|
||||
if (!result.changes) throw new Error("Account not found. Register the account first.");
|
||||
console.log(`Role for ${username} set to ${role}.`);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user