feat(cli): add secret generator command for the cli (#659)

This commit is contained in:
Bereket Engida
2024-11-25 23:44:30 +03:00
committed by GitHub
parent 2d209bcdd4
commit ca5e90883c
4 changed files with 46 additions and 1 deletions

View File

@@ -40,4 +40,13 @@ npx @better-auth/cli@latest migrate
If you see this error, it means the CLI cant resolve imported modules in your Better Auth config file. We're working on a fix for many of these issues, but in the meantime, you can try the following:
- Remove any import aliases in your config file and use relative paths instead. After running the CLI, you can revert to using aliases.
- Remove any import aliases in your config file and use relative paths instead. After running the CLI, you can revert to using aliases.
## Secret
The CLI also provides a way to generate a secret key for your Better Auth instance.
```bash title="Terminal"
npx @better-auth/cli@latest secret
```

View File

@@ -22,6 +22,28 @@ To avoid instantiation and reference errors, configure your TypeScript config fi
If you're using a monorepo and want to share the `auth` package across multiple projects, either export the TypeScript files as-is without compilation or use build tools like `tsup` to transpile the package.
### Strict Mode
Better Auth is designed to work with TypeScript's strict mode. We recommend enabling strict mode in your TypeScript config file:
```json title="tsconfig.json"
{
"compilerOptions": {
"strict": true
}
}
```
if you can't set `strict` to `true`, you can enable `strictNullChecks`:
```json title="tsconfig.json"
{
"compilerOptions": {
"strictNullChecks": true,
}
}
```
## Inferring Types
Both the client SDK and the server offer types that can be inferred using the `$Infer` property. Plugins can extend base types like `User` and `Session`, and you can use `$Infer` to infer these types. Additionally, plugins can provide extra types that can also be inferred through `$Infer`.

View File

@@ -0,0 +1,12 @@
import { logger } from "better-auth";
import chalk from "chalk";
import { Command } from "commander";
import Crypto from "crypto";
export const generateSecret = new Command("secret").action(() => {
const secret = Crypto.randomBytes(32).toString("hex");
logger.info(`\nAdd the following to your .env file:
${
chalk.gray("# Auth Secret") + chalk.green(`\nBETTER_AUTH_SECRET=${secret}`)
}`);
});

View File

@@ -4,12 +4,14 @@ import { Command } from "commander";
import { migrate } from "./commands/migrate";
import { generate } from "./commands/generate";
import "dotenv/config";
import { generateSecret } from "./commands/secert";
async function main() {
const program = new Command("better-auth");
program
.addCommand(migrate)
.addCommand(generate)
.addCommand(generateSecret)
.version("0.0.1")
.description("Better Auth CLI");
program.parse();