You can close this tab and return to the terminal.
", + ); + + clearTimeout(timeoutHandle); + server.close(() => { + saveMeshToken(meshUrl, apiKey) + .then(() => resolve(apiKey)) + .catch((err) => { + console.warn( + "Warning: Could not persist Mesh token:", + err instanceof Error ? err.message : String(err), + ); + resolve(apiKey); + }); + }); + } catch (err) { + res.writeHead(500); + res.end("Authentication error — check terminal for details."); + clearTimeout(timeoutHandle); + server.close(() => + reject(err instanceof Error ? err : new Error(String(err))), + ); + } + }); + + server.on("error", (err) => { + clearTimeout(timeoutHandle); + reject(err); + }); + + // Listen on a random port + server.listen(0, () => { + const addr = server.address(); + const port = typeof addr === "object" && addr ? addr.port : 3458; + const callbackUrl = `http://localhost:${port}/callback`; + const loginUrl = `${meshUrl}/login?cli&redirectTo=${encodeURIComponent(callbackUrl)}`; + + console.log("Opening browser for Mesh authentication..."); + console.log( + "If the browser does not open automatically, visit:", + loginUrl, + ); + + openBrowser(loginUrl); + }); + }); +} + +/** + * Ensure the CLI has a valid Mesh API key for the given Mesh URL. + * + * - If a stored token exists, returns it immediately. + * - If not, starts a browser OAuth flow (120-second timeout). + * + * Returns the API key string. + */ +export async function ensureMeshAuth(meshUrl: string): PromiseLoading...
++ No local-dev connection is configured for this project. Add a + local-dev project first. +
++ Starting declare server... +
++ The .planning/ directory exists but the declare server isn't + running. Start it to view the dashboard. +
++ {isLoading + ? "Checking declare server..." + : "Starting declare server..."} +
++ {result.message} +
+ ++ Plan your project with declarations, milestones, and actions. +
+{error}
+ )} + + ++ {suggestion.reason} +
++ Enter a URL to analyze your site across SEO, performance, content, + and more. +
+Loading...
++ This plugin requires a connection to be configured. Go to project + settings to select which integration to use. +
+Loading report...
+Report not found
+ ++ Analyzed{" "} + {new Date(report.analyzedAt).toLocaleDateString(undefined, { + year: "numeric", + month: "short", + day: "numeric", + hour: "2-digit", + minute: "2-digit", + })} +
+