Skip to content

feat(add): init Guided provider setup #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 14, 2024
Next Next commit
Adds auth add <provider> command
joshnuss committed Jun 6, 2024
commit efa78e6ebbaf8f2b75dec84c18bea4e9396d9635
47 changes: 47 additions & 0 deletions commands/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as y from "yoctocolors"
import { select } from '@inquirer/prompts'

const providers = {
google: {
name: "Google"
},
github: {
name: "GitHub"
},
apple: {
name: "Apple"
}
}

function hasInstructions(provider) {
return Object.keys(providers).includes(provider)
}

async function chooseProvider() {
const choices = Object.keys(providers).map((key) => {
const provider = providers[key]

return {
name: provider.name,
value: key
}
})

return await select({
message: "What provider do you want to set up?",
choices
})
}

export async function action(provider) {
if (!provider) {
provider = await chooseProvider()
}

if (!hasInstructions(provider)) {
console.error(y.red(`Missing instructions for ${provider}.\nAvailable providers are: ${y.bold(Object.keys(providers).sort().join(', '))}`))
process.exit(0)
}

console.log(provider)
}
1 change: 1 addition & 0 deletions commands/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * as ask from "./ask.js"
export * as init from "./init.js"
export * as secret from "./secret.js"
export * as add from './add.js'
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

import { Command, InvalidArgumentError } from "commander"
import * as y from "yoctocolors"
import { ask, init, secret } from "./commands/index.js"
import { ask, init, secret, add } from "./commands/index.js"

// import pkg from "./package.json" assert { type: "json" }

@@ -52,6 +52,12 @@ program
.description("Generate a random string and add it to the .env file.")
.action(secret.action)

program
.command("add")
.argument("[provider]", "The authentication provider.")
.description('Register a new authentication provider')
.action(add.action)

program.parse()

export { program }