説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

logout.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const command_1 = require("../command");
  5. const logger_1 = require("../logger");
  6. const clc = require("colorette");
  7. const utils = require("../utils");
  8. const auth = require("../auth");
  9. const prompt_1 = require("../prompt");
  10. exports.command = new command_1.Command("logout [email]")
  11. .description("log the CLI out of Firebase")
  12. .action(async (email, options) => {
  13. const globalToken = utils.getInheritedOption(options, "token");
  14. utils.assertIsStringOrUndefined(globalToken);
  15. const allAccounts = auth.getAllAccounts();
  16. if (allAccounts.length === 0 && !globalToken) {
  17. logger_1.logger.info("No need to logout, not logged in");
  18. return;
  19. }
  20. const defaultAccount = auth.getGlobalDefaultAccount();
  21. const additionalAccounts = auth.getAdditionalAccounts();
  22. const accountsToLogOut = email
  23. ? allAccounts.filter((a) => a.user.email === email)
  24. : allAccounts;
  25. if (email && accountsToLogOut.length === 0) {
  26. utils.logWarning(`No account matches ${email}, can't log out.`);
  27. return;
  28. }
  29. const logoutDefault = email === (defaultAccount === null || defaultAccount === void 0 ? void 0 : defaultAccount.user.email);
  30. let newDefaultAccount = undefined;
  31. if (logoutDefault && additionalAccounts.length > 0) {
  32. if (additionalAccounts.length === 1) {
  33. newDefaultAccount = additionalAccounts[0];
  34. }
  35. else {
  36. const choices = additionalAccounts.map((a) => {
  37. return {
  38. name: a.user.email,
  39. value: a,
  40. };
  41. });
  42. newDefaultAccount = await (0, prompt_1.promptOnce)({
  43. type: "list",
  44. message: "You are logging out of your default account, which account should become the new default?",
  45. choices,
  46. });
  47. }
  48. }
  49. for (const account of accountsToLogOut) {
  50. const token = account.tokens.refresh_token;
  51. if (token) {
  52. auth.setRefreshToken(token);
  53. try {
  54. await auth.logout(token);
  55. }
  56. catch (e) {
  57. utils.logWarning(`Invalid refresh token for ${account.user.email}, did not need to deauthorize`);
  58. }
  59. utils.logSuccess(`Logged out from ${clc.bold(account.user.email)}`);
  60. }
  61. }
  62. if (globalToken) {
  63. auth.setRefreshToken(globalToken);
  64. try {
  65. await auth.logout(globalToken);
  66. }
  67. catch (e) {
  68. utils.logWarning("Invalid refresh token, did not need to deauthorize");
  69. }
  70. utils.logSuccess(`Logged out from token "${clc.bold(globalToken)}"`);
  71. }
  72. if (newDefaultAccount) {
  73. utils.logSuccess(`Setting default account to "${newDefaultAccount.user.email}"`);
  74. auth.setGlobalDefaultAccount(newDefaultAccount);
  75. }
  76. });