-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from SySagar/fix
🚀 feat : authentication added
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'gitemo-cli': minor | ||
--- | ||
|
||
authentication for cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |