better-ts-stack 2.1.2 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -8
- package/dist/args.js +2 -1
- package/dist/builder/buildPlanner.js +7 -1
- package/dist/builder/configGenerator.js +28 -3
- package/dist/builder/index.js +2 -1
- package/dist/builder/readmeGenerator.js +2 -2
- package/dist/output/nextSteps.js +2 -4
- package/dist/prompts/stack.js +3 -5
- package/dist/types/index.js +1 -1
- package/package.json +1 -1
- package/templates/backend/express/src/env.ts.hbs +13 -2
- package/templates/backend/express/src/index.ts.hbs +31 -2
- package/templates/backend/nestjs/src/app.module.ts.hbs +4 -1
- package/templates/backend/nestjs/src/env.ts.hbs +13 -2
- package/templates/backend/nestjs/src/health/health.controller.ts.hbs +7 -0
- package/templates/backend/nestjs/src/{main.ts → main.ts.hbs} +11 -0
- package/templates/frontend/nextjs/app/globals.css +119 -79
- package/templates/frontend/nextjs/app/layout.tsx +13 -11
- package/templates/frontend/nextjs/app/page.tsx.hbs +63 -43
- package/templates/frontend/nextjs/components/ui/alert.tsx +75 -0
- package/templates/frontend/nextjs/components/ui/badge.tsx +51 -0
- package/templates/frontend/nextjs/components/ui/button.tsx +33 -27
- package/templates/frontend/nextjs/components/ui/card.tsx +76 -34
- package/templates/frontend/nextjs/components/ui/field.tsx +203 -32
- package/templates/frontend/nextjs/components/ui/input.tsx +8 -7
- package/templates/frontend/nextjs/components/ui/label.tsx +19 -0
- package/templates/frontend/nextjs/components/ui/separator.tsx +24 -0
- package/templates/frontend/nextjs/components/ui/skeleton.tsx +13 -0
- package/templates/frontend/nextjs/components/ui/spinner.tsx +10 -0
- package/templates/frontend/nextjs/components.json +11 -5
- package/templates/frontend/nextjs/config.json +4 -3
- package/templates/frontend/nextjs/lib/utils.ts +1 -6
- package/templates/frontend/tanstack/components.json +12 -5
- package/templates/frontend/tanstack/config.json +5 -2
- package/templates/frontend/tanstack/src/components/ui/alert.tsx +75 -0
- package/templates/frontend/tanstack/src/components/ui/badge.tsx +51 -0
- package/templates/frontend/tanstack/src/components/ui/button.tsx +33 -27
- package/templates/frontend/tanstack/src/components/ui/card.tsx +76 -34
- package/templates/frontend/tanstack/src/components/ui/field.tsx +201 -32
- package/templates/frontend/tanstack/src/components/ui/input.tsx +8 -7
- package/templates/frontend/tanstack/src/components/ui/label.tsx +17 -0
- package/templates/frontend/tanstack/src/components/ui/separator.tsx +24 -0
- package/templates/frontend/tanstack/src/components/ui/skeleton.tsx +13 -0
- package/templates/frontend/tanstack/src/components/ui/spinner.tsx +10 -0
- package/templates/frontend/tanstack/src/lib/utils.ts +1 -6
- package/templates/frontend/tanstack/src/routes/index.tsx.hbs +64 -45
- package/templates/frontend/tanstack/src/styles/app.css +100 -55
- package/templates/modules/agents/AGENTS.md.hbs +29 -21
- package/templates/modules/auth/express/config.json +12 -11
- package/templates/modules/auth/express/src/lib/auth.ts.hbs +143 -0
- package/templates/modules/auth/express/src/lib/email.ts +37 -0
- package/templates/modules/auth/express/src/middleware/requireAuth.ts +29 -0
- package/templates/modules/auth/express/src/routes/me.ts +13 -0
- package/templates/modules/auth/nestjs/config.json +13 -11
- package/templates/modules/auth/nestjs/src/auth/auth.module.ts.hbs +64 -14
- package/templates/modules/auth/nestjs/src/auth/auth.ts.hbs +152 -0
- package/templates/modules/auth/nestjs/src/auth/email.ts +37 -0
- package/templates/modules/auth/nestjs/src/me/me.controller.ts +15 -0
- package/templates/modules/auth/nextjs/app/dashboard/page.tsx +101 -45
- package/templates/modules/auth/nextjs/app/forgot-password/page.tsx +11 -0
- package/templates/modules/auth/nextjs/app/reset-password/page.tsx +17 -0
- package/templates/modules/auth/nextjs/app/sign-in/page.tsx +23 -17
- package/templates/modules/auth/nextjs/app/sign-up/page.tsx +25 -19
- package/templates/modules/auth/nextjs/components/auth/change-password-form.tsx +125 -0
- package/templates/modules/auth/nextjs/components/auth/email-verification-card.tsx +91 -0
- package/templates/modules/auth/nextjs/components/auth/forgot-password-form.tsx +133 -0
- package/templates/modules/auth/nextjs/components/auth/reset-password-form.tsx +155 -0
- package/templates/modules/auth/nextjs/components/auth/sign-in-form.tsx +46 -32
- package/templates/modules/auth/nextjs/components/auth/sign-out-button.tsx +6 -5
- package/templates/modules/auth/nextjs/components/auth/sign-up-form.tsx +36 -30
- package/templates/modules/auth/nextjs/components/auth/social-buttons.tsx +73 -0
- package/templates/modules/auth/nextjs/config.json +8 -2
- package/templates/modules/auth/nextjs/lib/auth-schema.ts +27 -2
- package/templates/modules/auth/nextjs/lib/auth.ts.hbs +65 -0
- package/templates/modules/auth/nextjs/lib/email.ts +43 -0
- package/templates/modules/auth/nextjs/lib/session.ts +12 -0
- package/templates/modules/auth/tanstack/config.json +9 -3
- package/templates/modules/auth/tanstack/src/components/auth/change-password-form.tsx +123 -0
- package/templates/modules/auth/tanstack/src/components/auth/email-verification-card.tsx +89 -0
- package/templates/modules/auth/tanstack/src/components/auth/forgot-password-form.tsx +131 -0
- package/templates/modules/auth/tanstack/src/components/auth/reset-password-form.tsx +149 -0
- package/templates/modules/auth/tanstack/src/components/auth/sign-in-form.tsx +44 -35
- package/templates/modules/auth/tanstack/src/components/auth/sign-out-button.tsx +7 -6
- package/templates/modules/auth/tanstack/src/components/auth/sign-up-form.tsx +37 -34
- package/templates/modules/auth/tanstack/src/components/auth/social-buttons.tsx +71 -0
- package/templates/modules/auth/tanstack/src/lib/auth-functions.ts +7 -1
- package/templates/modules/auth/tanstack/src/lib/auth-schema.ts +27 -2
- package/templates/modules/auth/tanstack/src/lib/auth.ts.hbs +61 -1
- package/templates/modules/auth/tanstack/src/lib/email.ts +43 -0
- package/templates/modules/auth/tanstack/src/routeTree.gen.ts +61 -3
- package/templates/modules/auth/tanstack/src/routes/dashboard.tsx +40 -32
- package/templates/modules/auth/tanstack/src/routes/forgot-password.tsx +17 -0
- package/templates/modules/auth/tanstack/src/routes/reset-password.tsx +25 -0
- package/templates/modules/auth/tanstack/src/routes/sign-in.tsx +19 -12
- package/templates/modules/auth/tanstack/src/routes/sign-up.tsx +21 -14
- package/templates/modules/drizzle/express/src/lib/schema.ts.hbs +90 -0
- package/templates/modules/drizzle/nestjs/src/database/schema.ts.hbs +90 -0
- package/templates/modules/mongoose/nestjs/config.json +2 -1
- package/templates/modules/prisma/express/prisma/schema.prisma.hbs +92 -0
- package/templates/modules/prisma/nestjs/prisma/schema.prisma.hbs +91 -0
- package/templates/modules/rate-limit/express/src/middleware/rateLimit.ts +0 -8
- package/templates/modules/auth/express/src/controllers/authController.ts.hbs +0 -116
- package/templates/modules/auth/express/src/lib/jwt.ts.hbs +0 -27
- package/templates/modules/auth/express/src/middleware/requireAuth.ts.hbs +0 -25
- package/templates/modules/auth/express/src/routes/auth.ts.hbs +0 -27
- package/templates/modules/auth/express/src/services/userStore.ts.hbs +0 -117
- package/templates/modules/auth/nestjs/src/auth/auth.controller.ts.hbs +0 -61
- package/templates/modules/auth/nestjs/src/auth/auth.guard.ts +0 -36
- package/templates/modules/auth/nestjs/src/auth/auth.schemas.ts +0 -35
- package/templates/modules/auth/nestjs/src/auth/auth.service.ts +0 -70
- package/templates/modules/auth/nestjs/src/auth/jwt.ts +0 -27
- package/templates/modules/auth/nestjs/src/auth/users.service.ts.hbs +0 -144
- package/templates/modules/auth/nestjs/src/auth/zod-validation.pipe.ts +0 -16
- package/templates/modules/drizzle/express/src/lib/schema.ts +0 -12
- package/templates/modules/drizzle/nestjs/src/database/schema.ts +0 -12
- package/templates/modules/prisma/express/prisma/schema.prisma +0 -24
- package/templates/modules/prisma/nestjs/prisma/schema.prisma +0 -23
package/README.md
CHANGED
|
@@ -37,6 +37,9 @@ npx better-ts-stack . --framework nextjs --database drizzle --pm pnpm
|
|
|
37
37
|
| `--auth` / `--no-auth` | Add authentication |
|
|
38
38
|
| `--docker` / `--no-docker` | Add Docker files |
|
|
39
39
|
| `--rate-limit` / `--no-rate-limit` | Add rate limiting (Express and NestJS) |
|
|
40
|
+
| `--ci` / `--no-ci` | Add a GitHub Actions workflow |
|
|
41
|
+
| `--no-agents` | Leave out AGENTS.md (added by default) |
|
|
42
|
+
| `--vscode` / `--no-vscode` | Add VS Code settings and extensions |
|
|
40
43
|
| `--git` / `--no-git` | Initialize a git repository |
|
|
41
44
|
| `--install` / `--no-install` | Install dependencies |
|
|
42
45
|
| `-y`, `--yes` | Use defaults for missing options, no prompts |
|
|
@@ -46,7 +49,7 @@ npx better-ts-stack . --framework nextjs --database drizzle --pm pnpm
|
|
|
46
49
|
|
|
47
50
|
`--database` names the ORM, which also selects the database: `prisma` and `drizzle` use PostgreSQL, `mongoose` uses MongoDB.
|
|
48
51
|
|
|
49
|
-
With `--yes`, the defaults are Express, no database, no auth, no rate limiting, no Docker, git initialized, and dependencies not installed. The package manager defaults to the one that ran the CLI: `pnpm` for `pnpm dlx`, `bun` for `bunx`, and `npm` otherwise.
|
|
52
|
+
With `--yes`, the defaults are Express, no database, no auth, no rate limiting, no Docker, no CI, no VS Code settings, an `AGENTS.md`, git initialized, and dependencies not installed. The package manager defaults to the one that ran the CLI: `pnpm` for `pnpm dlx`, `bun` for `bunx`, and `npm` otherwise.
|
|
50
53
|
|
|
51
54
|
The project path can be a name (`my-app`), a nested path (`apps/api`), or `.` for the current directory.
|
|
52
55
|
|
|
@@ -54,12 +57,12 @@ The project path can be a name (`my-app`), a nested path (`apps/api`), or `.` fo
|
|
|
54
57
|
|
|
55
58
|
| Project type | Stack | Optional setup |
|
|
56
59
|
| -------------- | --------------------------------------- | ------------------------------------------------------------------------ |
|
|
57
|
-
| Backend API | Express 5 or NestJS 12 + TypeScript | PostgreSQL, MongoDB, Prisma, Drizzle, Mongoose,
|
|
60
|
+
| Backend API | Express 5 or NestJS 12 + TypeScript | PostgreSQL, MongoDB, Prisma, Drizzle, Mongoose, Better Auth, Docker, git |
|
|
58
61
|
| Full-stack app | Next.js 16 or TanStack Start + React 19 | PostgreSQL, MongoDB, Prisma, Drizzle, Mongoose, Better Auth, Docker, git |
|
|
59
62
|
|
|
60
63
|
Notes:
|
|
61
64
|
|
|
62
|
-
- Better Auth is
|
|
65
|
+
- Better Auth is offered for every framework; full-stack projects need a database for it.
|
|
63
66
|
|
|
64
67
|
## Interactive Prompt Flow
|
|
65
68
|
|
|
@@ -77,10 +80,15 @@ Without flags, the CLI asks, in order:
|
|
|
77
80
|
6. Package manager: `npm`, `pnpm`, or `bun`
|
|
78
81
|
7. Docker setup
|
|
79
82
|
8. Authentication
|
|
80
|
-
-
|
|
81
|
-
- Next.js and TanStack Start apps:
|
|
82
|
-
9.
|
|
83
|
-
10.
|
|
83
|
+
- Better Auth for every framework
|
|
84
|
+
- Next.js and TanStack Start apps: only when a database is selected
|
|
85
|
+
9. Rate limiting (Express and NestJS)
|
|
86
|
+
10. GitHub Actions CI
|
|
87
|
+
11. VS Code settings
|
|
88
|
+
12. Git initialization
|
|
89
|
+
13. Dependency installation
|
|
90
|
+
|
|
91
|
+
`AGENTS.md` and `CLAUDE.md` are added without a question; pass `--no-agents` to leave them out.
|
|
84
92
|
|
|
85
93
|
The CLI does not ask for a port. Backend projects default to `PORT=3000`.
|
|
86
94
|
|
|
@@ -93,7 +101,7 @@ Every generated project includes:
|
|
|
93
101
|
- `.env.example` and `.env` setup
|
|
94
102
|
- Ready-to-run project scripts
|
|
95
103
|
- Health check endpoint at `/health` for backend projects
|
|
96
|
-
- shadcn
|
|
104
|
+
- shadcn/ui components built on Base UI for Next.js and TanStack Start projects
|
|
97
105
|
- Database wiring and schema setup when selected
|
|
98
106
|
- Authentication scaffolding when selected
|
|
99
107
|
- Docker files when selected
|
package/dist/args.js
CHANGED
|
@@ -23,7 +23,8 @@ Options left out are asked interactively, unless --yes is given.
|
|
|
23
23
|
--rate-limit, --no-rate-limit
|
|
24
24
|
Add rate limiting (Express and NestJS)
|
|
25
25
|
--ci, --no-ci Add a GitHub Actions workflow
|
|
26
|
-
--
|
|
26
|
+
--no-agents Leave out AGENTS.md for AI coding agents (added by
|
|
27
|
+
default)
|
|
27
28
|
--vscode, --no-vscode Add VS Code settings and recommended extensions
|
|
28
29
|
--git, --no-git Initialize a git repository
|
|
29
30
|
--install, --no-install Install dependencies
|
|
@@ -15,7 +15,13 @@ const gitInitializer_1 = require("./gitInitializer");
|
|
|
15
15
|
const moduleSelector_1 = require("./moduleSelector");
|
|
16
16
|
const templateContext_1 = require("./templateContext");
|
|
17
17
|
// Files the builder writes itself instead of copying them from a module
|
|
18
|
-
const GENERATED_FILES = [
|
|
18
|
+
const GENERATED_FILES = [
|
|
19
|
+
"package.json",
|
|
20
|
+
".env",
|
|
21
|
+
".env.example",
|
|
22
|
+
"README.md",
|
|
23
|
+
configGenerator_1.STACK_FILE,
|
|
24
|
+
];
|
|
19
25
|
// Loads the selected modules and merges their configurations
|
|
20
26
|
async function loadBuildInputs(config) {
|
|
21
27
|
const selection = (0, moduleSelector_1.selectModules)(config);
|
|
@@ -3,11 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.GENERATED_SECRETS = void 0;
|
|
6
|
+
exports.STACK_FILE = exports.GENERATED_SECRETS = void 0;
|
|
7
7
|
exports.processScriptVariables = processScriptVariables;
|
|
8
8
|
exports.mergeConfigurations = mergeConfigurations;
|
|
9
9
|
exports.generatePackageJson = generatePackageJson;
|
|
10
10
|
exports.generatePnpmWorkspace = generatePnpmWorkspace;
|
|
11
|
+
exports.generateStackFile = generateStackFile;
|
|
11
12
|
exports.generateEnvFile = generateEnvFile;
|
|
12
13
|
// Utilities for merging module configurations and generating project files
|
|
13
14
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -96,7 +97,6 @@ async function generatePackageJson(targetDir, mergedConfig, config) {
|
|
|
96
97
|
// these are not approved; entries for packages a project lacks are ignored.
|
|
97
98
|
const PNPM_BUILD_DEPENDENCIES = [
|
|
98
99
|
"@prisma/engines",
|
|
99
|
-
"bcrypt",
|
|
100
100
|
"esbuild",
|
|
101
101
|
"prisma",
|
|
102
102
|
"unrs-resolver",
|
|
@@ -128,7 +128,32 @@ async function generatePnpmWorkspace(targetDir, overrides) {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
// Variables that get a random value in .env instead of the module's default
|
|
131
|
-
exports.GENERATED_SECRETS = ["
|
|
131
|
+
exports.GENERATED_SECRETS = ["BETTER_AUTH_SECRET"];
|
|
132
|
+
// Name of the file that records how a project was generated
|
|
133
|
+
exports.STACK_FILE = "better-ts-stack.json";
|
|
134
|
+
// Records the stack choices, so later commands (such as adding a module to the
|
|
135
|
+
// project) know what the project was generated with
|
|
136
|
+
async function generateStackFile(targetDir, config) {
|
|
137
|
+
try {
|
|
138
|
+
const { version } = (await fs_extra_1.default.readJson(node_path_1.default.join(__dirname, "../../package.json")));
|
|
139
|
+
const stack = {
|
|
140
|
+
cliVersion: version,
|
|
141
|
+
framework: config.framework,
|
|
142
|
+
database: config.database,
|
|
143
|
+
packageManager: config.packageManager,
|
|
144
|
+
auth: config.useAuth,
|
|
145
|
+
docker: config.useDocker,
|
|
146
|
+
rateLimit: config.useRateLimit,
|
|
147
|
+
ci: config.useCi,
|
|
148
|
+
agents: config.useAgents,
|
|
149
|
+
vscode: config.useVscode,
|
|
150
|
+
};
|
|
151
|
+
await fs_extra_1.default.writeFile(node_path_1.default.join(targetDir, exports.STACK_FILE), JSON.stringify(stack, null, 2) + "\n", "utf-8");
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
throw (0, types_1.buildError)(error, "STACK_FILE_ERROR", `Failed to write ${exports.STACK_FILE}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
132
157
|
// Generates .env and .env.example files from merged environment variables
|
|
133
158
|
async function generateEnvFile(targetDir, envVars) {
|
|
134
159
|
try {
|
package/dist/builder/index.js
CHANGED
|
@@ -52,9 +52,10 @@ async function build(config, targetDir) {
|
|
|
52
52
|
if (config.packageManager === "pnpm") {
|
|
53
53
|
await (0, configGenerator_1.generatePnpmWorkspace)(targetDir, mergedConfig.overrides);
|
|
54
54
|
}
|
|
55
|
-
// 7. Generate environment files and the
|
|
55
|
+
// 7. Generate environment files, the README, and the stack file
|
|
56
56
|
await (0, configGenerator_1.generateEnvFile)(targetDir, mergedConfig.envVars);
|
|
57
57
|
await (0, readmeGenerator_1.generateReadme)(targetDir, config, mergedConfig);
|
|
58
|
+
await (0, configGenerator_1.generateStackFile)(targetDir, config);
|
|
58
59
|
// 8. Install dependencies and initialize git (both optional); a failure
|
|
59
60
|
// in either is reported as a warning and does not fail the build
|
|
60
61
|
const depsInstalled = config.installDeps &&
|
|
@@ -49,8 +49,8 @@ function renderReadme(config, mergedConfig, targetDir) {
|
|
|
49
49
|
}
|
|
50
50
|
if (config.useAuth) {
|
|
51
51
|
lines.push(isFullstack
|
|
52
|
-
? "- **Auth:** Better Auth with email and password"
|
|
53
|
-
: "- **Auth:**
|
|
52
|
+
? "- **Auth:** Better Auth with email and password, email verification, password reset, and GitHub and Google sign-in"
|
|
53
|
+
: "- **Auth:** Better Auth on `/api/auth` with email and password, email verification, password reset, GitHub and Google sign-in, and bearer tokens; `GET /api/me` is a protected example");
|
|
54
54
|
}
|
|
55
55
|
if (config.useRateLimit) {
|
|
56
56
|
lines.push(`- **Rate limiting:** 100 requests per client IP in 15 minutes${config.useAuth ? ", and 10 sign-up or login attempts" : ""}`);
|
package/dist/output/nextSteps.js
CHANGED
|
@@ -24,9 +24,7 @@ function generateNextSteps(config, targetDir, depsInstalled, isForReadme = false
|
|
|
24
24
|
steps.push("Review the generated .env and set your database connection details");
|
|
25
25
|
}
|
|
26
26
|
if (config.useAuth) {
|
|
27
|
-
steps.push(
|
|
28
|
-
? "Review BETTER_AUTH_SECRET and BETTER_AUTH_URL in .env"
|
|
29
|
-
: "Review the generated JWT_SECRET in .env");
|
|
27
|
+
steps.push("Review BETTER_AUTH_URL in .env, and add GitHub, Google, or Resend keys when you need them");
|
|
30
28
|
}
|
|
31
29
|
// Step 3: Install dependencies if not already done
|
|
32
30
|
if (!depsInstalled) {
|
|
@@ -66,7 +64,7 @@ function generateNextSteps(config, targetDir, depsInstalled, isForReadme = false
|
|
|
66
64
|
if (config.useAuth) {
|
|
67
65
|
steps.push(isFullstack
|
|
68
66
|
? "Visit /sign-up to create your first account"
|
|
69
|
-
: "Create a user
|
|
67
|
+
: "Create a user with POST /api/auth/sign-up/email, then call GET /api/me with the set-auth-token header as a bearer token");
|
|
70
68
|
}
|
|
71
69
|
if (config.useDocker) {
|
|
72
70
|
steps.push(`To run the app in Docker instead: ${config.packageManager} run docker:up`);
|
package/dist/prompts/stack.js
CHANGED
|
@@ -84,7 +84,7 @@ async function collectStackChoices(preset) {
|
|
|
84
84
|
}
|
|
85
85
|
const useAuth = isAuthAvailable
|
|
86
86
|
? await ask(preset.useAuth, () => (0, ui_1.confirm)({
|
|
87
|
-
message:
|
|
87
|
+
message: "Add authentication (Better Auth)?",
|
|
88
88
|
initialValue: false,
|
|
89
89
|
}))
|
|
90
90
|
: false;
|
|
@@ -96,10 +96,8 @@ async function collectStackChoices(preset) {
|
|
|
96
96
|
? false
|
|
97
97
|
: await ask(preset.useRateLimit, () => (0, ui_1.confirm)({ message: "Add rate limiting?", initialValue: false }));
|
|
98
98
|
const useCi = await ask(preset.useCi, () => (0, ui_1.confirm)({ message: "Add GitHub Actions CI?", initialValue: false }));
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
initialValue: false,
|
|
102
|
-
}));
|
|
99
|
+
// AGENTS.md is always added without asking; --no-agents leaves it out
|
|
100
|
+
const useAgents = preset.useAgents ?? true;
|
|
103
101
|
const useVscode = await ask(preset.useVscode, () => (0, ui_1.confirm)({ message: "Add VS Code settings?", initialValue: false }));
|
|
104
102
|
const initGit = await ask(preset.initGit, () => (0, ui_1.confirm)({ message: "Initialize a git repository?", initialValue: true }));
|
|
105
103
|
const installDeps = await ask(preset.installDeps, () => (0, ui_1.confirm)({ message: "Install dependencies now?", initialValue: false }));
|
package/dist/types/index.js
CHANGED
package/package.json
CHANGED
|
@@ -22,8 +22,19 @@ const envSchema = z.object({
|
|
|
22
22
|
MONGODB_URI: z.url(),
|
|
23
23
|
{{/if}}
|
|
24
24
|
{{#if useAuth}}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
BETTER_AUTH_SECRET: z
|
|
26
|
+
.string()
|
|
27
|
+
.min(32, "BETTER_AUTH_SECRET must be at least 32 characters"),
|
|
28
|
+
// The public URL of this server; links in emails point here
|
|
29
|
+
BETTER_AUTH_URL: z.url(),
|
|
30
|
+
// Optional: GitHub and Google sign-in are turned on when both are set
|
|
31
|
+
GITHUB_CLIENT_ID: z.string().optional(),
|
|
32
|
+
GITHUB_CLIENT_SECRET: z.string().optional(),
|
|
33
|
+
GOOGLE_CLIENT_ID: z.string().optional(),
|
|
34
|
+
GOOGLE_CLIENT_SECRET: z.string().optional(),
|
|
35
|
+
// Optional: without it, emails are printed to the log
|
|
36
|
+
RESEND_API_KEY: z.string().optional(),
|
|
37
|
+
EMAIL_FROM: z.string().default("onboarding@resend.dev"),
|
|
27
38
|
{{/if}}
|
|
28
39
|
});
|
|
29
40
|
|
|
@@ -16,9 +16,17 @@ import { connectDB, disconnectDB } from "./lib/db";
|
|
|
16
16
|
{{#if useRateLimit}}
|
|
17
17
|
import { apiLimiter } from "./middleware/rateLimit";
|
|
18
18
|
{{/if}}
|
|
19
|
+
{{#if useAuth}}
|
|
20
|
+
import { toNodeHandler } from "better-auth/node";
|
|
21
|
+
{{#if (eq database 'mongoose')}}
|
|
22
|
+
import { auth, mongoClient } from "./lib/auth";
|
|
23
|
+
{{else}}
|
|
24
|
+
import { auth } from "./lib/auth";
|
|
25
|
+
{{/if}}
|
|
26
|
+
{{/if}}
|
|
19
27
|
import healthRouter from "./routes/health";
|
|
20
28
|
{{#if useAuth}}
|
|
21
|
-
import
|
|
29
|
+
import meRouter from "./routes/me";
|
|
22
30
|
{{/if}}
|
|
23
31
|
|
|
24
32
|
const app: Express = express();
|
|
@@ -26,18 +34,35 @@ const port = env.PORT;
|
|
|
26
34
|
|
|
27
35
|
// Middleware
|
|
28
36
|
app.use(helmet());
|
|
37
|
+
{{#if useAuth}}
|
|
38
|
+
// Browser clients read the bearer token from the set-auth-token header
|
|
39
|
+
app.use(cors({ origin: env.CORS_ORIGIN, exposedHeaders: ["set-auth-token"] }));
|
|
40
|
+
{{else}}
|
|
29
41
|
app.use(cors({ origin: env.CORS_ORIGIN }));
|
|
42
|
+
{{/if}}
|
|
30
43
|
{{#if useRateLimit}}
|
|
31
44
|
app.use(apiLimiter);
|
|
32
45
|
{{/if}}
|
|
33
46
|
app.use(morgan("dev"));
|
|
47
|
+
{{#if useAuth}}
|
|
48
|
+
// Better Auth reads the client IP for its rate limits from this header. It is
|
|
49
|
+
// set from req.ip on every request, so a client cannot pick its own value.
|
|
50
|
+
// Behind a reverse proxy, set app.set("trust proxy", 1) for the real client IP
|
|
51
|
+
app.use("/api/auth", (req: Request, _res: Response, next: NextFunction) => {
|
|
52
|
+
req.headers["x-client-ip"] = req.ip;
|
|
53
|
+
next();
|
|
54
|
+
});
|
|
55
|
+
// Sign-up, sign-in, sessions, email verification, and password reset. Better
|
|
56
|
+
// Auth reads the request body itself, so it is mounted before express.json()
|
|
57
|
+
app.all("/api/auth/*splat", toNodeHandler(auth));
|
|
58
|
+
{{/if}}
|
|
34
59
|
app.use(express.json());
|
|
35
60
|
app.use(express.urlencoded({ extended: true }));
|
|
36
61
|
|
|
37
62
|
// Routes
|
|
38
63
|
app.use("/health", healthRouter);
|
|
39
64
|
{{#if useAuth}}
|
|
40
|
-
app.use("/
|
|
65
|
+
app.use("/api/me", meRouter);
|
|
41
66
|
{{/if}}
|
|
42
67
|
|
|
43
68
|
// 404 handler
|
|
@@ -73,7 +98,11 @@ function closeDatabase(): Promise<void> {
|
|
|
73
98
|
{{else if (eq database 'drizzle')}}
|
|
74
99
|
return db.$client.end();
|
|
75
100
|
{{else if (eq database 'mongoose')}}
|
|
101
|
+
{{#if useAuth}}
|
|
102
|
+
return Promise.all([disconnectDB(), mongoClient.close()]).then(() => undefined);
|
|
103
|
+
{{else}}
|
|
76
104
|
return disconnectDB();
|
|
105
|
+
{{/if}}
|
|
77
106
|
{{else}}
|
|
78
107
|
return Promise.resolve();
|
|
79
108
|
{{/if}}
|
|
@@ -16,6 +16,9 @@ import { AuthModule } from "./auth/auth.module.js";
|
|
|
16
16
|
import { DatabaseModule } from "./database/database.module.js";
|
|
17
17
|
{{/if}}
|
|
18
18
|
import { HealthController } from "./health/health.controller.js";
|
|
19
|
+
{{#if useAuth}}
|
|
20
|
+
import { MeController } from "./me/me.controller.js";
|
|
21
|
+
{{/if}}
|
|
19
22
|
{{#if (eq database 'prisma')}}
|
|
20
23
|
import { PrismaModule } from "./prisma/prisma.module.js";
|
|
21
24
|
{{/if}}
|
|
@@ -39,7 +42,7 @@ import { PrismaModule } from "./prisma/prisma.module.js";
|
|
|
39
42
|
ThrottlerModule.forRoot([{ ttl: 15 * 60 * 1000, limit: 100 }]),
|
|
40
43
|
{{/if}}
|
|
41
44
|
],
|
|
42
|
-
controllers: [HealthController],
|
|
45
|
+
controllers: [HealthController{{#if useAuth}}, MeController{{/if}}],
|
|
43
46
|
{{#if useRateLimit}}
|
|
44
47
|
providers: [{ provide: APP_GUARD, useClass: ThrottlerGuard }],
|
|
45
48
|
{{/if}}
|
|
@@ -22,8 +22,19 @@ const envSchema = z.object({
|
|
|
22
22
|
MONGODB_URI: z.url(),
|
|
23
23
|
{{/if}}
|
|
24
24
|
{{#if useAuth}}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
BETTER_AUTH_SECRET: z
|
|
26
|
+
.string()
|
|
27
|
+
.min(32, "BETTER_AUTH_SECRET must be at least 32 characters"),
|
|
28
|
+
// The public URL of this server; links in emails point here
|
|
29
|
+
BETTER_AUTH_URL: z.url(),
|
|
30
|
+
// Optional: GitHub and Google sign-in are turned on when both are set
|
|
31
|
+
GITHUB_CLIENT_ID: z.string().optional(),
|
|
32
|
+
GITHUB_CLIENT_SECRET: z.string().optional(),
|
|
33
|
+
GOOGLE_CLIENT_ID: z.string().optional(),
|
|
34
|
+
GOOGLE_CLIENT_SECRET: z.string().optional(),
|
|
35
|
+
// Optional: without it, emails are printed to the log
|
|
36
|
+
RESEND_API_KEY: z.string().optional(),
|
|
37
|
+
EMAIL_FROM: z.string().default("onboarding@resend.dev"),
|
|
27
38
|
{{/if}}
|
|
28
39
|
});
|
|
29
40
|
|
|
@@ -2,12 +2,19 @@ import { Controller, Get } from "@nestjs/common";
|
|
|
2
2
|
{{#if useRateLimit}}
|
|
3
3
|
import { SkipThrottle } from "@nestjs/throttler";
|
|
4
4
|
{{/if}}
|
|
5
|
+
{{#if useAuth}}
|
|
6
|
+
import { AllowAnonymous } from "@thallesp/nestjs-better-auth";
|
|
7
|
+
{{/if}}
|
|
5
8
|
|
|
6
9
|
{{#if useRateLimit}}
|
|
7
10
|
// Docker and load balancers call the health check on a schedule, so it is not
|
|
8
11
|
// counted
|
|
9
12
|
@SkipThrottle()
|
|
10
13
|
{{/if}}
|
|
14
|
+
{{#if useAuth}}
|
|
15
|
+
// Every route needs a session unless it is marked public
|
|
16
|
+
@AllowAnonymous()
|
|
17
|
+
{{/if}}
|
|
11
18
|
@Controller("health")
|
|
12
19
|
export class HealthController {
|
|
13
20
|
@Get()
|
|
@@ -7,11 +7,22 @@ import { AppModule } from "./app.module.js";
|
|
|
7
7
|
import { env } from "./env.js";
|
|
8
8
|
|
|
9
9
|
async function bootstrap(): Promise<void> {
|
|
10
|
+
{{#if useAuth}}
|
|
11
|
+
// Better Auth reads the body of its own routes; the auth module adds the
|
|
12
|
+
// JSON and form parsers back for every other route
|
|
13
|
+
const app = await NestFactory.create(AppModule, { bodyParser: false });
|
|
14
|
+
{{else}}
|
|
10
15
|
const app = await NestFactory.create(AppModule);
|
|
16
|
+
{{/if}}
|
|
11
17
|
const port = env.PORT;
|
|
12
18
|
|
|
13
19
|
app.use(helmet());
|
|
20
|
+
{{#if useAuth}}
|
|
21
|
+
// Browser clients read the bearer token from the set-auth-token header
|
|
22
|
+
app.enableCors({ origin: env.CORS_ORIGIN, exposedHeaders: ["set-auth-token"] });
|
|
23
|
+
{{else}}
|
|
14
24
|
app.enableCors({ origin: env.CORS_ORIGIN });
|
|
25
|
+
{{/if}}
|
|
15
26
|
// Lets modules close database connections when the process is stopped
|
|
16
27
|
app.enableShutdownHooks();
|
|
17
28
|
|
|
@@ -1,89 +1,129 @@
|
|
|
1
1
|
@import "tailwindcss";
|
|
2
|
+
@import "tw-animate-css";
|
|
3
|
+
@import "shadcn/tailwind.css";
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
--radius: 0.65rem;
|
|
5
|
-
--background: oklch(1 0 0);
|
|
6
|
-
--foreground: oklch(0.145 0 0);
|
|
7
|
-
--card: oklch(1 0 0);
|
|
8
|
-
--card-foreground: oklch(0.145 0 0);
|
|
9
|
-
--popover: oklch(1 0 0);
|
|
10
|
-
--popover-foreground: oklch(0.145 0 0);
|
|
11
|
-
--primary: oklch(0.205 0 0);
|
|
12
|
-
--primary-foreground: oklch(0.985 0 0);
|
|
13
|
-
--secondary: oklch(0.97 0 0);
|
|
14
|
-
--secondary-foreground: oklch(0.205 0 0);
|
|
15
|
-
--muted: oklch(0.97 0 0);
|
|
16
|
-
--muted-foreground: oklch(0.556 0 0);
|
|
17
|
-
--accent: oklch(0.97 0 0);
|
|
18
|
-
--accent-foreground: oklch(0.205 0 0);
|
|
19
|
-
--destructive: oklch(0.577 0.245 27.325);
|
|
20
|
-
--border: oklch(0.922 0 0);
|
|
21
|
-
--input: oklch(0.922 0 0);
|
|
22
|
-
--ring: oklch(0.708 0 0);
|
|
23
|
-
--chart-1: oklch(0.646 0.222 41.116);
|
|
24
|
-
--chart-2: oklch(0.6 0.118 184.704);
|
|
25
|
-
--chart-3: oklch(0.398 0.07 227.392);
|
|
26
|
-
--chart-4: oklch(0.828 0.189 84.429);
|
|
27
|
-
--chart-5: oklch(0.769 0.188 70.08);
|
|
28
|
-
--radius: 0.625rem;
|
|
29
|
-
--sidebar: oklch(0.985 0 0);
|
|
30
|
-
--sidebar-foreground: oklch(0.145 0 0);
|
|
31
|
-
--sidebar-primary: oklch(0.205 0 0);
|
|
32
|
-
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
33
|
-
--sidebar-accent: oklch(0.97 0 0);
|
|
34
|
-
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
35
|
-
--sidebar-border: oklch(0.922 0 0);
|
|
36
|
-
--sidebar-ring: oklch(0.708 0 0);
|
|
37
|
-
}
|
|
5
|
+
@custom-variant dark (&:is(.dark *));
|
|
38
6
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
7
|
+
@theme inline {
|
|
8
|
+
--font-heading: var(--font-sans);
|
|
9
|
+
--font-sans: var(--font-sans);
|
|
10
|
+
--color-sidebar-ring: var(--sidebar-ring);
|
|
11
|
+
--color-sidebar-border: var(--sidebar-border);
|
|
12
|
+
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
|
13
|
+
--color-sidebar-accent: var(--sidebar-accent);
|
|
14
|
+
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
|
|
15
|
+
--color-sidebar-primary: var(--sidebar-primary);
|
|
16
|
+
--color-sidebar-foreground: var(--sidebar-foreground);
|
|
17
|
+
--color-sidebar: var(--sidebar);
|
|
18
|
+
--color-chart-5: var(--chart-5);
|
|
19
|
+
--color-chart-4: var(--chart-4);
|
|
20
|
+
--color-chart-3: var(--chart-3);
|
|
21
|
+
--color-chart-2: var(--chart-2);
|
|
22
|
+
--color-chart-1: var(--chart-1);
|
|
23
|
+
--color-ring: var(--ring);
|
|
24
|
+
--color-input: var(--input);
|
|
25
|
+
--color-border: var(--border);
|
|
26
|
+
--color-destructive: var(--destructive);
|
|
27
|
+
--color-accent-foreground: var(--accent-foreground);
|
|
28
|
+
--color-accent: var(--accent);
|
|
29
|
+
--color-muted-foreground: var(--muted-foreground);
|
|
30
|
+
--color-muted: var(--muted);
|
|
31
|
+
--color-secondary-foreground: var(--secondary-foreground);
|
|
32
|
+
--color-secondary: var(--secondary);
|
|
33
|
+
--color-primary-foreground: var(--primary-foreground);
|
|
34
|
+
--color-primary: var(--primary);
|
|
35
|
+
--color-popover-foreground: var(--popover-foreground);
|
|
36
|
+
--color-popover: var(--popover);
|
|
37
|
+
--color-card-foreground: var(--card-foreground);
|
|
38
|
+
--color-card: var(--card);
|
|
39
|
+
--color-foreground: var(--foreground);
|
|
40
|
+
--color-background: var(--background);
|
|
41
|
+
--radius-sm: calc(var(--radius) * 0.6);
|
|
42
|
+
--radius-md: calc(var(--radius) * 0.8);
|
|
43
|
+
--radius-lg: var(--radius);
|
|
44
|
+
--radius-xl: calc(var(--radius) * 1.4);
|
|
45
|
+
--radius-2xl: calc(var(--radius) * 1.8);
|
|
46
|
+
--radius-3xl: calc(var(--radius) * 2.2);
|
|
47
|
+
--radius-4xl: calc(var(--radius) * 2.6);
|
|
74
48
|
}
|
|
75
49
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
50
|
+
:root {
|
|
51
|
+
--background: oklch(1 0 0);
|
|
52
|
+
--foreground: oklch(0.145 0 0);
|
|
53
|
+
--card: oklch(1 0 0);
|
|
54
|
+
--card-foreground: oklch(0.145 0 0);
|
|
55
|
+
--popover: oklch(1 0 0);
|
|
56
|
+
--popover-foreground: oklch(0.145 0 0);
|
|
57
|
+
--primary: oklch(0.205 0 0);
|
|
58
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
59
|
+
--secondary: oklch(0.97 0 0);
|
|
60
|
+
--secondary-foreground: oklch(0.205 0 0);
|
|
61
|
+
--muted: oklch(0.97 0 0);
|
|
62
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
63
|
+
--accent: oklch(0.97 0 0);
|
|
64
|
+
--accent-foreground: oklch(0.205 0 0);
|
|
65
|
+
--destructive: oklch(0.577 0.245 27.325);
|
|
66
|
+
--border: oklch(0.922 0 0);
|
|
67
|
+
--input: oklch(0.922 0 0);
|
|
68
|
+
--ring: oklch(0.708 0 0);
|
|
69
|
+
--chart-1: oklch(0.87 0 0);
|
|
70
|
+
--chart-2: oklch(0.556 0 0);
|
|
71
|
+
--chart-3: oklch(0.439 0 0);
|
|
72
|
+
--chart-4: oklch(0.371 0 0);
|
|
73
|
+
--chart-5: oklch(0.269 0 0);
|
|
74
|
+
--radius: 0.625rem;
|
|
75
|
+
--sidebar: oklch(0.985 0 0);
|
|
76
|
+
--sidebar-foreground: oklch(0.145 0 0);
|
|
77
|
+
--sidebar-primary: oklch(0.205 0 0);
|
|
78
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
79
|
+
--sidebar-accent: oklch(0.97 0 0);
|
|
80
|
+
--sidebar-accent-foreground: oklch(0.205 0 0);
|
|
81
|
+
--sidebar-border: oklch(0.922 0 0);
|
|
82
|
+
--sidebar-ring: oklch(0.708 0 0);
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
|
|
85
|
+
.dark {
|
|
86
|
+
--background: oklch(0.145 0 0);
|
|
87
|
+
--foreground: oklch(0.985 0 0);
|
|
88
|
+
--card: oklch(0.205 0 0);
|
|
89
|
+
--card-foreground: oklch(0.985 0 0);
|
|
90
|
+
--popover: oklch(0.205 0 0);
|
|
91
|
+
--popover-foreground: oklch(0.985 0 0);
|
|
92
|
+
--primary: oklch(0.922 0 0);
|
|
93
|
+
--primary-foreground: oklch(0.205 0 0);
|
|
94
|
+
--secondary: oklch(0.269 0 0);
|
|
95
|
+
--secondary-foreground: oklch(0.985 0 0);
|
|
96
|
+
--muted: oklch(0.269 0 0);
|
|
97
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
98
|
+
--accent: oklch(0.269 0 0);
|
|
99
|
+
--accent-foreground: oklch(0.985 0 0);
|
|
100
|
+
--destructive: oklch(0.704 0.191 22.216);
|
|
101
|
+
--border: oklch(1 0 0 / 10%);
|
|
102
|
+
--input: oklch(1 0 0 / 15%);
|
|
103
|
+
--ring: oklch(0.556 0 0);
|
|
104
|
+
--chart-1: oklch(0.87 0 0);
|
|
105
|
+
--chart-2: oklch(0.556 0 0);
|
|
106
|
+
--chart-3: oklch(0.439 0 0);
|
|
107
|
+
--chart-4: oklch(0.371 0 0);
|
|
108
|
+
--chart-5: oklch(0.269 0 0);
|
|
109
|
+
--sidebar: oklch(0.205 0 0);
|
|
110
|
+
--sidebar-foreground: oklch(0.985 0 0);
|
|
111
|
+
--sidebar-primary: oklch(0.488 0.243 264.376);
|
|
112
|
+
--sidebar-primary-foreground: oklch(0.985 0 0);
|
|
113
|
+
--sidebar-accent: oklch(0.269 0 0);
|
|
114
|
+
--sidebar-accent-foreground: oklch(0.985 0 0);
|
|
115
|
+
--sidebar-border: oklch(1 0 0 / 10%);
|
|
116
|
+
--sidebar-ring: oklch(0.556 0 0);
|
|
84
117
|
}
|
|
85
118
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
119
|
+
@layer base {
|
|
120
|
+
* {
|
|
121
|
+
@apply border-border outline-ring/50;
|
|
122
|
+
}
|
|
123
|
+
body {
|
|
124
|
+
@apply bg-background text-foreground;
|
|
125
|
+
}
|
|
126
|
+
html {
|
|
127
|
+
@apply font-sans;
|
|
128
|
+
}
|
|
89
129
|
}
|