mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
Co-authored-by: IhorKarpiuk <ihor.karpiuk@redocly.com> Co-authored-by: SmoliyY <yevhen.smoliy@gmail.com>
28 lines
870 B
TypeScript
28 lines
870 B
TypeScript
import { Region, RedoclyClient, Config } from '@redocly/openapi-core';
|
|
import { blue, green, gray } from 'colorette';
|
|
import { promptUser } from '../utils/miscellaneous';
|
|
|
|
export function promptClientToken(domain: string) {
|
|
return promptUser(
|
|
green(
|
|
`\n 🔑 Copy your API key from ${blue(`https://app.${domain}/profile`)} and paste it below`
|
|
),
|
|
true
|
|
);
|
|
}
|
|
|
|
export type LoginOptions = {
|
|
verbose?: boolean;
|
|
region?: Region;
|
|
config?: string;
|
|
};
|
|
|
|
export async function handleLogin(argv: LoginOptions, config: Config) {
|
|
const region = argv.region || config.region;
|
|
const client = new RedoclyClient(region);
|
|
const clientToken = await promptClientToken(client.domain);
|
|
process.stdout.write(gray('\n Logging in...\n'));
|
|
await client.login(clientToken, argv.verbose);
|
|
process.stdout.write(green(' Authorization confirmed. ✅\n\n'));
|
|
}
|