alwaysai
Version:
The alwaysAI command-line interface (CLI)
58 lines • 3.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.alwaysaiUserLoginYesComponent = void 0;
const alwayscli_1 = require("@alwaysai/alwayscli");
const cloud_api_1 = require("@alwaysai/cloud-api");
const chalk = require("chalk");
const constants_1 = require("../../constants");
const infrastructure_1 = require("../../infrastructure");
const util_1 = require("../../util");
async function alwaysaiUserLoginYesComponent(props) {
const { alwaysaiUserEmail, alwaysaiUserPassword } = props;
const boldEmail = chalk.bold(alwaysaiUserEmail);
const webAuthUrl = chalk.bold(`https://dashboard.${(0, cloud_api_1.SystemDomainName)((0, infrastructure_1.getSystemId)())}/auth`);
const spinner = (0, util_1.Spinner)(`Log in ${props.alwaysaiUserEmail}`);
try {
const { authenticationState } = await (0, infrastructure_1.CliAuthenticationClient)().signIn(alwaysaiUserEmail, alwaysaiUserPassword);
switch (authenticationState) {
case 'AUTHENTICATED': {
spinner.succeed();
break;
}
case 'PASSWORD_RESET_REQUIRED': {
throw new alwayscli_1.CliTerseError(`Password reset required. Please visit the following URL in a web browser:\n\n ${webAuthUrl}`);
}
case 'NON_TEMPORARY_PASSWORD_REQUIRED': {
throw new alwayscli_1.CliTerseError(`First-time login must be done on the web. Please complete the authentication process first in a web browser by visiting the following URL:\n\n ${webAuthUrl}\n\n`);
}
case 'USER_CONFIRMATION_REQUIRED': {
throw new alwayscli_1.CliTerseError('Account not confirmed. Please check your inbox and follow instructions to confirm your account');
}
case 'INVALID_PASSWORD':
case 'INCORRECT_PASSWORD': {
throw new alwayscli_1.CliTerseError(`Incorrect password for ${boldEmail}. Please try again or visit the following URL to reset your password:\n\n ${webAuthUrl}`);
}
case 'USER_NOT_FOUND': {
throw new alwayscli_1.CliTerseError(`User not found for email ${boldEmail}`);
}
case 'CUSTOM_CHALLENGE':
case 'MFA_REQUIRED':
case 'MFA_SETUP':
case 'TOTP_REQUIRED':
case 'SELECT_MFA_TYPE': {
util_1.logger.error(`Authentication client responded with authentication state "${authenticationState}".`);
throw new alwayscli_1.CliTerseError(`Authentication client responded with authentication state "${authenticationState}". ${constants_1.PLEASE_REPORT_THIS_ERROR_MESSAGE}`);
}
default: {
util_1.logger.error(`Unexpected authentication state "${authenticationState}".`);
throw new alwayscli_1.CliTerseError(`Unexpected authentication state "${authenticationState}". ${constants_1.PLEASE_REPORT_THIS_ERROR_MESSAGE}`);
}
}
}
catch (exception) {
spinner.fail();
throw exception;
}
}
exports.alwaysaiUserLoginYesComponent = alwaysaiUserLoginYesComponent;
//# sourceMappingURL=alwaysai-user-login-yes-component.js.map