feat(36-01): add scripts/grant-admin.ts for granting/revoking admin status
This commit is contained in:
33
scripts/grant-admin.ts
Normal file
33
scripts/grant-admin.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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}`);
|
||||
Reference in New Issue
Block a user