convex
Version:
Client for the Convex Cloud
45 lines (44 loc) • 1.45 kB
JavaScript
;
import { Command } from "commander";
import chalk from "chalk";
import { readProjectConfig } from "./lib/config.js";
import open from "open";
import axios from "axios";
import { version } from "../index.js";
import { fatalServerErr } from "./lib/utils.js";
import { getUrlAndAdminKey } from "./lib/api.js";
import { oneoffContext } from "./lib/context.js";
export const dashboard = new Command("dashboard").description("Open the dashboard in the browser").option(
"--no-open",
"Don't automatically open the dashboard in the default browser"
).action(async (options) => {
const ctx = oneoffContext;
const { projectConfig } = await readProjectConfig(ctx);
const { url, adminKey } = await getUrlAndAdminKey(
ctx,
projectConfig.project,
projectConfig.team,
"prod"
);
const loginUrl = await dashboardLogin(ctx, url, adminKey);
if (options.open) {
console.log(chalk.gray(`Opening ${loginUrl} in the default browser...`));
await open(loginUrl);
} else {
console.log(loginUrl);
}
});
async function dashboardLogin(ctx, instanceOrigin, adminKey) {
try {
return (await axios.post(`${instanceOrigin}/api/${version}/one_time_login_url`, {
version,
adminKey
})).data.loginUrl;
} catch (err) {
console.error(
chalk.red("Error: Unable to login to dashboard at ", instanceOrigin)
);
return await fatalServerErr(ctx, err);
}
}
//# sourceMappingURL=dashboard.js.map