feat: automatically open the oauth URL

This commit is contained in:
2025-12-03 14:32:43 -08:00
parent bd3f2c6388
commit 43e8b4e6c6
3 changed files with 113 additions and 6 deletions
+11 -1
View File
@@ -19,6 +19,7 @@ import crypto from "node:crypto";
import http from "node:http";
import process from "node:process";
import { confirm } from "@inquirer/prompts";
import open from "open";
interface Guild {
name?: string;
@@ -348,13 +349,22 @@ async function startOAuthFlow(): Promise<string> {
authUrl.searchParams.set("code_challenge_method", "S256");
console.log("\n====== Discord OAuth ======");
console.log("1. Open the following URL in your browser:");
console.log(
`1. Open the following URL in your browser (we will try to automatically open it for you):`,
);
console.log(authUrl.toString());
console.log("2. Approve access for your application.");
console.log(
"3. Return here; the script will continue once approval is complete.\n",
);
void open(authUrl.toString(), { wait: false }).catch(() => {
console.log(
"Failed to open browser. Please open the following URL in your browser:",
);
console.log(authUrl.toString());
});
const code = await waitForOAuthCode(redirectUri, state);
const tokenRequest: TokenExchangeOptions = {
clientId,