@redocly/cli
Version:
[@Redocly](https://redocly.com) CLI is your all-in-one API documentation utility. It builds, manages, improves, and quality-checks your API descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make
31 lines • 1.25 kB
JavaScript
import { logger } from '@redocly/openapi-core';
import { RedoclyOAuthClient } from '../../../auth/oauth-client.js';
import { getReuniteUrl } from '../../../reunite/api/index.js';
import { exitWithError } from '../../../utils/error.js';
export async function handleLoginAndFetchToken(config, verbose = false) {
const reuniteUrl = getReuniteUrl(config, config.resolvedConfig?.residency);
const oauthClient = new RedoclyOAuthClient();
let accessToken = await oauthClient.getAccessToken(reuniteUrl);
if (accessToken) {
if (verbose) {
logger.info(`Using existing access token.\n`);
}
return accessToken;
}
if (verbose) {
logger.warn(`No valid access token found or refresh token expired. Attempting login...\n`);
}
try {
await oauthClient.login(reuniteUrl);
accessToken = await oauthClient.getAccessToken(reuniteUrl);
}
catch (error) {
if (verbose) {
logger.error(`❌ Login failed.\n`);
logger.error(`Error details: ${error.message}\n`);
}
exitWithError(`Login failed. Please try again or check your connection to ${reuniteUrl}.`);
}
return accessToken;
}
//# sourceMappingURL=login-handler.js.map