generated from nhcarrigan/template
feat: automatically open the oauth URL
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user