From 7c9befe428003d5f4f0d9cbca8f82f1cb11c8934 Mon Sep 17 00:00:00 2001 From: Sagar Date: Thu, 4 Jul 2024 13:51:29 +0530 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9A=80=20feat=20:=20Auth=20for=20cli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An authentication method for cli using clerk --- .github/workflows/build_and_publish.yaml | 2 ++ src/utils/findGitemoCommands.js | 15 ++++++++++++++ src/utils/requireLogin.js | 25 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/utils/requireLogin.js diff --git a/.github/workflows/build_and_publish.yaml b/.github/workflows/build_and_publish.yaml index b15eab1..813bc1a 100644 --- a/.github/workflows/build_and_publish.yaml +++ b/.github/workflows/build_and_publish.yaml @@ -23,6 +23,7 @@ jobs: run: | export CLIENT_URL=${{ secrets.CLIENT_URL }} export API_KEY=${{ secrets.API_KEY }} + export KEY_FILENAME=${{ secrets.KEY_FILENAME }} npm install --frozen-lockfile npm run build --if-present - name: Create Release Pull Request or Publish @@ -31,6 +32,7 @@ jobs: with: publish: npm run release title: "📦 Version packages" + commit: "📦 package: Version packages" env: GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/src/utils/findGitemoCommands.js b/src/utils/findGitemoCommands.js index 32c0d0a..8ef2eec 100644 --- a/src/utils/findGitemoCommands.js +++ b/src/utils/findGitemoCommands.js @@ -1,4 +1,6 @@ import FLAGS from '@constants/flag.js'; +import requireLogin from './requireLogin'; +import chalk from 'chalk'; const isSupportedCommand = (command, options) => { return Object.keys(options).includes(command); @@ -38,6 +40,19 @@ const getOptionsForCommand = (command, flags, input, type) => { const findGitemoCommand = (cli, options) => { const { command, type } = determineCommand(cli.flags, cli.input, options); + var key = requireLogin(command); + + if (command === FLAGS.LOGIN) { + if (key && key !== 1) { + console.log(chalk.bold.green(`\n\nYou are already logged in\n\n`)); + return; + } + } + + if (!key || key === undefined) { + return; + } + if (!command || !isSupportedCommand(command, options)) { return cli.showHelp(); } diff --git a/src/utils/requireLogin.js b/src/utils/requireLogin.js new file mode 100644 index 0000000..ad0300f --- /dev/null +++ b/src/utils/requireLogin.js @@ -0,0 +1,25 @@ +import os from 'os'; +import path from 'path'; +import chalk from 'chalk'; +import { readFileSync } from 'fs'; +import dotenv from 'dotenv'; +dotenv.config(); + +function requireLogin(command) { + try { + const FILENAME = process.env.KEY_FILENAME; + const homeDir = os.homedir(); + const filePath = path.join(homeDir, FILENAME); + const fileData = readFileSync(filePath, 'utf8'); + const { key } = JSON.parse(fileData); + return key; + } catch (error) { + if (command === 'login') { + return 1; + } + console.log(chalk.red(`No key found! Please login first\n\n`)); + console.log(`use ${chalk.cyan('gitemo login')} to login\n`); + } +} + +export default requireLogin; From e55cb150eb6aea1881b8c11ad10f84018179b0d4 Mon Sep 17 00:00:00 2001 From: Sagar Date: Thu, 4 Jul 2024 13:54:21 +0530 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=96=20release=20:=20New=20releases?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/little-apes-appear.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/little-apes-appear.md diff --git a/.changeset/little-apes-appear.md b/.changeset/little-apes-appear.md new file mode 100644 index 0000000..7d2540a --- /dev/null +++ b/.changeset/little-apes-appear.md @@ -0,0 +1,5 @@ +--- +'gitemo-cli': minor +--- + +authentication for cli