-
-
Notifications
You must be signed in to change notification settings - Fork 5
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 #9 from fluentci-io/feat/flu-11-cli-login
feat: implement command line `login`
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -11,3 +11,6 @@ export { z } from "https://deno.land/x/[email protected]/mod.ts"; | |
export { decompress } from "https://deno.land/x/[email protected]/mod.ts"; | ||
export { existsSync } from "https://deno.land/[email protected]/fs/exists.ts"; | ||
export { load } from "https://deno.land/[email protected]/dotenv/mod.ts"; | ||
export { Secret } from "https://deno.land/x/[email protected]/prompt/secret.ts"; | ||
import dir from "https://deno.land/x/[email protected]/mod.ts"; | ||
export { dir }; |
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,24 @@ | ||
import { Secret, brightGreen, dir, red } from "../../deps.ts"; | ||
|
||
async function login() { | ||
console.log( | ||
`You can generate an access token from ${brightGreen( | ||
"https://app.fluentci.io/settings/tokens" | ||
)}` | ||
); | ||
const accessToken: string = await Secret.prompt("Enter your access token: "); | ||
const status = await fetch( | ||
`https://api.fluentci.io/validate?token=${accessToken}` | ||
).then((res) => res.status); | ||
|
||
if (status !== 200) { | ||
console.log(`${red("[✗]")} Invalid access token`); | ||
Deno.exit(1); | ||
} | ||
|
||
Deno.mkdirSync(`${dir("home")}/.fluentci`, { recursive: true }); | ||
Deno.writeTextFileSync(`${dir("home")}/.fluentci/access-token`, accessToken); | ||
console.log(`${brightGreen("[✓]")} Logged in successfully`); | ||
} | ||
|
||
export default login; |