34 lines
952 B
TypeScript
34 lines
952 B
TypeScript
/**
|
|
* Grant or revoke admin status for a GearBox user.
|
|
*
|
|
* Usage:
|
|
* bun scripts/grant-admin.ts <logto-sub> # grant admin
|
|
* bun scripts/grant-admin.ts <logto-sub> --revoke # revoke admin
|
|
*/
|
|
|
|
import { eq } from "drizzle-orm";
|
|
import { db } from "../src/db/index.ts";
|
|
import { users } from "../src/db/schema.ts";
|
|
|
|
const sub = process.argv[2];
|
|
const revoke = process.argv.includes("--revoke");
|
|
|
|
if (!sub) {
|
|
console.error("Usage: bun scripts/grant-admin.ts <logto-sub> [--revoke]");
|
|
process.exit(1);
|
|
}
|
|
|
|
const [user] = await db
|
|
.update(users)
|
|
.set({ isAdmin: !revoke })
|
|
.where(eq(users.logtoSub, sub))
|
|
.returning({ id: users.id, logtoSub: users.logtoSub, isAdmin: users.isAdmin });
|
|
|
|
if (!user) {
|
|
console.error(`User not found with logto_sub: ${sub}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const action = revoke ? "Revoked admin from" : "Granted admin to";
|
|
console.log(`${action} user ${user.id} (${user.logtoSub}) — isAdmin: ${user.isAdmin}`);
|