├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── 1_bug.yml │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md └── stale.yml ├── .gitignore ├── LICENSE ├── README.md ├── commands ├── add.js ├── ask.js ├── index.js ├── init.js └── secret.js ├── index.js ├── lib ├── apple-gen-secret.js ├── detect.js ├── is-online.js ├── markdown.js ├── meta.js ├── pkg-manager.js └── write-env.js ├── package.json ├── pnpm-lock.yaml └── scripts └── generate-docs.js /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # https://docs.github.com/en/github/administering-a-repository/displaying-a-sponsor-button-in-your-repository 2 | 3 | open_collective: nextauth 4 | github: [balazsorban44, ThangHuuVu] 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/1_bug.yml: -------------------------------------------------------------------------------- 1 | name: Bug report 2 | description: Report an issue so we can improve 3 | labels: [triage, bug] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | **NOTE:** Issues that are potentially security related should be reported to us by following the [Security guidelines](https://next-auth.js.org/security) rather than on GitHub. 9 | Thanks for taking the time to fill out this issue after reading/searching through the [documentation](https://next-auth.js.org) first! 10 | Is this your first time contributing? Check out this video: https://www.youtube.com/watch?v=cuoNzXFLitc 11 | 12 | ### Important :exclamation: 13 | 14 | _Providing incorrect/insufficient information or skipping steps to reproduce the issue may result in closing the issue or converting to a discussion without further explanation._ 15 | 16 | If you have a generic question specific to your project, it is best asked in Discussions under the [Questions category](https://github.com/nextauthjs/next-auth/discussions/new?category=Questions) 17 | - type: textarea 18 | attributes: 19 | label: Environment 20 | description: | 21 | Run this command in your project's root folder and paste the result: 22 | 23 | `npx envinfo --system --binaries --browsers --npmPackages "{next,react,next-auth,@auth/*}"` 24 | 25 | Alternatively, you can manually gather the version information from your package.json for these packages: "next", "react" and "next-auth". Please also mention your OS and Node.js version, as well as the browser you are using. 26 | validations: 27 | required: true 28 | # Not sure how feasible it is to make reproduction URLs for a CLI :thinking: 29 | # - type: input 30 | # attributes: 31 | # label: Reproduction URL 32 | # description: A URL to a repository/code that clearly reproduces your issue. You can use our [`next-auth-example`](https://github.com/nextauthjs/next-auth-example) template repository to get started more easily, or link to your project if it's public 33 | # validations: 34 | # required: true 35 | - type: textarea 36 | attributes: 37 | label: Describe the issue 38 | description: Describe us what the issue is and what have you tried so far to fix it. Add any extra useful information in this section. Feel free to use screenshots (but prefer [code blocks](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#syntax-highlighting) over a picture of your code) or a video explanation. 39 | validations: 40 | required: true 41 | - type: textarea 42 | attributes: 43 | label: How to reproduce 44 | description: Explain with clear steps how to reproduce the issue 45 | validations: 46 | required: true 47 | - type: textarea 48 | attributes: 49 | label: Expected behavior 50 | description: Explain what should have happened instead of what actually happened 51 | validations: 52 | required: true 53 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Ask a question 4 | url: https://github.com/nextauthjs/next-auth/discussions/new?category=questions 5 | about: Ask questions and discuss with other community members 6 | - name: Feature request 7 | url: https://github.com/nextauthjs/next-auth/discussions/new?category=ideas 8 | about: Feature requests should be opened as discussions 9 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 13 | 14 | ## ☕️ Reasoning 15 | 16 | 17 | 18 | ## 🧢 Checklist 19 | 20 | - [ ] Documentation 21 | - [ ] Tests 22 | - [ ] Ready to be merged 23 | 24 | ## 🎫 Affected issues 25 | 26 | 31 | 32 | ## 📌 Resources 33 | 34 | - [Security guidelines](https://github.com/nextauthjs/.github/blob/main/SECURITY.md) 35 | - [Contributing guidelines](https://github.com/nextauthjs/.github/blob/main/CONTRIBUTING.md) 36 | - [Code of conduct](https://github.com/nextauthjs/.github/blob/main/CODE_OF_CONDUCT.md) 37 | - [Contributing to Open Source](https://kcd.im/pull-request) 38 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/probot/stale#usage 2 | 3 | daysUntilStale: 60 4 | daysUntilClose: 7 5 | exemptLabels: 6 | - pinned 7 | - security 8 | - priority 9 | - bug 10 | - triage 11 | - accepted 12 | staleLabel: stale 13 | markComment: > 14 | It looks like this issue did not receive any activity for 60 days. 15 | It will be closed in 7 days if no further activity occurs. If you think your issue 16 | is still relevant, commenting will keep it open. Thanks! 17 | closeComment: > 18 | To keep things tidy, we are closing this issue for now. 19 | If you think your issue is still relevant, leave a comment 20 | and we might reopen it. Thanks! 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | 132 | 133 | *.p8 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Auth.js 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | 4 |

Auth.js CLI

5 |

6 |

7 | The CLI tool by Auth.js to supercharge your authentication workflows. 8 |

9 |

10 | JavaScript 11 | Downloads 12 | npm latest release 13 | Github Stars 14 |

15 | 16 | ## Features 17 | 18 | - Natural language search to answer questions about Auth.js, docs, APIs, or general auth concepts 19 | - Initialize new projects with Auth.js for any of the supported frameworks 20 | - Guides you through adding authentication providers to your existing project 21 | - ... and more coming soon! 22 | 23 | ## Installation 24 | 25 | You don't need to install this package, run the following: 26 | 27 | ```sh 28 | npx auth # or pnpx, bunx, yarn dlx, etc. 29 | ``` 30 | 31 | ## Usage 32 | 33 | 34 | 35 | ``` 36 | Usage: auth [options] [command] 37 | 38 | Options: 39 | -V, --version output the version number 40 | -h, --help display help for command 41 | 42 | Commands: 43 | ask [options] Ask about docs, API, or auth concepts. 44 | init [options] [framework] Initialize a project. 45 | secret [options] Generate a random string and add it to the .env 46 | file. 47 | add [provider] Register a new authentication provider 48 | help [command] display help for command 49 | ``` 50 | 51 | 52 | 53 | ## Security 54 | 55 | If you think you have found a vulnerability (or are not sure) in Auth.js or any of the related packages (i.e. Adapters), we ask you to read our [Security Policy](https://authjs.dev/security) to reach out responsibly. Please do not open Pull Requests/Issues/Discussions before consulting with us. 56 | 57 | ## Acknowledgements 58 | 59 | Special thanks to Craig for the `auth` package name on npm. 60 | 61 | ### Sponsors 62 | 63 | We have an [OpenCollective](https://opencollective.com/nextauth) for companies and individuals looking to contribute financially to the project! 64 | 65 | 66 | 67 | 68 | 69 | 76 | 83 | 90 | 97 | 104 | 111 | 112 | 113 | 120 | 127 | 134 | 141 | 148 | 155 | 156 | 157 | 164 | 171 | 178 | 179 | 180 |
70 | 71 | Clerk Logo 72 |
73 |
Clerk
74 | 💵 75 |
77 | 78 | Auth0 Logo 79 |
80 |
Auth0
81 | 💵 82 |
84 | 85 | FusionAuth Logo 86 |
87 |
FusionAuth
88 | 💵 89 |
91 | 92 | Beyond Identity Logo 93 |
94 |
Beyond Identity
95 | 💵 96 |
98 | 99 | Stytch Logo 100 |
101 |
Stytch
102 | 💵 103 |
105 | 106 | Prisma Logo 107 |
108 |
Prisma
109 | 💵 110 |
114 | 115 | Lowdefy Logo 116 |
117 |
Lowdefy
118 | 💵 119 |
121 | 122 | Descope Logo 123 |
124 |
Descope
125 | 💵 126 |
128 | 129 | Badass Courses Logo 130 |
131 |
Badass Courses
132 | 💵 133 |
135 | 136 | Encore Logo 137 |
138 |
Encore
139 | 💵 140 |
142 | 143 | Arcjet Logo 144 |
145 |
Arcjet
146 | 💵 147 |
149 | 150 | Netlight logo 151 |
152 |
Netlight
153 | ☁️ 154 |
158 | 159 | Checkly Logo 160 |
161 |
Checkly
162 | ☁️ 163 |
165 | 166 | superblog Logo 167 |
168 |
superblog
169 | ☁️ 170 |
172 | 173 | Vercel Logo 174 |
175 |
Vercel
176 | ☁️ 177 |
181 | 182 | - 💵 Financial Sponsor 183 | - ☁️ Infrastructure Support 184 | 185 |
186 | 187 | 188 | ## Contributing 189 | 190 | We're open to all community contributions! If you'd like to contribute in any way, please first read 191 | our [Contributing Guide](https://github.com/nextauthjs/.github/blob/main/CONTRIBUTING.md). 192 | 193 | ## License 194 | 195 | MIT 196 | -------------------------------------------------------------------------------- /commands/add.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import * as y from "yoctocolors" 4 | import open from "open" 5 | import clipboard from "clipboardy" 6 | import { select, input, password, number } from "@inquirer/prompts" 7 | import { requireFramework } from "../lib/detect.js" 8 | import { updateEnvFile } from "../lib/write-env.js" 9 | import { providers, frameworks } from "../lib/meta.js" 10 | import { link, markdownToAnsi } from "../lib/markdown.js" 11 | import { appleGenSecret } from "../lib/apple-gen-secret.js" 12 | 13 | /** 14 | * @param {string} label 15 | * @param {string} [defaultValue] 16 | */ 17 | async function promptInput(label, defaultValue) { 18 | return input({ 19 | message: `Paste ${y.magenta(label)}:`, 20 | validate: (value) => !!value, 21 | default: defaultValue, 22 | }) 23 | } 24 | 25 | /** @param {string} label */ 26 | async function promptPassword(label) { 27 | return password({ 28 | message: `Paste ${y.magenta(label)}:`, 29 | mask: true, 30 | validate: (value) => !!value, 31 | }) 32 | } 33 | 34 | const choices = Object.entries(providers) 35 | .filter(([, { setupUrl }]) => !!setupUrl) 36 | .map(([value, { name }]) => ({ name, value })) 37 | 38 | /** @param {string | undefined} providerId */ 39 | export async function action(providerId) { 40 | try { 41 | providerId ??= await select({ 42 | message: "What provider do you want to set up?", 43 | choices: choices, 44 | }) 45 | 46 | const provider = providers[providerId] 47 | if (!provider?.setupUrl) { 48 | console.error( 49 | y.red( 50 | `Missing instructions for ${ 51 | provider?.name ?? providerId 52 | }.\nInstructions are available for: ${y.bold( 53 | choices.map((choice) => choice.name).join(", ") 54 | )}` 55 | ) 56 | ) 57 | return 58 | } 59 | 60 | const frameworkId = await requireFramework() 61 | const framework = frameworks[frameworkId] 62 | 63 | console.log( 64 | y.dim( 65 | `Setting up OAuth provider in your ${framework.name} app (${link( 66 | "more info", 67 | "https://authjs.dev/getting-started/authentication/oauth" 68 | )})...\n` 69 | ) 70 | ) 71 | 72 | const url = new URL( 73 | `${framework.path}/callback/${providerId}`, 74 | `http://localhost:${framework.port}` 75 | ) 76 | 77 | clipboard.writeSync(url.toString()) 78 | console.log( 79 | `\ 80 | ${y.bold("Setup URL")}: ${provider.setupUrl} 81 | ${y.bold("Callback URL (copied to clipboard)")}: ${url}` 82 | ) 83 | 84 | console.log("_________________________") 85 | if (provider.instructions) { 86 | console.log(y.dim("\nFollow the instructions:\n")) 87 | console.log(markdownToAnsi(provider.instructions)) 88 | } 89 | console.log( 90 | y.dim( 91 | `\nProvider documentation: https://providers.authjs.dev/${providerId}\n` 92 | ) 93 | ) 94 | console.log("‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾") 95 | console.log(y.dim("Opening setup URL in your browser...\n")) 96 | await new Promise((resolve) => setTimeout(resolve, 3000)) 97 | 98 | await open(provider.setupUrl) 99 | 100 | if (providerId === "apple") { 101 | const clientId = await promptInput("Client ID") 102 | const keyId = await promptInput("Key ID") 103 | const teamId = await promptInput("Team ID") 104 | const privateKey = await input({ 105 | message: "Path to Private Key", 106 | validate: (value) => !!value, 107 | default: "./private-key.p8", 108 | }) 109 | 110 | const expiresInDays = 111 | (await number({ 112 | message: "Expires in days (default: 180)", 113 | required: false, 114 | default: 180, 115 | })) ?? 180 116 | 117 | console.log(y.dim("Updating environment variable file...")) 118 | 119 | await updateEnvFile({ AUTH_APPLE_ID: clientId }) 120 | 121 | const secret = await appleGenSecret({ 122 | teamId, 123 | clientId, 124 | keyId, 125 | privateKey, 126 | expiresInDays, 127 | }) 128 | 129 | await updateEnvFile({ AUTH_APPLE_SECRET: secret }) 130 | } else { 131 | const clientId = await promptInput("Client ID") 132 | const clientSecret = await promptPassword("Client Secret") 133 | 134 | console.log(y.dim("Updating environment variable file...")) 135 | 136 | const varPrefix = `AUTH_${providerId.toUpperCase()}` 137 | await updateEnvFile({ 138 | [`${varPrefix}_ID`]: clientId, 139 | [`${varPrefix}_SECRET`]: clientSecret, 140 | }) 141 | } 142 | 143 | console.log("\n🎉 Done! You can now use this provider in your app.") 144 | } catch (error) { 145 | if (!(error instanceof Error)) return 146 | if (error.message.startsWith("User force closed")) return 147 | throw error 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /commands/ask.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import * as y from "yoctocolors" 4 | import { input } from "@inquirer/prompts" 5 | import { InkeepAI } from "@inkeep/ai-api" 6 | import { ChatModeOptions } from "@inkeep/ai-api/models/components/index.js" 7 | import * as ora from "ora" 8 | import { link, markdownToAnsi, breakStringToLines } from "../lib/markdown.js" 9 | 10 | const INKEEP_API_KEY = "e32967a320a48a2cd933922099e1f38f6ebb4ab62ff98343" 11 | const INKEEP_INTEGRATION_ID = "clvn0fdez000cip0e5w2oaobw" 12 | 13 | const inkeepAI = new InkeepAI({ apiKey: INKEEP_API_KEY }) 14 | 15 | function randomSpinner() { 16 | const allSpinners = Object.keys(ora.spinners) 17 | const max = allSpinners.length - 1 18 | const random = Math.floor(Math.random() * (max + 1)) 19 | return allSpinners[random] 20 | } 21 | 22 | export async function action({ stream = false, raw = false }) { 23 | const format = raw ? (i) => i : markdownToAnsi 24 | const newLocal = randomSpinner() 25 | const spinner = ora.default({ 26 | text: "Understanding question", 27 | // @ts-expect-error 28 | spinner: newLocal, 29 | }) 30 | try { 31 | const content = await input({ message: "What would you like to know: " }) 32 | 33 | spinner.start() 34 | 35 | const result = await inkeepAI.chatSession.create({ 36 | integrationId: INKEEP_INTEGRATION_ID, 37 | stream, 38 | chatSession: { messages: [{ content, role: "user" }] }, 39 | chatMode: ChatModeOptions.Auto, 40 | }) 41 | 42 | if (stream) { 43 | if (result.chatResultStream == null) { 44 | throw new Error("failed to create stream: received null value") 45 | } 46 | 47 | spinner.stop().clear() 48 | 49 | for await (const event of result.chatResultStream) { 50 | if (event.event === "message_chunk") { 51 | const content = format(event.data.contentChunk) 52 | process.stdout.write(content) 53 | } 54 | } 55 | } else { 56 | const answer = result.chatResult?.message.content 57 | if (!answer) return console.error(y.red("Could not get an answer.")) 58 | 59 | console.log(breakStringToLines(format(answer), 80)) 60 | } 61 | 62 | console.log( 63 | y.italic( 64 | `\n\nAnswered by ${y.cyan( 65 | link("Inkeep AI", "https://inkeep.com") 66 | )}. Check out the official ${y.magenta( 67 | link("Auth.js", "https://authjs.dev") 68 | )} docs.` 69 | ) 70 | ) 71 | } catch (e) { 72 | spinner.stop().clear() 73 | if (!(e instanceof Error)) return 74 | if (e.message.startsWith("User force closed")) return 75 | 76 | console.error(y.red(e.stack ?? e.message)) 77 | console.error( 78 | y.bold( 79 | y.red( 80 | `\n This is a bug. Please report it on ${link( 81 | "GitHub", 82 | "https://github.com/nextauthjs/auth-cli/issues" 83 | )}.` 84 | ) 85 | ) 86 | ) 87 | } finally { 88 | spinner.stop().clear() 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /commands/index.js: -------------------------------------------------------------------------------- 1 | export * as ask from "./ask.js" 2 | export * as init from "./init.js" 3 | export * as secret from "./secret.js" 4 | export * as add from './add.js' 5 | -------------------------------------------------------------------------------- /commands/init.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import { execSync } from "node:child_process" 3 | import { input, confirm, select, checkbox } from "@inquirer/prompts" 4 | import * as y from "yoctocolors" 5 | import { action as secretAction } from "./secret.js" 6 | 7 | import { getPkgManager, install } from "../lib/pkg-manager.js" 8 | import * as meta from "../lib/meta.js" 9 | import { updateEnvFile } from "../lib/write-env.js" 10 | import { mkdir } from "node:fs/promises" 11 | 12 | /** 13 | * @param {string} framework 14 | * @param {{example?: boolean}} options 15 | * @returns 16 | */ 17 | export async function action(framework, options) { 18 | try { 19 | if (!framework) { 20 | framework = await select({ 21 | message: "Select a framework", 22 | choices: Object.entries(meta.frameworks).map(([key, value]) => ({ 23 | name: `${value.name} ${y.dim(`(${key})`)}`, 24 | value: key, 25 | })), 26 | }) 27 | } 28 | 29 | const dir = await input({ 30 | message: "Name of the project", 31 | default: `my-${framework}-app`, 32 | }) 33 | 34 | if (options.example) await createFromExample(framework, dir) 35 | 36 | const providers = await checkbox({ 37 | instructions: false, 38 | message: "Select one or multiple providers", 39 | choices: Object.entries(meta.providers).map(([value, { name }]) => ({ 40 | name, 41 | value, 42 | })), 43 | }) 44 | 45 | /** @type {string|undefined} */ 46 | let adapter = await select({ 47 | default: "none", 48 | message: "Select a database adapter", 49 | choices: Object.entries(meta.adapters).map(([value, name]) => ({ 50 | name, 51 | value, 52 | })), 53 | }) 54 | adapter = adapter === "none" ? undefined : adapter 55 | 56 | await scaffoldProject({ framework, dir, providers, adapter }) 57 | } catch (e) { 58 | if (!(e instanceof Error)) return 59 | if (e.message.startsWith("User force closed")) return 60 | 61 | console.error(y.red(e.message)) 62 | } 63 | } 64 | 65 | /** 66 | * @param {string} framework 67 | * @param {string} dir 68 | */ 69 | async function createFromExample(framework, dir) { 70 | const { src, demo } = meta.frameworks[framework] 71 | execSync(`git clone ${src} ${dir}`) 72 | if ( 73 | await confirm({ 74 | message: "Initiailze .env with `AUTH_SECRET`", 75 | default: true, 76 | }) 77 | ) { 78 | execSync(`cd ${dir}`) 79 | await secretAction({ path: dir }) 80 | } 81 | 82 | await install() 83 | 84 | console.log(` 85 | Project ${y.italic(`\`${dir}\``)} has been created. 86 | Source code: ${src} 87 | Deployed demo: ${demo}`) 88 | } 89 | 90 | /** 91 | * @param {{framework: string, dir: string, providers: string[], adapter?: string}} options 92 | */ 93 | async function scaffoldProject(options) { 94 | const { framework, providers, dir, adapter } = options 95 | const pkgManager = getPkgManager() 96 | console.log( 97 | `Scaffolding ${y.bold(framework)} project with ${y.bold( 98 | pkgManager 99 | )} at ${y.bold(dir)}...` 100 | ) 101 | throw new Error("Scaffolding not implemented. Please use `init --example`") 102 | console.log(`Create directory ${dir}`) 103 | await mkdir(dir) 104 | console.log(`Change directory to ${dir}`) 105 | execSync(`cd ${dir}`) 106 | console.log(`Initialize ${pkgManager} project`) 107 | execSync(`${pkgManager} init`) 108 | // console.log(`Add ${framework} to ${pkgManager}`) 109 | // execSync(`${pkgManager} install ${framework}`) 110 | for (const provider of providers) { 111 | const id = `AUTH_${provider.toUpperCase()}_ID` 112 | const secret = `AUTH_${provider.toUpperCase()}_SECRET` 113 | await updateEnvFile( 114 | { 115 | [id]: "", 116 | [secret]: "", 117 | }, 118 | dir 119 | ) 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /commands/secret.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import * as y from "yoctocolors" 4 | import clipboard from "clipboardy" 5 | import { detectFramework } from "../lib/detect.js" 6 | import { updateEnvFile } from "../lib/write-env.js" 7 | 8 | /** Web compatible method to create a random string of a given length */ 9 | function randomString(size = 32) { 10 | const bytes = crypto.getRandomValues(new Uint8Array(size)) 11 | // @ts-expect-error 12 | return Buffer.from(bytes, "base64").toString("base64") 13 | } 14 | 15 | /** 16 | * @param {{ 17 | * copy?: boolean 18 | * path?: string 19 | * raw?: boolean 20 | * }} options 21 | */ 22 | export async function action(options) { 23 | const key = "AUTH_SECRET" 24 | const value = randomString() 25 | if (options.raw) return console.log(value) 26 | 27 | const line = `${key}="${value}"` 28 | const message = { 29 | introClipboard: 30 | "Secret generated. It has been copied to your clipboard, paste it to your .env/.env.local file to continue.", 31 | introCopy: 32 | "Secret generated. Copy it to your .env/.env.local file (depending on your framework):", 33 | value: `\n${line}`, 34 | } 35 | 36 | if (options.copy) { 37 | try { 38 | clipboard.writeSync(line) 39 | console.log(message.introClipboard) 40 | } catch (error) { 41 | console.error(y.red(error)) 42 | console.log(message.introCopy) 43 | } finally { 44 | console.log(message.value) 45 | process.exit(0) 46 | } 47 | } 48 | 49 | try { 50 | const framework = await detectFramework(options.path) 51 | if (framework === "unknown") { 52 | return console.log(value) 53 | } 54 | await updateEnvFile({ [key]: value }, options.path) 55 | } catch (error) { 56 | console.error(y.red(error)) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | // @ts-check 4 | 5 | import { Command } from "commander" 6 | import * as y from "yoctocolors" 7 | import { ask, init, secret, add } from "./commands/index.js" 8 | 9 | // import pkg from "./package.json" assert { type: "json" } 10 | 11 | import fs from "node:fs/promises" 12 | import { join } from "node:path" 13 | import { fileURLToPath } from "node:url" 14 | 15 | const __dirname = fileURLToPath(new URL(".", import.meta.url)) 16 | const pkg = JSON.parse( 17 | await fs.readFile(join(__dirname, "./package.json"), "utf-8") 18 | ) 19 | const { name, description, version } = pkg 20 | 21 | try { 22 | // TODO: Remove when Node.js 18 is not maintained anymore 23 | // @ts-expect-error 24 | globalThis.crypto ??= (await import("crypto")).webcrypto 25 | } catch {} 26 | 27 | const program = new Command() 28 | 29 | program 30 | .name(name) 31 | .description(description.replace("Auth.js", y.magenta(y.bold("Auth.js")))) 32 | .version(version) 33 | 34 | program 35 | .command("ask") 36 | .option("--stream", "Stream the response.") 37 | .option("--raw", "Show the Markdown response without formatting.") 38 | .description("Ask about docs, API, or auth concepts.") 39 | .action(ask.action) 40 | 41 | program 42 | .command("init") 43 | .argument("[framework]", "The framework to use.") 44 | .option("-e, --example", "Clone a full example.") 45 | .description("Initialize a project.") 46 | .action(init.action) 47 | 48 | program 49 | .command("secret") 50 | .option("--raw", "Output the string without any formatting.") 51 | .option("--copy", 'Copy AUTH_SECRET="value".') 52 | .description("Generate a random string and add it to the .env file.") 53 | .action(secret.action) 54 | 55 | program 56 | .command("add") 57 | .argument("[provider]", "The authentication provider.") 58 | .description("Register a new authentication provider") 59 | .action(add.action) 60 | 61 | program.parse() 62 | 63 | export { program } 64 | -------------------------------------------------------------------------------- /lib/apple-gen-secret.js: -------------------------------------------------------------------------------- 1 | import fs from "node:fs" 2 | import path from "node:path" 3 | import * as y from "yoctocolors" 4 | 5 | /** 6 | * Generates an Apple client secret. 7 | * 8 | * @param {object} options 9 | * @param {string} options.teamId - Apple Team ID. 10 | * @param {string} options.clientId - Apple Client ID. 11 | * @param {string} options.keyId - Apple Key ID. 12 | * @param {string} options.privateKey - Apple Private Key. 13 | * @param {number} options.expiresInDays - Days until the secret expires. 14 | * 15 | * @see https://developer.apple.com/documentation/accountorganizationaldatasharing/creating-a-client-secret 16 | */ 17 | export async function appleGenSecret({ 18 | teamId: iss, 19 | clientId: sub, 20 | keyId: kid, 21 | privateKey, 22 | expiresInDays, 23 | }) { 24 | const expiresIn = 86400 * expiresInDays 25 | const exp = Math.ceil(Date.now() / 1000) + expiresIn 26 | 27 | const secret = await signJWT(sub, iss, kid, privateKey, exp) 28 | 29 | console.log( 30 | y.green( 31 | `Apple client secret generated. Valid until: ${new Date(exp * 1000)}` 32 | ) 33 | ) 34 | 35 | return secret 36 | } 37 | 38 | /** 39 | * 40 | * @param {string} sub - Apple client ID. 41 | * @param {string} iss - Apple team ID. 42 | * @param {string} kid - Apple key ID. 43 | * @param {string} privateKeyPath - Apple private key. 44 | * @param {Date} exp - Expiry date. 45 | */ 46 | async function signJWT(sub, iss, kid, privateKeyPath, exp) { 47 | const header = { alg: "ES256", kid } 48 | 49 | const payload = { 50 | iss, 51 | iat: Date.now() / 1000, 52 | exp, 53 | aud: "https://appleid.apple.com", 54 | sub, 55 | } 56 | 57 | const parts = [ 58 | toBase64Url(encoder.encode(JSON.stringify(header))), 59 | toBase64Url(encoder.encode(JSON.stringify(payload))), 60 | ] 61 | 62 | const privateKey = fs 63 | .readFileSync(path.resolve(privateKeyPath), "utf8") 64 | .replace(/-----BEGIN PRIVATE KEY-----|\n|-----END PRIVATE KEY-----/g, "") 65 | 66 | const signature = await sign(parts.join("."), privateKey) 67 | 68 | parts.push(toBase64Url(signature)) 69 | return parts.join(".") 70 | } 71 | 72 | const encoder = new TextEncoder() 73 | function toBase64Url(data) { 74 | return btoa(String.fromCharCode(...new Uint8Array(data))) 75 | .replace(/\+/g, "-") 76 | .replace(/\//g, "_") 77 | .replace(/=+$/, "") 78 | } 79 | 80 | async function sign(data, private_key) { 81 | const pem = private_key.replace( 82 | /-----BEGIN PRIVATE KEY-----|\n|-----END PRIVATE KEY-----/g, 83 | "" 84 | ) 85 | const binaryDerString = atob(pem) 86 | const binaryDer = new Uint8Array( 87 | [...binaryDerString].map((char) => char.charCodeAt(0)) 88 | ) 89 | 90 | const privateKey = await globalThis.crypto.subtle.importKey( 91 | "pkcs8", 92 | binaryDer.buffer, 93 | { name: "ECDSA", namedCurve: "P-256" }, 94 | true, 95 | ["sign"] 96 | ) 97 | 98 | return await globalThis.crypto.subtle.sign( 99 | { name: "ECDSA", hash: { name: "SHA-256" } }, 100 | privateKey, 101 | encoder.encode(data) 102 | ) 103 | } 104 | -------------------------------------------------------------------------------- /lib/detect.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import { readFile } from "node:fs/promises" 3 | import { join } from "node:path" 4 | import { frameworks } from "../lib/meta.js" 5 | import * as y from "yoctocolors" 6 | 7 | /** 8 | * When this function runs in a framework directory we support, 9 | * it will return the framework's name 10 | * @param {string} path 11 | * @returns {Promise} 12 | */ 13 | export async function detectFramework(path = "") { 14 | const dir = process.cwd() 15 | const packageJsonPath = join(dir, path, "package.json") 16 | try { 17 | const packageJson = JSON.parse(await readFile(packageJsonPath, "utf-8")) 18 | 19 | /** @type {import("./meta").SupportedFramework[]} */ 20 | const foundFrameworks = [] 21 | 22 | if (packageJson?.dependencies?.["next"]) foundFrameworks.push("next") 23 | if (packageJson?.dependencies?.["express"]) foundFrameworks.push("express") 24 | if (packageJson?.devDependencies?.["@sveltejs/kit"]) 25 | foundFrameworks.push("sveltekit") 26 | 27 | if (foundFrameworks.length === 1) return foundFrameworks[0] 28 | 29 | if (foundFrameworks.length > 1) { 30 | console.error( 31 | `Multiple supported frameworks detected: ${foundFrameworks.join(", ")}` 32 | ) 33 | return "unknown" 34 | } 35 | return "unknown" 36 | } catch (error) { 37 | console.error(error) 38 | return "unknown" 39 | } 40 | } 41 | 42 | export async function requireFramework(path = "") { 43 | const framework = await detectFramework(path) 44 | 45 | if (framework === "unknown") { 46 | console.error( 47 | y.red( 48 | `No framework detected. Currently supported frameworks are: ${y.bold( 49 | Object.keys(frameworks).join(", ") 50 | )}` 51 | ) 52 | ) 53 | 54 | process.exit(0) 55 | } 56 | 57 | return framework 58 | } 59 | -------------------------------------------------------------------------------- /lib/is-online.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { execSync } from "node:child_process" 4 | import dns from "node:dns/promises" 5 | 6 | function getProxy() { 7 | if (process.env.https_proxy) { 8 | return process.env.https_proxy 9 | } 10 | 11 | try { 12 | const httpsProxy = execSync("npm config get https-proxy").toString().trim() 13 | return httpsProxy !== "null" ? httpsProxy : undefined 14 | } catch (e) { 15 | return 16 | } 17 | } 18 | 19 | export async function getOnline() { 20 | try { 21 | await dns.lookup("registry.yarnpkg.com") 22 | // If DNS lookup succeeds, we are online 23 | return true 24 | } catch { 25 | // The DNS lookup failed, but we are still fine as long as a proxy has been set 26 | const proxy = getProxy() 27 | if (!proxy) { 28 | return false 29 | } 30 | 31 | const { hostname } = new URL(proxy) 32 | if (!hostname) { 33 | // Invalid proxy URL 34 | return false 35 | } 36 | 37 | try { 38 | await dns.lookup(hostname) 39 | // If DNS lookup succeeds for the proxy server, we are online 40 | return true 41 | } catch { 42 | // The DNS lookup for the proxy server also failed, so we are offline 43 | return false 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /lib/markdown.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | import * as y from "yoctocolors" 3 | 4 | // double char markdown matchers 5 | const BOLD_REGEX = /\*{2}([^*]+)\*{2}/g 6 | const UNDERLINE_REGEX = /_{2}([^_]+)_{2}/g 7 | const STRIKETHROUGH_REGEX = /~{2}([^~]+)~{2}/g 8 | const LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g 9 | 10 | // single char markdown matchers 11 | const ITALIC_REGEX = /(? y.bold(args[1])) 23 | input = input.replace(UNDERLINE_REGEX, (...args) => y.underline(args[1])) 24 | input = input.replace(STRIKETHROUGH_REGEX, (...args) => 25 | y.strikethrough(args[1]) 26 | ) 27 | input = input.replace(ITALIC_REGEX, (...args) => y.italic(args[1] || args[2])) 28 | input = input.replace(/(? 32 | y.blue(" " + link(args[2], args[1])) 33 | ) 34 | return input 35 | } 36 | 37 | /** 38 | * @param {string} str 39 | * @param {number} maxLineLength 40 | * @returns {string} 41 | */ 42 | export function breakStringToLines(str, maxLineLength) { 43 | let result = "" 44 | let line = "" 45 | 46 | str.split(" ").forEach((word) => { 47 | if (line.length + word.length + 1 > maxLineLength) { 48 | result += line + "\n" 49 | line = word 50 | } else { 51 | if (line) line += " " 52 | line += word 53 | } 54 | }) 55 | 56 | if (line) result += line 57 | 58 | return result 59 | } 60 | -------------------------------------------------------------------------------- /lib/meta.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | // TODO: Get these programmatically 4 | 5 | /** 6 | * @typedef {"next" | "express" | "sveltekit"} SupportedFramework 7 | */ 8 | 9 | export const frameworks = { 10 | next: { 11 | name: "Next.js", 12 | src: "https://github.com/nextauthjs/next-auth-example", 13 | demo: "https://next-auth-example.vercel.app", 14 | path: "/api/auth", 15 | port: 3000, 16 | envFile: ".env.local", 17 | }, 18 | sveltekit: { 19 | name: "SvelteKit", 20 | src: "https://github.com/nextauthjs/sveltekit-auth-example", 21 | demo: "https://sveltekit-auth-example.vercel.app", 22 | path: "/auth", 23 | port: 5173, 24 | envFile: ".env", 25 | }, 26 | express: { 27 | name: "Express", 28 | src: "https://github.com/nextauthjs/express-auth-example", 29 | demo: "https://express-auth-example.vercel.app", 30 | path: "/auth", 31 | port: 3000, 32 | envFile: ".env", 33 | }, 34 | } 35 | 36 | export const providers = { 37 | "42-school": { name: "42 School", setupUrl: undefined }, 38 | apple: { 39 | name: "Apple", 40 | setupUrl: 41 | "https://developer.apple.com/account/resources/identifiers/list/serviceId", 42 | }, 43 | asgardeo: { name: "Asgardeo", setupUrl: undefined }, 44 | auth0: { name: "Auth0", setupUrl: undefined }, 45 | authentik: { name: "Authentik", setupUrl: undefined }, 46 | "azure-ad-b2c": { name: "Azure AD B2C", setupUrl: undefined }, 47 | "azure-ad": { name: "Azure AD", setupUrl: undefined }, 48 | "azure-devops": { name: "Azure DevOps", setupUrl: undefined }, 49 | battlenet: { name: "Battlenet", setupUrl: undefined }, 50 | beyondidentity: { name: "Beyond Identity", setupUrl: undefined }, 51 | box: { name: "Box", setupUrl: undefined }, 52 | "boxyhq-saml": { name: "Boxyhq SAML", setupUrl: undefined }, 53 | bungie: { name: "Bungie", setupUrl: undefined }, 54 | "click-up": { name: "Click-up", setupUrl: undefined }, 55 | cognito: { name: "Cognito", setupUrl: undefined }, 56 | coinbase: { name: "Coinbase", setupUrl: undefined }, 57 | credentials: { name: "Credentials", setupUrl: undefined }, 58 | descope: { name: "Descope", setupUrl: undefined }, 59 | discord: { 60 | name: "Discord", 61 | setupUrl: "https://discord.com/developers/applications", 62 | instructions: `\ 63 | 1. Click on *New Application* 64 | 2. Set *Application name* (can be anything) 65 | 3. Click on *OAuth2* in the side menu 66 | 4. Click on *Add Redirect* and paste the callback URI (on your clipboard) 67 | 5. Click on *Save Changes* 68 | 6. Copy and paste the *Client ID* 69 | 7. Copy and paste the *Client Secret* 70 | `, 71 | }, 72 | dribbble: { name: "Dribbble", setupUrl: undefined }, 73 | dropbox: { name: "Dropbox", setupUrl: undefined }, 74 | "duende-identity-server6": { 75 | name: "Duende Identity Server 6", 76 | setupUrl: undefined, 77 | }, 78 | email: { name: "Email", setupUrl: undefined }, 79 | eveonline: { name: "Eveonline", setupUrl: undefined }, 80 | facebook: { name: "Facebook", setupUrl: undefined }, 81 | faceit: { name: "Faceit", setupUrl: undefined }, 82 | foursquare: { name: "Foursquare", setupUrl: undefined }, 83 | freshbooks: { name: "Freshbooks", setupUrl: undefined }, 84 | fusionauth: { name: "FusionAuth", setupUrl: undefined }, 85 | github: { 86 | name: "GitHub", 87 | setupUrl: "https://github.com/settings/applications/new", 88 | instructions: `\ 89 | 1. Set *Application name* (can be anything) 90 | 2. Set *Homepage URL* (your business/website, but can be anything) 91 | 3. Paste the redirect URI (on your clipboard) to *Authorization callback URL* 92 | 4. Click *Register application* 93 | 5. Paste the *Client ID* back here 94 | 6. Click *Generate a new client secret* 95 | 7. Paste the *Client secret* back here (Note: This is the only time you can see it)`, 96 | }, 97 | gitlab: { name: "GitLab", setupUrl: undefined }, 98 | google: { 99 | name: "Google", 100 | setupUrl: "https://console.cloud.google.com/apis/credentials/oauthclient", 101 | instructions: `\ 102 | 1. Choose *Application Type: Web Application* 103 | 2. Paste the redirect URI (on your clipboard) to *Authorized redirect URIs* 104 | 3. Fill out the rest of the form 105 | 4. Click *Create*`, 106 | }, 107 | hubspot: { name: "Hubspot", setupUrl: undefined }, 108 | "identity-server4": { name: "Identity Server 4", setupUrl: undefined }, 109 | instagram: { name: "Instagram", setupUrl: undefined }, 110 | kakao: { name: "Kakao", setupUrl: undefined }, 111 | keycloak: { name: "Keycloak", setupUrl: undefined }, 112 | line: { name: "Line", setupUrl: undefined }, 113 | linkedin: { 114 | name: "LinkedIn", 115 | setupUrl: "https://linkedin.com/developers/apps", 116 | instructions: `\ 117 | 0. Prerequisites: You are required to have a LinkedIn page that will be 118 | associated with your authentication app. 119 | 1. Click on *Create app* 120 | 2. Set *App name* (can be anything) 121 | 3. Create a *LinkedIn page* (Skip this step if you already have one) 122 | 4. Set *LinkedIn Page URL* (LinkedIn page you created) 123 | 5. Set *App logo* (can be anything) 124 | 6. Navigate to *Auth* in the top menu 125 | 7. Scroll down to *OAuth 2.0 settings* 126 | 8. Under *Authorized redirect URLs for your app* paste the callback URI (on your clipboard) 127 | 9. Scroll back up 128 | 10. Copy and paste the *Client ID* 129 | 11. Copy and paste the *Primary Client Secret* 130 | `, 131 | }, 132 | mailchimp: { name: "Mailchimp", setupUrl: undefined }, 133 | mailru: { name: "Mail.ru", setupUrl: undefined }, 134 | mastodon: { name: "Mastodon", setupUrl: undefined }, 135 | mattermost: { name: "Mattermost", setupUrl: undefined }, 136 | medium: { name: "Medium", setupUrl: undefined }, 137 | "microsoft-entra-id": { name: "Microsoft Entra ID", setupUrl: undefined }, 138 | naver: { name: "Naver", setupUrl: undefined }, 139 | netlify: { name: "Netlify", setupUrl: undefined }, 140 | netsuite: { name: "Netsuite", setupUrl: undefined }, 141 | nodemailer: { name: "Nodemailer", setupUrl: undefined }, 142 | notion: { name: "Notion", setupUrl: undefined }, 143 | okta: { name: "Okta", setupUrl: undefined }, 144 | onelogin: { name: "Onelogin", setupUrl: undefined }, 145 | "ory-hydra": { name: "Ory Hydra", setupUrl: undefined }, 146 | osso: { name: "Osso", setupUrl: undefined }, 147 | osu: { name: "Osu", setupUrl: undefined }, 148 | passage: { name: "Passage", setupUrl: undefined }, 149 | passkey: { name: "Passkey", setupUrl: undefined }, 150 | patreon: { name: "Patreon", setupUrl: undefined }, 151 | pinterest: { name: "Pinterest", setupUrl: undefined }, 152 | pipedrive: { name: "Pipedrive", setupUrl: undefined }, 153 | postmark: { name: "Postmark", setupUrl: undefined }, 154 | reddit: { name: "Reddit", setupUrl: undefined }, 155 | resend: { name: "Resend", setupUrl: undefined }, 156 | salesforce: { name: "Salesforce", setupUrl: undefined }, 157 | sendgrid: { name: "Sendgrid", setupUrl: undefined }, 158 | slack: { name: "Slack", setupUrl: undefined }, 159 | spotify: { name: "Spotify", setupUrl: undefined }, 160 | strava: { name: "Strava", setupUrl: undefined }, 161 | tiktok: { name: "Tiktok", setupUrl: undefined }, 162 | todoist: { name: "Todoist", setupUrl: undefined }, 163 | trakt: { name: "Trakt", setupUrl: undefined }, 164 | twitch: { name: "Twitch", setupUrl: undefined }, 165 | twitter: { 166 | name: "Twitter", 167 | setupUrl: "https://developer.x.com/en/portal/dashboard", 168 | instructions: `\ 169 | 1. Create a project 170 | 2. Set the *Project name* (can be anything) 171 | 3. Choose a use case, then click Next 172 | 4. Give it a description, then click Next 173 | 5. An app will be created for you 174 | 6. Set the app name 175 | 7. Click on *App Settings* 176 | 8. Click *Set up* under *User authentication settings* 177 | 9. Select *Web App, Automated App or Bot* at "Type of app" 178 | 10. Add the callback URI (on your clipboard) to *Callback URLs* 179 | 11. Fill out the other required fields (your website) 180 | 12. Copy and paste the *Client ID* 181 | 13. Copy and paste the *Client Secret* 182 | 14. Click *Done*`, 183 | }, 184 | "united-effects": { name: "United Effects", setupUrl: undefined }, 185 | vk: { name: "Vk", setupUrl: undefined }, 186 | webex: { name: "Webex", setupUrl: undefined }, 187 | wikimedia: { name: "Wikimedia", setupUrl: undefined }, 188 | wordpress: { name: "Wordpress", setupUrl: undefined }, 189 | workos: { name: "WorkOS", setupUrl: undefined }, 190 | yandex: { name: "Yandex", setupUrl: undefined }, 191 | zitadel: { name: "Zitadel", setupUrl: undefined }, 192 | zoho: { name: "Zoho", setupUrl: undefined }, 193 | zoom: { name: "Zoom", setupUrl: undefined }, 194 | } 195 | 196 | export const adapters = { 197 | none: "None", 198 | "adapter-azure-tables": "Azure Tables", 199 | d1: "d1", 200 | dgraph: "Dgraph", 201 | drizzle: "Drizzle", 202 | dynamodb: "DynamoDB", 203 | edgedb: "EdgeDB", 204 | fauna: "Fauna", 205 | firebase: "Firebase", 206 | hasura: "Hasura", 207 | kysely: "Kysely", 208 | "mikro-orm": "MikroORM", 209 | mongodb: "MongoDB", 210 | neo4j: "Neo4j", 211 | pg: "PostgreSQL", 212 | pouchdb: "PouchDB", 213 | prisma: "Prisma", 214 | sequelize: "Sequelize", 215 | supabase: "Supabase", 216 | surrealdb: "SurrealDB", 217 | typeorm: "TypeORM", 218 | unstorage: "Unstorage", 219 | "upstash-redis": "Upstash Redis", 220 | xata: "Xata", 221 | } 222 | -------------------------------------------------------------------------------- /lib/pkg-manager.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { yellow } from "yoctocolors" 4 | import { spawn } from "node:child_process" 5 | import { getOnline } from "./is-online.js" 6 | 7 | /** 8 | * @typedef {'npm' | 'pnpm' | 'yarn' | 'bun'} PackageManager 9 | */ 10 | 11 | /** 12 | * @source https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/get-pkg-manager.ts 13 | * @returns {PackageManager} 14 | */ 15 | export function getPkgManager() { 16 | const userAgent = process.env.npm_config_user_agent || "" 17 | 18 | if (userAgent.startsWith("pnpm")) { 19 | return "pnpm" 20 | } 21 | 22 | if (userAgent.startsWith("bun")) { 23 | return "bun" 24 | } 25 | 26 | if (userAgent.startsWith("yarn")) { 27 | return "yarn" 28 | } 29 | 30 | return "npm" 31 | } 32 | 33 | /** 34 | * @source https://github.com/vercel/next.js/blob/canary/packages/create-next-app/helpers/install.ts 35 | * Spawn a package manager installation based on user preference. 36 | * 37 | * @returns A Promise that resolves once the installation is finished. 38 | */ 39 | export async function install() { 40 | const packageManager = getPkgManager() 41 | /** @type {string[]} */ 42 | const args = ["install"] 43 | if (!(await getOnline())) { 44 | console.log( 45 | yellow("You appear to be offline.\nFalling back to the local cache.") 46 | ) 47 | args.push("--offline") 48 | } 49 | return new Promise((resolve, reject) => { 50 | /** Spawn the installation process. */ 51 | const child = spawn(packageManager, args, { 52 | stdio: "inherit", 53 | env: { 54 | ...process.env, 55 | ADBLOCK: "1", 56 | // we set NODE_ENV to development as pnpm skips dev 57 | // dependencies when production 58 | NODE_ENV: "development", 59 | DISABLE_OPENCOLLECTIVE: "1", 60 | }, 61 | }) 62 | child.on("close", (code) => { 63 | if (code !== 0) { 64 | reject({ command: `${packageManager} ${args.join(" ")}` }) 65 | return 66 | } 67 | resolve(void 0) 68 | }) 69 | }) 70 | } 71 | -------------------------------------------------------------------------------- /lib/write-env.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import * as y from "yoctocolors" 4 | import { readFile, writeFile } from "node:fs/promises" 5 | import prompt from "prompts" 6 | import { join } from "node:path" 7 | import { frameworks } from "./meta.js" 8 | import { detectFramework } from "./detect.js" 9 | 10 | /** 11 | * Add/update key-value pair(s) to a .env file 12 | * @param {Record} env 13 | * @param {string|undefined} envPath 14 | * @param {boolean} comment 15 | */ 16 | export async function updateEnvFile(env, envPath = "", comment = true) { 17 | const framework = await detectFramework(envPath) 18 | const dotEnvFile = frameworks[framework]?.envFile 19 | const file = join(process.cwd(), envPath, dotEnvFile) 20 | let content = "" 21 | let read = false 22 | let created = false 23 | for (const [key, value] of Object.entries(env)) { 24 | const line = `${key}="${value}"${ 25 | comment ? " # Added by `npx auth`. Read more: https://cli.authjs.dev" : "" 26 | }` 27 | try { 28 | if (!read) { 29 | content = await readFile(file, "utf-8") 30 | read = true 31 | } 32 | if (!content.includes(`${key}=`)) { 33 | console.log(`➕ Added \`${key}\` to ${y.italic(file)}.`) 34 | content = content ? `${content}\n${line}` : line 35 | } else { 36 | const { overwrite } = await prompt({ 37 | type: "confirm", 38 | name: "overwrite", 39 | message: `Overwrite existing \`${key}\`?`, 40 | initial: false, 41 | }) 42 | if (!overwrite) continue 43 | console.log(`✨ Updated \`${key}\` in ${y.italic(file)}.`) 44 | content = content.replace(new RegExp(`${key}=(.*)`), `${line}`) 45 | } 46 | } catch (error) { 47 | if (error.code === "ENOENT") { 48 | if (!created) { 49 | console.log(`📝 Created ${y.italic(file)} with \`${key}\`.`) 50 | created = true 51 | } else { 52 | console.log(`➕ Added \`${key}\` to ${y.italic(file)}.`) 53 | } 54 | content = content ? `${content}\n${line}` : line 55 | } else { 56 | throw error 57 | } 58 | } 59 | } 60 | if (content) await writeFile(file, content) 61 | } 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth", 3 | "version": "1.2.3", 4 | "homepage": "https://cli.authjs.dev", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/nextauthjs/cli.git" 8 | }, 9 | "description": "The CLI tool by Auth.js to supercharge your authentication workflows.", 10 | "scripts": { 11 | "generate-docs": "node ./scripts/generate-docs" 12 | }, 13 | "author": "Balázs Orbán ", 14 | "contributors": [ 15 | "Balázs Orbán ", 16 | "Nico Domino ", 17 | "Lluis Agusti ", 18 | "Thang Huu Vu " 19 | ], 20 | "license": "MIT", 21 | "type": "module", 22 | "bin": { 23 | "auth": "index.js" 24 | }, 25 | "files": [ 26 | "*.d.ts*", 27 | "*.js", 28 | "!scripts", 29 | "commands", 30 | "lib", 31 | "src" 32 | ], 33 | "keywords": [ 34 | "authjs", 35 | "cli" 36 | ], 37 | "dependencies": { 38 | "@inkeep/ai-api": "0.8.0", 39 | "@inquirer/prompts": "5.1.0", 40 | "clipboardy": "4.0.0", 41 | "commander": "12.1.0", 42 | "open": "10.1.0", 43 | "ora": "8.1.0", 44 | "prompts": "2.4.2", 45 | "yoctocolors": "2.1.1", 46 | "zod": "3.23.8" 47 | }, 48 | "prettier": { 49 | "semi": false 50 | }, 51 | "devDependencies": { 52 | "@types/node": "18" 53 | }, 54 | "engines": { 55 | "node": ">=18" 56 | }, 57 | "bugs": { 58 | "url": "https://github.com/nextauthjs/auth-cli/issues" 59 | }, 60 | "main": "index.js", 61 | "directories": { 62 | "lib": "lib" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | lockfileVersion: '6.0' 2 | 3 | settings: 4 | autoInstallPeers: true 5 | excludeLinksFromLockfile: false 6 | 7 | dependencies: 8 | '@inkeep/ai-api': 9 | specifier: 0.8.0 10 | version: 0.8.0(zod@3.23.8) 11 | '@inquirer/prompts': 12 | specifier: 5.1.0 13 | version: 5.1.0 14 | clipboardy: 15 | specifier: 4.0.0 16 | version: 4.0.0 17 | commander: 18 | specifier: 12.1.0 19 | version: 12.1.0 20 | open: 21 | specifier: 10.1.0 22 | version: 10.1.0 23 | ora: 24 | specifier: 8.1.0 25 | version: 8.1.0 26 | prompts: 27 | specifier: 2.4.2 28 | version: 2.4.2 29 | yoctocolors: 30 | specifier: 2.1.1 31 | version: 2.1.1 32 | zod: 33 | specifier: 3.23.8 34 | version: 3.23.8 35 | 36 | devDependencies: 37 | '@types/node': 38 | specifier: '18' 39 | version: 18.19.54 40 | 41 | packages: 42 | 43 | /@inkeep/ai-api@0.8.0(zod@3.23.8): 44 | resolution: {integrity: sha512-mMLhLxIj23ta2XlZt7Rz6Q5z1tcDBoeI1SkO/9jMRgL/tfu+t+I4DkXm0FS25AoBjepg4iSzXyZg867YGmjCmA==} 45 | peerDependencies: 46 | zod: '>= 3' 47 | dependencies: 48 | zod: 3.23.8 49 | dev: false 50 | 51 | /@inquirer/checkbox@2.3.8: 52 | resolution: {integrity: sha512-r6q3ViCa80EjBBCduaaiAlNwYtVX3MfFSqwvLOvBBVzGRve7jgghXnP8o+iAcTA564YGRyXDpcAKTIRRZj9m8g==} 53 | engines: {node: '>=18'} 54 | dependencies: 55 | '@inquirer/core': 9.0.0 56 | '@inquirer/figures': 1.0.3 57 | '@inquirer/type': 1.4.0 58 | ansi-escapes: 4.3.2 59 | yoctocolors-cjs: 2.1.1 60 | dev: false 61 | 62 | /@inquirer/confirm@3.1.12: 63 | resolution: {integrity: sha512-s5Sod79QsBBi5Qm7zxCq9DcAD0i7WRcjd/LzsiIAWqWZKW4+OJTGrCgVSLGIHTulwbZgdxM4AAxpCXe86hv4/Q==} 64 | engines: {node: '>=18'} 65 | dependencies: 66 | '@inquirer/core': 9.0.0 67 | '@inquirer/type': 1.4.0 68 | dev: false 69 | 70 | /@inquirer/core@9.0.0: 71 | resolution: {integrity: sha512-y3q+fkCTGmvwk9Wf6yZlI3QGlLXbEm5M7Y7Eh8abaUbv+ffvmw2aB4FxSUrWaoaozwvEJSG60raHbCaUorXEzA==} 72 | engines: {node: '>=18'} 73 | dependencies: 74 | '@inquirer/figures': 1.0.3 75 | '@inquirer/type': 1.4.0 76 | '@types/mute-stream': 0.0.4 77 | '@types/node': 20.16.10 78 | '@types/wrap-ansi': 3.0.0 79 | ansi-escapes: 4.3.2 80 | cli-spinners: 2.9.2 81 | cli-width: 4.1.0 82 | mute-stream: 1.0.0 83 | signal-exit: 4.1.0 84 | strip-ansi: 6.0.1 85 | wrap-ansi: 6.2.0 86 | yoctocolors-cjs: 2.1.1 87 | dev: false 88 | 89 | /@inquirer/editor@2.1.12: 90 | resolution: {integrity: sha512-rKd/mOkLlqVqQqQihgD6KM8FqRYRcgF1Y0oiYI8BYUk/KJOit7noWxsydJFQoHfrSU6mrpDtc6a+6wcVYH/V6A==} 91 | engines: {node: '>=18'} 92 | dependencies: 93 | '@inquirer/core': 9.0.0 94 | '@inquirer/type': 1.4.0 95 | external-editor: 3.1.0 96 | dev: false 97 | 98 | /@inquirer/expand@2.1.12: 99 | resolution: {integrity: sha512-Q3pG0TD0Ra4hhlKcgXEJf8FACp70F2mW6NXXIbsIEDLKDdiihlAc4Y98RnsME9b0zwqbBMYlUrGJ/bYgXt3cIw==} 100 | engines: {node: '>=18'} 101 | dependencies: 102 | '@inquirer/core': 9.0.0 103 | '@inquirer/type': 1.4.0 104 | yoctocolors-cjs: 2.1.1 105 | dev: false 106 | 107 | /@inquirer/figures@1.0.3: 108 | resolution: {integrity: sha512-ErXXzENMH5pJt5/ssXV0DfWUZqly8nGzf0UcBV9xTnP+KyffE2mqyxIMBrZ8ijQck2nU0TQm40EQB53YreyWHw==} 109 | engines: {node: '>=18'} 110 | dev: false 111 | 112 | /@inquirer/input@2.1.12: 113 | resolution: {integrity: sha512-buCMz8eVevE+TGEriC4hG6w1jaf4jDHUb7qcIVAgUG8BydtHw8YRkgwtcbxVaKBd9CvMLzF607fyZnMtEteDPg==} 114 | engines: {node: '>=18'} 115 | dependencies: 116 | '@inquirer/core': 9.0.0 117 | '@inquirer/type': 1.4.0 118 | dev: false 119 | 120 | /@inquirer/number@1.0.0: 121 | resolution: {integrity: sha512-CFQVgqXDi5Yd+BZMLPZN8wO85t0THoK1eDLlBY1wkRuUdxb87Umz4BkVcK9LVM9rTa9bzUSVgJ91waeo6ACp3Q==} 122 | engines: {node: '>=18'} 123 | dependencies: 124 | '@inquirer/core': 9.0.0 125 | '@inquirer/type': 1.4.0 126 | dev: false 127 | 128 | /@inquirer/password@2.1.12: 129 | resolution: {integrity: sha512-nXGVXOlEAqDXqggy5Vk1eQuSya7HOffQTFzBpCUg9PT5vhIsgApRp6jRqAn7creWkkn9on+mZfezGLVolCOerw==} 130 | engines: {node: '>=18'} 131 | dependencies: 132 | '@inquirer/core': 9.0.0 133 | '@inquirer/type': 1.4.0 134 | ansi-escapes: 4.3.2 135 | dev: false 136 | 137 | /@inquirer/prompts@5.1.0: 138 | resolution: {integrity: sha512-3rEwrBnGT9opMCiA3Lij98kH5E+JuXAVLYKlXnlK1qIWDvx7tIfypF+z1oK6m61HZ5NHGPF3HtjhVga80DR1PA==} 139 | engines: {node: '>=18'} 140 | dependencies: 141 | '@inquirer/checkbox': 2.3.8 142 | '@inquirer/confirm': 3.1.12 143 | '@inquirer/editor': 2.1.12 144 | '@inquirer/expand': 2.1.12 145 | '@inquirer/input': 2.1.12 146 | '@inquirer/number': 1.0.0 147 | '@inquirer/password': 2.1.12 148 | '@inquirer/rawlist': 2.1.12 149 | '@inquirer/select': 2.3.8 150 | dev: false 151 | 152 | /@inquirer/rawlist@2.1.12: 153 | resolution: {integrity: sha512-avwuYZp4R69BtDTpb93hAR+Zk5QKBhZYEf59IhVlW6oYTAztA80vW5m9heh+D4tv58Xy41qbVKbCF7tVl/WNpA==} 154 | engines: {node: '>=18'} 155 | dependencies: 156 | '@inquirer/core': 9.0.0 157 | '@inquirer/type': 1.4.0 158 | yoctocolors-cjs: 2.1.1 159 | dev: false 160 | 161 | /@inquirer/select@2.3.8: 162 | resolution: {integrity: sha512-x4gJq9OVw8i0K03V3tJwTt2svz4J7ghqEhXaFBprRTnmbYJwQZRnnLf3PFBg+fWOti7b7fD0Oc4SLXqGeQLByg==} 163 | engines: {node: '>=18'} 164 | dependencies: 165 | '@inquirer/core': 9.0.0 166 | '@inquirer/figures': 1.0.3 167 | '@inquirer/type': 1.4.0 168 | ansi-escapes: 4.3.2 169 | yoctocolors-cjs: 2.1.1 170 | dev: false 171 | 172 | /@inquirer/type@1.4.0: 173 | resolution: {integrity: sha512-AjOqykVyjdJQvtfkNDGUyMYGF8xN50VUxftCQWsOyIo4DFRLr6VQhW0VItGI1JIyQGCGgIpKa7hMMwNhZb4OIw==} 174 | engines: {node: '>=18'} 175 | dependencies: 176 | mute-stream: 1.0.0 177 | dev: false 178 | 179 | /@types/mute-stream@0.0.4: 180 | resolution: {integrity: sha512-CPM9nzrCPPJHQNA9keH9CVkVI+WR5kMa+7XEs5jcGQ0VoAGnLv242w8lIVgwAEfmE4oufJRaTc9PNLQl0ioAow==} 181 | dependencies: 182 | '@types/node': 18.19.54 183 | dev: false 184 | 185 | /@types/node@18.19.54: 186 | resolution: {integrity: sha512-+BRgt0G5gYjTvdLac9sIeE0iZcJxi4Jc4PV5EUzqi+88jmQLr+fRZdv2tCTV7IHKSGxM6SaLoOXQWWUiLUItMw==} 187 | dependencies: 188 | undici-types: 5.26.5 189 | 190 | /@types/node@20.16.10: 191 | resolution: {integrity: sha512-vQUKgWTjEIRFCvK6CyriPH3MZYiYlNy0fKiEYHWbcoWLEgs4opurGGKlebrTLqdSMIbXImH6XExNiIyNUv3WpA==} 192 | dependencies: 193 | undici-types: 6.19.8 194 | dev: false 195 | 196 | /@types/wrap-ansi@3.0.0: 197 | resolution: {integrity: sha512-ltIpx+kM7g/MLRZfkbL7EsCEjfzCcScLpkg37eXEtx5kmrAKBkTJwd1GIAjDSL8wTpM6Hzn5YO4pSb91BEwu1g==} 198 | dev: false 199 | 200 | /ansi-escapes@4.3.2: 201 | resolution: {integrity: sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ==} 202 | engines: {node: '>=8'} 203 | dependencies: 204 | type-fest: 0.21.3 205 | dev: false 206 | 207 | /ansi-regex@5.0.1: 208 | resolution: {integrity: sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==} 209 | engines: {node: '>=8'} 210 | dev: false 211 | 212 | /ansi-regex@6.0.1: 213 | resolution: {integrity: sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==} 214 | engines: {node: '>=12'} 215 | dev: false 216 | 217 | /ansi-styles@4.3.0: 218 | resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==} 219 | engines: {node: '>=8'} 220 | dependencies: 221 | color-convert: 2.0.1 222 | dev: false 223 | 224 | /bundle-name@4.1.0: 225 | resolution: {integrity: sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==} 226 | engines: {node: '>=18'} 227 | dependencies: 228 | run-applescript: 7.0.0 229 | dev: false 230 | 231 | /chalk@5.3.0: 232 | resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} 233 | engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} 234 | dev: false 235 | 236 | /chardet@0.7.0: 237 | resolution: {integrity: sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==} 238 | dev: false 239 | 240 | /cli-cursor@5.0.0: 241 | resolution: {integrity: sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==} 242 | engines: {node: '>=18'} 243 | dependencies: 244 | restore-cursor: 5.1.0 245 | dev: false 246 | 247 | /cli-spinners@2.9.2: 248 | resolution: {integrity: sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==} 249 | engines: {node: '>=6'} 250 | dev: false 251 | 252 | /cli-width@4.1.0: 253 | resolution: {integrity: sha512-ouuZd4/dm2Sw5Gmqy6bGyNNNe1qt9RpmxveLSO7KcgsTnU7RXfsw+/bukWGo1abgBiMAic068rclZsO4IWmmxQ==} 254 | engines: {node: '>= 12'} 255 | dev: false 256 | 257 | /clipboardy@4.0.0: 258 | resolution: {integrity: sha512-5mOlNS0mhX0707P2I0aZ2V/cmHUEO/fL7VFLqszkhUsxt7RwnmrInf/eEQKlf5GzvYeHIjT+Ov1HRfNmymlG0w==} 259 | engines: {node: '>=18'} 260 | dependencies: 261 | execa: 8.0.1 262 | is-wsl: 3.1.0 263 | is64bit: 2.0.0 264 | dev: false 265 | 266 | /color-convert@2.0.1: 267 | resolution: {integrity: sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==} 268 | engines: {node: '>=7.0.0'} 269 | dependencies: 270 | color-name: 1.1.4 271 | dev: false 272 | 273 | /color-name@1.1.4: 274 | resolution: {integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==} 275 | dev: false 276 | 277 | /commander@12.1.0: 278 | resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} 279 | engines: {node: '>=18'} 280 | dev: false 281 | 282 | /cross-spawn@7.0.3: 283 | resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==} 284 | engines: {node: '>= 8'} 285 | dependencies: 286 | path-key: 3.1.1 287 | shebang-command: 2.0.0 288 | which: 2.0.2 289 | dev: false 290 | 291 | /default-browser-id@5.0.0: 292 | resolution: {integrity: sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==} 293 | engines: {node: '>=18'} 294 | dev: false 295 | 296 | /default-browser@5.2.1: 297 | resolution: {integrity: sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg==} 298 | engines: {node: '>=18'} 299 | dependencies: 300 | bundle-name: 4.1.0 301 | default-browser-id: 5.0.0 302 | dev: false 303 | 304 | /define-lazy-prop@3.0.0: 305 | resolution: {integrity: sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==} 306 | engines: {node: '>=12'} 307 | dev: false 308 | 309 | /emoji-regex@10.3.0: 310 | resolution: {integrity: sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==} 311 | dev: false 312 | 313 | /emoji-regex@8.0.0: 314 | resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} 315 | dev: false 316 | 317 | /execa@8.0.1: 318 | resolution: {integrity: sha512-VyhnebXciFV2DESc+p6B+y0LjSm0krU4OgJN44qFAhBY0TJ+1V61tYD2+wHusZ6F9n5K+vl8k0sTy7PEfV4qpg==} 319 | engines: {node: '>=16.17'} 320 | dependencies: 321 | cross-spawn: 7.0.3 322 | get-stream: 8.0.1 323 | human-signals: 5.0.0 324 | is-stream: 3.0.0 325 | merge-stream: 2.0.0 326 | npm-run-path: 5.3.0 327 | onetime: 6.0.0 328 | signal-exit: 4.1.0 329 | strip-final-newline: 3.0.0 330 | dev: false 331 | 332 | /external-editor@3.1.0: 333 | resolution: {integrity: sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew==} 334 | engines: {node: '>=4'} 335 | dependencies: 336 | chardet: 0.7.0 337 | iconv-lite: 0.4.24 338 | tmp: 0.0.33 339 | dev: false 340 | 341 | /get-east-asian-width@1.2.0: 342 | resolution: {integrity: sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==} 343 | engines: {node: '>=18'} 344 | dev: false 345 | 346 | /get-stream@8.0.1: 347 | resolution: {integrity: sha512-VaUJspBffn/LMCJVoMvSAdmscJyS1auj5Zulnn5UoYcY531UWmdwhRWkcGKnGU93m5HSXP9LP2usOryrBtQowA==} 348 | engines: {node: '>=16'} 349 | dev: false 350 | 351 | /human-signals@5.0.0: 352 | resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} 353 | engines: {node: '>=16.17.0'} 354 | dev: false 355 | 356 | /iconv-lite@0.4.24: 357 | resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} 358 | engines: {node: '>=0.10.0'} 359 | dependencies: 360 | safer-buffer: 2.1.2 361 | dev: false 362 | 363 | /is-docker@3.0.0: 364 | resolution: {integrity: sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==} 365 | engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} 366 | hasBin: true 367 | dev: false 368 | 369 | /is-fullwidth-code-point@3.0.0: 370 | resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} 371 | engines: {node: '>=8'} 372 | dev: false 373 | 374 | /is-inside-container@1.0.0: 375 | resolution: {integrity: sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==} 376 | engines: {node: '>=14.16'} 377 | hasBin: true 378 | dependencies: 379 | is-docker: 3.0.0 380 | dev: false 381 | 382 | /is-interactive@2.0.0: 383 | resolution: {integrity: sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==} 384 | engines: {node: '>=12'} 385 | dev: false 386 | 387 | /is-stream@3.0.0: 388 | resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==} 389 | engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} 390 | dev: false 391 | 392 | /is-unicode-supported@1.3.0: 393 | resolution: {integrity: sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==} 394 | engines: {node: '>=12'} 395 | dev: false 396 | 397 | /is-unicode-supported@2.0.0: 398 | resolution: {integrity: sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==} 399 | engines: {node: '>=18'} 400 | dev: false 401 | 402 | /is-wsl@3.1.0: 403 | resolution: {integrity: sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==} 404 | engines: {node: '>=16'} 405 | dependencies: 406 | is-inside-container: 1.0.0 407 | dev: false 408 | 409 | /is64bit@2.0.0: 410 | resolution: {integrity: sha512-jv+8jaWCl0g2lSBkNSVXdzfBA0npK1HGC2KtWM9FumFRoGS94g3NbCCLVnCYHLjp4GrW2KZeeSTMo5ddtznmGw==} 411 | engines: {node: '>=18'} 412 | dependencies: 413 | system-architecture: 0.1.0 414 | dev: false 415 | 416 | /isexe@2.0.0: 417 | resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} 418 | dev: false 419 | 420 | /kleur@3.0.3: 421 | resolution: {integrity: sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==} 422 | engines: {node: '>=6'} 423 | dev: false 424 | 425 | /log-symbols@6.0.0: 426 | resolution: {integrity: sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==} 427 | engines: {node: '>=18'} 428 | dependencies: 429 | chalk: 5.3.0 430 | is-unicode-supported: 1.3.0 431 | dev: false 432 | 433 | /merge-stream@2.0.0: 434 | resolution: {integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==} 435 | dev: false 436 | 437 | /mimic-fn@4.0.0: 438 | resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} 439 | engines: {node: '>=12'} 440 | dev: false 441 | 442 | /mimic-function@5.0.1: 443 | resolution: {integrity: sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==} 444 | engines: {node: '>=18'} 445 | dev: false 446 | 447 | /mute-stream@1.0.0: 448 | resolution: {integrity: sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==} 449 | engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0} 450 | dev: false 451 | 452 | /npm-run-path@5.3.0: 453 | resolution: {integrity: sha512-ppwTtiJZq0O/ai0z7yfudtBpWIoxM8yE6nHi1X47eFR2EWORqfbu6CnPlNsjeN683eT0qG6H/Pyf9fCcvjnnnQ==} 454 | engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} 455 | dependencies: 456 | path-key: 4.0.0 457 | dev: false 458 | 459 | /onetime@6.0.0: 460 | resolution: {integrity: sha512-1FlR+gjXK7X+AsAHso35MnyN5KqGwJRi/31ft6x0M194ht7S+rWAvd7PHss9xSKMzE0asv1pyIHaJYq+BbacAQ==} 461 | engines: {node: '>=12'} 462 | dependencies: 463 | mimic-fn: 4.0.0 464 | dev: false 465 | 466 | /onetime@7.0.0: 467 | resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==} 468 | engines: {node: '>=18'} 469 | dependencies: 470 | mimic-function: 5.0.1 471 | dev: false 472 | 473 | /open@10.1.0: 474 | resolution: {integrity: sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==} 475 | engines: {node: '>=18'} 476 | dependencies: 477 | default-browser: 5.2.1 478 | define-lazy-prop: 3.0.0 479 | is-inside-container: 1.0.0 480 | is-wsl: 3.1.0 481 | dev: false 482 | 483 | /ora@8.1.0: 484 | resolution: {integrity: sha512-GQEkNkH/GHOhPFXcqZs3IDahXEQcQxsSjEkK4KvEEST4t7eNzoMjxTzef+EZ+JluDEV+Raoi3WQ2CflnRdSVnQ==} 485 | engines: {node: '>=18'} 486 | dependencies: 487 | chalk: 5.3.0 488 | cli-cursor: 5.0.0 489 | cli-spinners: 2.9.2 490 | is-interactive: 2.0.0 491 | is-unicode-supported: 2.0.0 492 | log-symbols: 6.0.0 493 | stdin-discarder: 0.2.2 494 | string-width: 7.2.0 495 | strip-ansi: 7.1.0 496 | dev: false 497 | 498 | /os-tmpdir@1.0.2: 499 | resolution: {integrity: sha512-D2FR03Vir7FIu45XBY20mTb+/ZSWB00sjU9jdQXt83gDrI4Ztz5Fs7/yy74g2N5SVQY4xY1qDr4rNddwYRVX0g==} 500 | engines: {node: '>=0.10.0'} 501 | dev: false 502 | 503 | /path-key@3.1.1: 504 | resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==} 505 | engines: {node: '>=8'} 506 | dev: false 507 | 508 | /path-key@4.0.0: 509 | resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} 510 | engines: {node: '>=12'} 511 | dev: false 512 | 513 | /prompts@2.4.2: 514 | resolution: {integrity: sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==} 515 | engines: {node: '>= 6'} 516 | dependencies: 517 | kleur: 3.0.3 518 | sisteransi: 1.0.5 519 | dev: false 520 | 521 | /restore-cursor@5.1.0: 522 | resolution: {integrity: sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==} 523 | engines: {node: '>=18'} 524 | dependencies: 525 | onetime: 7.0.0 526 | signal-exit: 4.1.0 527 | dev: false 528 | 529 | /run-applescript@7.0.0: 530 | resolution: {integrity: sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==} 531 | engines: {node: '>=18'} 532 | dev: false 533 | 534 | /safer-buffer@2.1.2: 535 | resolution: {integrity: sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==} 536 | dev: false 537 | 538 | /shebang-command@2.0.0: 539 | resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==} 540 | engines: {node: '>=8'} 541 | dependencies: 542 | shebang-regex: 3.0.0 543 | dev: false 544 | 545 | /shebang-regex@3.0.0: 546 | resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==} 547 | engines: {node: '>=8'} 548 | dev: false 549 | 550 | /signal-exit@4.1.0: 551 | resolution: {integrity: sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==} 552 | engines: {node: '>=14'} 553 | dev: false 554 | 555 | /sisteransi@1.0.5: 556 | resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==} 557 | dev: false 558 | 559 | /stdin-discarder@0.2.2: 560 | resolution: {integrity: sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==} 561 | engines: {node: '>=18'} 562 | dev: false 563 | 564 | /string-width@4.2.3: 565 | resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} 566 | engines: {node: '>=8'} 567 | dependencies: 568 | emoji-regex: 8.0.0 569 | is-fullwidth-code-point: 3.0.0 570 | strip-ansi: 6.0.1 571 | dev: false 572 | 573 | /string-width@7.2.0: 574 | resolution: {integrity: sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==} 575 | engines: {node: '>=18'} 576 | dependencies: 577 | emoji-regex: 10.3.0 578 | get-east-asian-width: 1.2.0 579 | strip-ansi: 7.1.0 580 | dev: false 581 | 582 | /strip-ansi@6.0.1: 583 | resolution: {integrity: sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==} 584 | engines: {node: '>=8'} 585 | dependencies: 586 | ansi-regex: 5.0.1 587 | dev: false 588 | 589 | /strip-ansi@7.1.0: 590 | resolution: {integrity: sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==} 591 | engines: {node: '>=12'} 592 | dependencies: 593 | ansi-regex: 6.0.1 594 | dev: false 595 | 596 | /strip-final-newline@3.0.0: 597 | resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==} 598 | engines: {node: '>=12'} 599 | dev: false 600 | 601 | /system-architecture@0.1.0: 602 | resolution: {integrity: sha512-ulAk51I9UVUyJgxlv9M6lFot2WP3e7t8Kz9+IS6D4rVba1tR9kON+Ey69f+1R4Q8cd45Lod6a4IcJIxnzGc/zA==} 603 | engines: {node: '>=18'} 604 | dev: false 605 | 606 | /tmp@0.0.33: 607 | resolution: {integrity: sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==} 608 | engines: {node: '>=0.6.0'} 609 | dependencies: 610 | os-tmpdir: 1.0.2 611 | dev: false 612 | 613 | /type-fest@0.21.3: 614 | resolution: {integrity: sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==} 615 | engines: {node: '>=10'} 616 | dev: false 617 | 618 | /undici-types@5.26.5: 619 | resolution: {integrity: sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==} 620 | 621 | /undici-types@6.19.8: 622 | resolution: {integrity: sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==} 623 | dev: false 624 | 625 | /which@2.0.2: 626 | resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} 627 | engines: {node: '>= 8'} 628 | hasBin: true 629 | dependencies: 630 | isexe: 2.0.0 631 | dev: false 632 | 633 | /wrap-ansi@6.2.0: 634 | resolution: {integrity: sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==} 635 | engines: {node: '>=8'} 636 | dependencies: 637 | ansi-styles: 4.3.0 638 | string-width: 4.2.3 639 | strip-ansi: 6.0.1 640 | dev: false 641 | 642 | /yoctocolors-cjs@2.1.1: 643 | resolution: {integrity: sha512-c6T13b6qYcJZvck7QbEFXrFX/Mu2KOjvAGiKHmYMUg96jxNpfP6i+psGW72BOPxOIDUJrORG+Kyu7quMX9CQBQ==} 644 | engines: {node: '>=18'} 645 | dev: false 646 | 647 | /yoctocolors@2.1.1: 648 | resolution: {integrity: sha512-GQHQqAopRhwU8Kt1DDM8NjibDXHC8eoh1erhGAJPEyveY9qqVeXvVikNKrDz69sHowPMorbPUrH/mx8c50eiBQ==} 649 | engines: {node: '>=18'} 650 | dev: false 651 | 652 | /zod@3.23.8: 653 | resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} 654 | dev: false 655 | -------------------------------------------------------------------------------- /scripts/generate-docs.js: -------------------------------------------------------------------------------- 1 | import { execSync } from "node:child_process" 2 | import fs from "fs/promises" 3 | import { join } from "path" 4 | import { fileURLToPath } from "url" 5 | const __dirname = fileURLToPath(new URL(".", import.meta.url)) 6 | 7 | let output = execSync("node index.js --help", { 8 | encoding: "utf-8", 9 | }) 10 | 11 | // Drop description 12 | output = output.replace( 13 | /(?<=Usage: auth \[options\] \[command\]\n\n)[\s\S]*?(?=Options:)/, 14 | "" 15 | ) 16 | 17 | const readmePath = join(__dirname, "../README.md") 18 | const readme = await fs.readFile(readmePath, "utf-8") 19 | 20 | const updatedReadme = readme.replace( 21 | /(?<=\n\n```\n)[\s\S]*?(?=```\n\n)/, 22 | output 23 | ) 24 | 25 | await fs.writeFile(readmePath, updatedReadme, "utf-8") 26 | --------------------------------------------------------------------------------