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.

57 lines
2.7 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const _ = require("lodash");
  5. const clc = require("colorette");
  6. const command_1 = require("../command");
  7. const logger_1 = require("../logger");
  8. const configstore_1 = require("../configstore");
  9. const utils = require("../utils");
  10. const error_1 = require("../error");
  11. const prompt_1 = require("../prompt");
  12. const auth = require("../auth");
  13. const utils_1 = require("../utils");
  14. exports.command = new command_1.Command("login")
  15. .description("log the CLI into Firebase")
  16. .option("--no-localhost", "login from a device without an accessible localhost")
  17. .option("--reauth", "force reauthentication even if already logged in")
  18. .action(async (options) => {
  19. if (options.nonInteractive) {
  20. throw new error_1.FirebaseError("Cannot run login in non-interactive mode. See " +
  21. clc.bold("login:ci") +
  22. " to generate a token for use in non-interactive environments.", { exit: 1 });
  23. }
  24. const user = options.user;
  25. const tokens = options.tokens;
  26. if (user && tokens && !options.reauth) {
  27. logger_1.logger.info("Already logged in as", clc.bold(user.email));
  28. return user;
  29. }
  30. if (!options.reauth) {
  31. utils.logBullet("Firebase optionally collects CLI and Emulator Suite usage and error reporting information to help improve our products. Data is collected in accordance with Google's privacy policy (https://policies.google.com/privacy) and is not used to identify you.\n");
  32. const collectUsage = await (0, prompt_1.promptOnce)({
  33. type: "confirm",
  34. name: "collectUsage",
  35. message: "Allow Firebase to collect CLI and Emulator Suite usage and error reporting information?",
  36. });
  37. configstore_1.configstore.set("usage", collectUsage);
  38. if (collectUsage) {
  39. utils.logBullet("To change your data collection preference at any time, run `firebase logout` and log in again.");
  40. }
  41. }
  42. const useLocalhost = (0, utils_1.isCloudEnvironment)() ? false : options.localhost;
  43. const result = await auth.loginGoogle(useLocalhost, _.get(user, "email"));
  44. configstore_1.configstore.set("user", result.user);
  45. configstore_1.configstore.set("tokens", result.tokens);
  46. configstore_1.configstore.set("loginScopes", result.scopes);
  47. configstore_1.configstore.delete("session");
  48. logger_1.logger.info();
  49. if (typeof result.user !== "string") {
  50. utils.logSuccess("Success! Logged in as " + clc.bold(result.user.email));
  51. }
  52. else {
  53. logger_1.logger.debug("Unexpected string for UserCredentials.user. Maybe an auth response JWT didn't parse right?");
  54. utils.logSuccess("Success! Logged in");
  55. }
  56. return auth;
  57. });