mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-27 17:36:42 -05:00
feat(cli): add secret generator command for the cli (#659)
This commit is contained in:
@@ -40,4 +40,13 @@ npx @better-auth/cli@latest migrate
|
||||
|
||||
If you see this error, it means the CLI can’t 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
|
||||
```
|
||||
@@ -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`.
|
||||
|
||||
12
packages/cli/src/commands/secert.ts
Normal file
12
packages/cli/src/commands/secert.ts
Normal 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}`)
|
||||
}`);
|
||||
});
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user