Files
GearBox/scripts/grant-admin.ts
Jean-Luc Makiola e044547121
Some checks failed
CI / ci (push) Failing after 1m41s
CI / e2e (push) Has been skipped
CI / deploy (push) Has been skipped
chore: fix lint errors — auto-format, isNaN, unused imports, button type
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 22:54:37 +02:00

40 lines
964 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}`,
);