GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.5 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const command_1 = require("../command");
  6. const logger_1 = require("../logger");
  7. const utils = require("../utils");
  8. const error_1 = require("../error");
  9. const auth = require("../auth");
  10. exports.command = new command_1.Command("login:add [email]")
  11. .description("authorize the CLI for an additional account")
  12. .option("--no-localhost", "copy and paste a code instead of starting a local server for authentication")
  13. .action(async (email, options) => {
  14. if (options.nonInteractive) {
  15. throw new error_1.FirebaseError(`Cannot run "${clc.bold("login:add")}" in non-interactive mode.`);
  16. }
  17. const account = auth.getGlobalDefaultAccount();
  18. if (!account) {
  19. throw new error_1.FirebaseError(`No existing accounts found, please run "${clc.bold("firebase login")}" to add your first account`);
  20. }
  21. const hintUser = auth.getAllAccounts().find((a) => a.user.email === email);
  22. if (email && hintUser) {
  23. throw new error_1.FirebaseError(`Already signed in as ${email}, use "${clc.bold("firebase login --reauth")}" to reauthenticate.`);
  24. }
  25. const useLocalhost = utils.isCloudEnvironment() ? false : options.localhost;
  26. const newAccount = await auth.loginAdditionalAccount(useLocalhost, email);
  27. if (newAccount) {
  28. logger_1.logger.info();
  29. utils.logSuccess("Success! Added account " + clc.bold(newAccount.user.email));
  30. }
  31. return newAccount;
  32. });