No Description
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.

account.js 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.doSetup = void 0;
  4. const logger_1 = require("../../logger");
  5. const utils = require("../../utils");
  6. const auth_1 = require("../../auth");
  7. const prompt_1 = require("../../prompt");
  8. const error_1 = require("../../error");
  9. async function promptForAccount() {
  10. logger_1.logger.info();
  11. logger_1.logger.info(`Which account do you want to use for this project? Choose an account or add a new one now`);
  12. logger_1.logger.info();
  13. const allAccounts = (0, auth_1.getAllAccounts)();
  14. const choices = allAccounts.map((a) => {
  15. return {
  16. name: a.user.email,
  17. value: a.user.email,
  18. };
  19. });
  20. choices.push({
  21. name: "(add a new account)",
  22. value: "__add__",
  23. });
  24. const emailChoice = await (0, prompt_1.promptOnce)({
  25. type: "list",
  26. name: "email",
  27. message: "Please select an option:",
  28. choices,
  29. });
  30. if (emailChoice === "__add__") {
  31. const newAccount = await (0, auth_1.loginAdditionalAccount)(true);
  32. if (!newAccount) {
  33. throw new error_1.FirebaseError("Failed to add new account", { exit: 1 });
  34. }
  35. return newAccount;
  36. }
  37. else {
  38. return (0, auth_1.findAccountByEmail)(emailChoice);
  39. }
  40. }
  41. async function doSetup(setup, config, options) {
  42. let account;
  43. if (options.account) {
  44. account = (0, auth_1.findAccountByEmail)(options.account);
  45. if (!account) {
  46. throw new error_1.FirebaseError(`Invalid account ${options.account}`, { exit: 1 });
  47. }
  48. }
  49. else {
  50. account = await promptForAccount();
  51. }
  52. if (!account) {
  53. throw new error_1.FirebaseError(`No account selected, have you run "firebase login"?`, { exit: 1 });
  54. }
  55. (0, auth_1.setActiveAccount)(options, account);
  56. if (config.projectDir) {
  57. (0, auth_1.setProjectAccount)(config.projectDir, account.user.email);
  58. }
  59. logger_1.logger.info();
  60. utils.logSuccess(`Using account: ${account.user.email}`);
  61. }
  62. exports.doSetup = doSetup;