feat(platform): add Discord onboarding and Velocity gate
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { hashToken } from "@minecraft-account-manager/auth";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { createDatabase, pluginCredentials } from "../src/index";
|
||||
|
||||
const serverId = process.argv[2]?.trim();
|
||||
if (!serverId || !/^[a-z0-9][a-z0-9_-]{1,99}$/i.test(serverId)) {
|
||||
throw new Error("Usage: npm run plugin:create-credential --workspace @minecraft-account-manager/database -- <server-id>");
|
||||
}
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL?.trim();
|
||||
if (!databaseUrl) throw new Error("DATABASE_URL is required");
|
||||
|
||||
const token = randomBytes(32).toString("base64url");
|
||||
const { db, client } = createDatabase(databaseUrl);
|
||||
const now = new Date();
|
||||
|
||||
await db
|
||||
.insert(pluginCredentials)
|
||||
.values({ serverId, secretHash: hashToken(token) })
|
||||
.onConflictDoUpdate({
|
||||
target: pluginCredentials.serverId,
|
||||
set: { secretHash: hashToken(token), revokedAt: null, updatedAt: now },
|
||||
});
|
||||
|
||||
console.log(`Server ID: ${serverId}`);
|
||||
console.log(`API token: ${token}`);
|
||||
console.log("Store this token in the Velocity plugin configuration now; it will not be shown again.");
|
||||
await client.end();
|
||||
Reference in New Issue
Block a user