create-mohit-next 0.0.0-stage → 1.0.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.
Files changed (82) hide show
  1. package/README.md +108 -2
  2. package/index.js +399 -0
  3. package/package.json +36 -4
  4. package/template/AGENTS.md +9 -0
  5. package/template/Dockerfile +48 -0
  6. package/template/README.md +262 -0
  7. package/template/_dockerignore +13 -0
  8. package/template/_env.example +11 -0
  9. package/template/_gitignore +42 -0
  10. package/template/_prettierignore +11 -0
  11. package/template/_prettierrc +9 -0
  12. package/template/components.json +25 -0
  13. package/template/docker-compose.yml +33 -0
  14. package/template/eslint.config.mjs +21 -0
  15. package/template/next.config.ts +45 -0
  16. package/template/package.json +53 -0
  17. package/template/public/robots.txt +6 -0
  18. package/template/src/app/(app)/admin/page.tsx +53 -0
  19. package/template/src/app/(app)/dashboard/page.tsx +127 -0
  20. package/template/src/app/(app)/error.tsx +28 -0
  21. package/template/src/app/(app)/layout.tsx +35 -0
  22. package/template/src/app/(app)/loading.tsx +5 -0
  23. package/template/src/app/(app)/reports/page.tsx +109 -0
  24. package/template/src/app/(auth)/layout.tsx +22 -0
  25. package/template/src/app/(auth)/login/page.tsx +18 -0
  26. package/template/src/app/(auth)/register/page.tsx +20 -0
  27. package/template/src/app/api/admin/users/[id]/route.ts +40 -0
  28. package/template/src/app/api/admin/users/route.ts +18 -0
  29. package/template/src/app/api/auth/login/route.ts +26 -0
  30. package/template/src/app/api/auth/logout/route.ts +21 -0
  31. package/template/src/app/api/auth/me/route.ts +19 -0
  32. package/template/src/app/api/auth/register/route.ts +40 -0
  33. package/template/src/app/api/health/route.ts +27 -0
  34. package/template/src/app/favicon.ico +0 -0
  35. package/template/src/app/forbidden/page.tsx +49 -0
  36. package/template/src/app/globals.css +142 -0
  37. package/template/src/app/layout.tsx +52 -0
  38. package/template/src/app/not-found.tsx +18 -0
  39. package/template/src/app/page.tsx +187 -0
  40. package/template/src/components/admin/users-table.tsx +162 -0
  41. package/template/src/components/auth/auth-card.tsx +41 -0
  42. package/template/src/components/auth/can.tsx +34 -0
  43. package/template/src/components/auth/form-field.tsx +32 -0
  44. package/template/src/components/auth/login-form.tsx +82 -0
  45. package/template/src/components/auth/register-form.tsx +114 -0
  46. package/template/src/components/auth/session-refresher.tsx +44 -0
  47. package/template/src/components/layout/logout-button.tsx +34 -0
  48. package/template/src/components/layout/navbar.tsx +67 -0
  49. package/template/src/components/layout/page-header.tsx +21 -0
  50. package/template/src/components/layout/skeletons.tsx +35 -0
  51. package/template/src/components/logo.tsx +19 -0
  52. package/template/src/components/motion/fade-in.tsx +19 -0
  53. package/template/src/components/providers/user-provider.tsx +60 -0
  54. package/template/src/components/reports/animated-bar.tsx +28 -0
  55. package/template/src/components/role-badge.tsx +17 -0
  56. package/template/src/components/theme-toggle.tsx +25 -0
  57. package/template/src/components/ui/badge.tsx +44 -0
  58. package/template/src/components/ui/button.tsx +66 -0
  59. package/template/src/components/ui/card.tsx +87 -0
  60. package/template/src/components/ui/input.tsx +18 -0
  61. package/template/src/components/ui/label.tsx +20 -0
  62. package/template/src/components/ui/native-select.tsx +54 -0
  63. package/template/src/components/ui/skeleton.tsx +13 -0
  64. package/template/src/config/rbac.ts +140 -0
  65. package/template/src/config/site.ts +4 -0
  66. package/template/src/lib/api.ts +143 -0
  67. package/template/src/lib/auth.ts +42 -0
  68. package/template/src/lib/dal.ts +60 -0
  69. package/template/src/lib/db.ts +35 -0
  70. package/template/src/lib/env.ts +36 -0
  71. package/template/src/lib/http.ts +57 -0
  72. package/template/src/lib/redirect.ts +21 -0
  73. package/template/src/lib/session.ts +67 -0
  74. package/template/src/lib/theme.ts +8 -0
  75. package/template/src/lib/users.ts +159 -0
  76. package/template/src/lib/utils.ts +1 -0
  77. package/template/src/lib/validations/auth.ts +44 -0
  78. package/template/src/lib/validations/user.ts +13 -0
  79. package/template/src/models/user.ts +30 -0
  80. package/template/src/proxy.ts +57 -0
  81. package/template/src/types/user.ts +10 -0
  82. package/template/tsconfig.json +34 -0
@@ -0,0 +1,262 @@
1
+ # {{PROJECT_TITLE}}
2
+
3
+ A full-stack **Next.js 16** + **TypeScript** app with MongoDB, JWT authentication and
4
+ role-based access control (RBAC), scaffolded with `create-mohit-next`.
5
+
6
+ | Area | Stack |
7
+ | ---------- | ----------------------------------------------------------------------- |
8
+ | Framework | Next.js 16 (App Router, Turbopack, Cache Components), React 19 |
9
+ | UI | Tailwind CSS v4, shadcn/ui (Radix), lucide-react, motion, sonner toasts |
10
+ | Data | MongoDB with Mongoose (cached connection) |
11
+ | Auth | bcryptjs (cost 12) + JWT (`jose`, HS256) in an httpOnly cookie |
12
+ | Validation | zod v4 (env vars + request/form schemas shared by client and server) |
13
+ | Forms | react-hook-form + @hookform/resolvers |
14
+ | Tooling | ESLint, Prettier (+ Tailwind class sorting), `typecheck` script |
15
+
16
+ ## Getting started
17
+
18
+ **Requirements:** Node.js 20.19+ and a MongoDB database.
19
+
20
+ ```bash
21
+ npm install # if you skipped it during scaffolding
22
+ ```
23
+
24
+ 1. **Environment.** `.env.local` was generated for you with a random `JWT_SECRET`. To recreate it,
25
+ copy `.env.example` to `.env.local` and fill in:
26
+
27
+ | Variable | Description |
28
+ | ------------- | -------------------------------------------------------------- |
29
+ | `MONGODB_URI` | e.g. `mongodb://localhost:27017/my-app` or a MongoDB Atlas URI |
30
+ | `JWT_SECRET` | At least 32 random characters, used to sign session tokens |
31
+
32
+ Variables are validated with zod the first time they are used, so `next build` works without them.
33
+
34
+ 2. **Database.** Use any MongoDB 6+ instance (a local install or MongoDB Atlas) and point
35
+ `MONGODB_URI` at it.
36
+
37
+ 3. **Run it.**
38
+
39
+ ```bash
40
+ npm run dev
41
+ ```
42
+
43
+ Open http://localhost:3000 and register. **The first account becomes `admin`**; every account
44
+ after that starts as `user`. Promote people from **/admin**.
45
+
46
+ ### Scripts
47
+
48
+ | Script | What it does |
49
+ | ---------------------- | ----------------------------------------- |
50
+ | `npm run dev` | Dev server with Turbopack |
51
+ | `npm run build` | Production build (`.next/standalone`) |
52
+ | `npm run start` | Serve the production build |
53
+ | `npm run lint` | ESLint |
54
+ | `npm run typecheck` | Generate route types, then `tsc --noEmit` |
55
+ | `npm run format` | Prettier (with Tailwind class sorting) |
56
+ | `npm run format:check` | Check formatting (CI) |
57
+
58
+ <!-- docker:start -->
59
+
60
+ ## Docker
61
+
62
+ | Script | What it does |
63
+ | --------------------- | --------------------------------------------- |
64
+ | `npm run docker:db` | Start only MongoDB (for `npm run dev`) |
65
+ | `npm run docker:up` | Build the image and start the app + MongoDB |
66
+ | `npm run docker:down` | Stop the containers (the data volume is kept) |
67
+
68
+ - The `Dockerfile` is multi-stage: deps → build → a slim runtime containing only `.next/standalone`,
69
+ running as a non-root user with a `HEALTHCHECK` on `/api/health`.
70
+ - `docker-compose.yml` reads `JWT_SECRET` from `.env.local` and points `MONGODB_URI` at the `mongo`
71
+ service. Data persists in the `mongo-data` volume.
72
+ - In production (`NODE_ENV=production`) the session cookie is `Secure`, so serve the app over HTTPS
73
+ (browsers allow it on `http://localhost`).
74
+
75
+ <!-- docker:end -->
76
+
77
+ ## Folder structure
78
+
79
+ ```
80
+ src/
81
+ ├── app/
82
+ │ ├── (auth)/ # /login, /register (guest-only)
83
+ │ ├── (app)/ # authenticated shell: navbar + pages
84
+ │ │ ├── layout.tsx # loads the user inside <Suspense>, provides UserProvider
85
+ │ │ ├── dashboard/ # any signed-in user
86
+ │ │ ├── reports/ # manager+
87
+ │ │ └── admin/ # manager (read-only) / admin (manage)
88
+ │ ├── api/
89
+ │ │ ├── auth/ # register, login, logout, me
90
+ │ │ ├── admin/users/ # list, PATCH role, DELETE
91
+ │ │ └── health/
92
+ │ ├── forbidden/ # 403 page
93
+ │ ├── layout.tsx # root layout, theme script, toaster
94
+ │ └── page.tsx # landing page
95
+ ├── components/
96
+ │ ├── ui/ # shadcn/ui components (add more with `npx shadcn add`)
97
+ │ ├── auth/ # <Can>, login/register forms
98
+ │ ├── providers/ # UserProvider + useUser()
99
+ │ └── ...
100
+ ├── config/
101
+ │ ├── rbac.ts # ★ roles, permissions, route rules, nav (single source of truth)
102
+ │ └── site.ts
103
+ ├── lib/
104
+ │ ├── api.ts # withAuth(), ApiError, parseBody()
105
+ │ ├── auth.ts # password hashing, session cookie helpers
106
+ │ ├── dal.ts # getCurrentUser(), requireUser(), requirePermission()
107
+ │ ├── db.ts # cached Mongoose connection
108
+ │ ├── env.ts # lazy zod-validated env
109
+ │ ├── session.ts # JWT sign/verify (jose)
110
+ │ ├── users.ts # user queries
111
+ │ └── validations/ # zod schemas shared by client + server
112
+ ├── models/user.ts # Mongoose model
113
+ └── proxy.ts # route protection (Next.js 16's replacement for middleware.ts)
114
+ ```
115
+
116
+ ## How RBAC works
117
+
118
+ Everything starts in [`src/config/rbac.ts`](src/config/rbac.ts):
119
+
120
+ ```ts
121
+ ROLES = ["user", "manager", "admin"] // lowest → highest
122
+ ROLE_PERMISSIONS = {
123
+ user: ["dashboard:view"],
124
+ manager: ["dashboard:view", "reports:view", "users:read"],
125
+ admin: [...everything, "users:update-role", "users:delete"],
126
+ }
127
+ ROUTE_RULES = [{ prefix: "/reports", permission: "reports:view" }, ...] // longest prefix wins
128
+ ```
129
+
130
+ Each request is checked in **three layers**:
131
+
132
+ | Layer | Where | Checks | Why |
133
+ | ----- | -------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------- |
134
+ | 1 | `src/proxy.ts` | The JWT's role | Fast redirects: signed out → `/login?next=…`, no permission → `/forbidden`, signed in → away from `/login` |
135
+ | 2 | `src/lib/dal.ts` | The user **in MongoDB** | Source of truth: role changes and deleted accounts apply on the next request |
136
+ | 3 | `withAuth()` in `src/lib/api.ts` | The user **in MongoDB** | Route handlers answer `401`/`403` JSON |
137
+
138
+ On the client, `useUser()` and `<Can permission="…">` hide UI the user can't use. That's only
139
+ cosmetic: the server always re-checks.
140
+
141
+ **Stale tokens.** The JWT stores the role so the proxy can stay database-free. After an admin
142
+ changes someone's role, layers 2 and 3 use the new role immediately. The app shell notices that
143
+ the token is out of date and calls `GET /api/auth/me`, which re-issues the cookie. The `/forbidden`
144
+ page does the same, so a freshly promoted user can just retry.
145
+
146
+ ### Add a role
147
+
148
+ ```ts
149
+ // src/config/rbac.ts
150
+ export const ROLES = ["user", "editor", "manager", "admin"] as const; // keep the order
151
+
152
+ export const ROLE_PERMISSIONS = {
153
+ user: ["dashboard:view"],
154
+ editor: ["dashboard:view", "reports:view"],
155
+ // ...
156
+ };
157
+ // Also add a label to ROLE_LABELS (TypeScript will flag any map you forget).
158
+ ```
159
+
160
+ The Mongoose enum, zod schemas and the admin role selector all read from `ROLES`, so nothing else
161
+ needs to change. (Optionally add a color in `src/components/role-badge.tsx`.)
162
+
163
+ ### Add a permission
164
+
165
+ ```ts
166
+ export const PERMISSIONS = [..., "billing:manage"] as const;
167
+ export const PERMISSION_LABELS = { ..., "billing:manage": "Manage billing" };
168
+ export const ROLE_PERMISSIONS = { ..., admin: [..., "billing:manage"] };
169
+ ```
170
+
171
+ ### Protect a page
172
+
173
+ 1. Add a route rule (layer 1) and, optionally, a nav item:
174
+
175
+ ```ts
176
+ ROUTE_RULES = [..., { prefix: "/billing", permission: "billing:manage" }];
177
+ NAV_ITEMS = [..., { href: "/billing", label: "Billing", permission: "billing:manage" }];
178
+ ```
179
+
180
+ 2. Create `src/app/(app)/billing/page.tsx` and check on the server (layer 2):
181
+
182
+ ```tsx
183
+ import { requirePermission } from "@/lib/dal";
184
+
185
+ export default async function BillingPage() {
186
+ const user = await requirePermission("billing:manage"); // redirects to /forbidden otherwise
187
+ return <h1>Billing for {user.name}</h1>;
188
+ }
189
+ ```
190
+
191
+ Pages inside `(app)` already render inside a `<Suspense>` boundary (the layout and
192
+ `loading.tsx`), which Cache Components requires for anything that reads cookies or the database.
193
+ If you read the user somewhere else, wrap that component in `<Suspense>` and don't `await` it
194
+ at a layout's top level.
195
+
196
+ 3. Hide or show UI with `<Can>`:
197
+
198
+ ```tsx
199
+ <Can permission="billing:manage" fallback={<p>Read only</p>}>
200
+ <Button>Edit plan</Button>
201
+ </Can>
202
+ ```
203
+
204
+ ### Protect an API route
205
+
206
+ ```ts
207
+ // src/app/api/invoices/[id]/route.ts
208
+ import { NextResponse } from "next/server";
209
+ import { ApiError, parseBody, withAuth } from "@/lib/api";
210
+
211
+ export const PATCH = withAuth<RouteContext<"/api/invoices/[id]">>(
212
+ async (req, ctx, user) => {
213
+ const { id } = await ctx.params; // params are a Promise in Next.js 16
214
+ const body = await parseBody(req, invoiceSchema); // 400 bad JSON / 422 validation
215
+ if (!invoice) throw ApiError.notFound("Invoice not found");
216
+ return NextResponse.json({ invoice });
217
+ },
218
+ { permission: "billing:manage" }, // 401 if signed out, 403 without permission
219
+ );
220
+ ```
221
+
222
+ Errors always use one JSON shape: `{ "error": { "code": "FORBIDDEN", "message": "...", "details"?: ... } }`.
223
+
224
+ ## API
225
+
226
+ | Method | Route | Access | Notes |
227
+ | ------ | ---------------------- | ------------------- | -------------------------------------------------- |
228
+ | POST | `/api/auth/register` | public | `{ name, email, password }`; first user → admin |
229
+ | POST | `/api/auth/login` | public | `{ email, password }`; generic error on failure |
230
+ | POST | `/api/auth/logout` | public | Clears the session cookie |
231
+ | GET | `/api/auth/me` | signed in | Current user + permissions; refreshes stale tokens |
232
+ | GET | `/api/admin/users` | `users:read` | `?page=1&limit=50` |
233
+ | PATCH | `/api/admin/users/:id` | `users:update-role` | `{ role }`; you can't change your own role |
234
+ | DELETE | `/api/admin/users/:id` | `users:delete` | You can't delete yourself |
235
+ | GET | `/api/health` | public | `200` when the database is reachable, else `503` |
236
+
237
+ ## Security notes
238
+
239
+ - Passwords are hashed with bcrypt (cost 12). Login always runs one bcrypt comparison (against a
240
+ dummy hash for unknown emails) and returns the same error, so responses don't reveal which emails exist.
241
+ - Session cookie: `httpOnly`, `SameSite=Lax`, `Secure` in production, expires after 7 days.
242
+ - `?next=` redirects only accept same-origin relative paths.
243
+ - Security headers (`X-Frame-Options`, `X-Content-Type-Options`, `Referrer-Policy`,
244
+ `Permissions-Policy`, HSTS) are set in `next.config.ts`. Add a Content-Security-Policy once you
245
+ know which origins you need.
246
+ - The "first user becomes admin" claim is atomic (a unique `_id` in the `app_meta` collection), so
247
+ concurrent sign-ups on an empty database can't create two admins.
248
+ - Before going live, consider adding rate limiting to `/api/auth/*`.
249
+
250
+ ## Adding UI components
251
+
252
+ shadcn/ui is configured (`components.json`, style `radix-nova`), so you can add more components:
253
+
254
+ ```bash
255
+ npx shadcn@latest add dialog dropdown-menu table
256
+ ```
257
+
258
+ ## Learn more
259
+
260
+ This project uses Next.js 16, which differs from older versions (for example, `middleware.ts` is
261
+ now `proxy.ts`, and `params` are Promises). Its docs ship with the package in
262
+ `node_modules/next/dist/docs/`; see `AGENTS.md`.
@@ -0,0 +1,13 @@
1
+ .git
2
+ .next
3
+ node_modules
4
+ npm-debug.log*
5
+ Dockerfile
6
+ docker-compose.yml
7
+ .dockerignore
8
+ .env*
9
+ !.env.example
10
+ README.md
11
+ coverage
12
+ .vscode
13
+ .idea
@@ -0,0 +1,11 @@
1
+ # Copy to .env.local and fill in (create-mohit-next already did this for you).
2
+ # Never commit real secrets.
3
+
4
+ # MongoDB connection string.
5
+ # Local / `npm run docker:db`: mongodb://localhost:27017/my-app
6
+ # Atlas: mongodb+srv://<user>:<password>@<cluster>.mongodb.net/my-app
7
+ MONGODB_URI=mongodb://localhost:27017/my-app
8
+
9
+ # Secret used to sign session JWTs (HS256). At least 32 characters.
10
+ # Generate one with: node -e "console.log(require('crypto').randomBytes(48).toString('base64url'))"
11
+ JWT_SECRET=change-me-to-a-long-random-string-of-at-least-32-chars
@@ -0,0 +1,42 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.*
7
+ .yarn/*
8
+ !.yarn/patches
9
+ !.yarn/plugins
10
+ !.yarn/releases
11
+ !.yarn/versions
12
+
13
+ # testing
14
+ /coverage
15
+
16
+ # next.js
17
+ /.next/
18
+ /out/
19
+
20
+ # production
21
+ /build
22
+
23
+ # misc
24
+ .DS_Store
25
+ *.pem
26
+
27
+ # debug
28
+ npm-debug.log*
29
+ yarn-debug.log*
30
+ yarn-error.log*
31
+ .pnpm-debug.log*
32
+
33
+ # env files (can opt-in for committing if needed)
34
+ .env*
35
+ !.env.example
36
+
37
+ # vercel
38
+ .vercel
39
+
40
+ # typescript
41
+ *.tsbuildinfo
42
+ next-env.d.ts
@@ -0,0 +1,11 @@
1
+ .next
2
+ out
3
+ build
4
+ node_modules
5
+ package-lock.json
6
+ pnpm-lock.yaml
7
+ yarn.lock
8
+ bun.lock
9
+ next-env.d.ts
10
+ # Rewritten by create-mohit-next for your package manager; format manually if you like.
11
+ README.md
@@ -0,0 +1,9 @@
1
+ {
2
+ "semi": true,
3
+ "singleQuote": false,
4
+ "trailingComma": "all",
5
+ "printWidth": 100,
6
+ "plugins": ["prettier-plugin-tailwindcss"],
7
+ "tailwindStylesheet": "./src/app/globals.css",
8
+ "tailwindFunctions": ["cn", "cva"]
9
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "radix-nova",
4
+ "rsc": true,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/app/globals.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "iconLibrary": "lucide",
14
+ "rtl": false,
15
+ "aliases": {
16
+ "components": "@/components",
17
+ "utils": "@/lib/utils",
18
+ "ui": "@/components/ui",
19
+ "lib": "@/lib",
20
+ "hooks": "@/hooks"
21
+ },
22
+ "menuColor": "default",
23
+ "menuAccent": "subtle",
24
+ "registries": {}
25
+ }
@@ -0,0 +1,33 @@
1
+ services:
2
+ app:
3
+ build: .
4
+ ports:
5
+ - "3000:3000"
6
+ env_file:
7
+ - path: .env.local
8
+ required: false
9
+ environment:
10
+ NODE_ENV: production
11
+ # Inside the compose network MongoDB is reachable as "mongo".
12
+ MONGODB_URI: mongodb://mongo:27017/app
13
+ depends_on:
14
+ mongo:
15
+ condition: service_healthy
16
+ restart: unless-stopped
17
+
18
+ mongo:
19
+ image: mongo:8
20
+ ports:
21
+ - "27017:27017"
22
+ volumes:
23
+ - mongo-data:/data/db
24
+ healthcheck:
25
+ test: ["CMD", "mongosh", "--quiet", "--eval", "db.adminCommand('ping').ok"]
26
+ interval: 10s
27
+ timeout: 5s
28
+ retries: 5
29
+ start_period: 10s
30
+ restart: unless-stopped
31
+
32
+ volumes:
33
+ mongo-data:
@@ -0,0 +1,21 @@
1
+ import { defineConfig, globalIgnores } from "eslint/config";
2
+ import nextVitals from "eslint-config-next/core-web-vitals";
3
+ import nextTs from "eslint-config-next/typescript";
4
+ import prettier from "eslint-config-prettier/flat";
5
+
6
+ const eslintConfig = defineConfig([
7
+ ...nextVitals,
8
+ ...nextTs,
9
+ // Turn off stylistic rules that conflict with Prettier (keep this last).
10
+ prettier,
11
+ // Override default ignores of eslint-config-next.
12
+ globalIgnores([
13
+ // Default ignores of eslint-config-next:
14
+ ".next/**",
15
+ "out/**",
16
+ "build/**",
17
+ "next-env.d.ts",
18
+ ]),
19
+ ]);
20
+
21
+ export default eslintConfig;
@@ -0,0 +1,45 @@
1
+ import type { NextConfig } from "next";
2
+
3
+ /**
4
+ * Baseline security headers applied to every response.
5
+ * Add a Content-Security-Policy once you know which origins your app needs:
6
+ * see node_modules/next/dist/docs/01-app/02-guides/content-security-policy.md
7
+ */
8
+ const securityHeaders = [
9
+ { key: "X-Content-Type-Options", value: "nosniff" },
10
+ { key: "X-Frame-Options", value: "DENY" },
11
+ { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
12
+ { key: "X-DNS-Prefetch-Control", value: "on" },
13
+ {
14
+ key: "Permissions-Policy",
15
+ value: "camera=(), microphone=(), geolocation=(), browsing-topics=()",
16
+ },
17
+ // Only honoured over HTTPS; harmless on http://localhost.
18
+ {
19
+ key: "Strict-Transport-Security",
20
+ value: "max-age=63072000; includeSubDomains",
21
+ },
22
+ ];
23
+
24
+ const nextConfig: NextConfig = {
25
+ // Self-contained server build used by the Dockerfile (.next/standalone).
26
+ output: "standalone",
27
+ poweredByHeader: false,
28
+ cacheComponents: true,
29
+ partialPrefetching: true,
30
+ // Mongoose relies on Node.js internals; load it natively instead of bundling.
31
+ serverExternalPackages: ["mongoose"],
32
+ turbopack: {
33
+ rules: {
34
+ "*.css": {
35
+ loaders: ["@tailwindcss/turbopack"],
36
+ as: "*.css",
37
+ },
38
+ },
39
+ },
40
+ async headers() {
41
+ return [{ source: "/:path*", headers: securityHeaders }];
42
+ },
43
+ };
44
+
45
+ export default nextConfig;
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "my-app",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "scripts": {
6
+ "dev": "next dev",
7
+ "build": "next build",
8
+ "start": "next start",
9
+ "lint": "eslint",
10
+ "typecheck": "next typegen && tsc --noEmit",
11
+ "format": "prettier --write .",
12
+ "format:check": "prettier --check .",
13
+ "docker:db": "docker compose up -d mongo",
14
+ "docker:up": "docker compose up -d --build",
15
+ "docker:down": "docker compose down"
16
+ },
17
+ "dependencies": {
18
+ "@hookform/resolvers": "^7.0.6",
19
+ "bcryptjs": "^3.0.3",
20
+ "class-variance-authority": "^0.7.1",
21
+ "cn": "^0.5.2",
22
+ "jose": "^6.2.17",
23
+ "lucide-react": "^1.73.0",
24
+ "mongoose": "^9.12.1",
25
+ "motion": "^14.14.0",
26
+ "next": "16.4.6",
27
+ "radix-ui": "^1.8.1",
28
+ "react": "19.3.0",
29
+ "react-dom": "19.3.0",
30
+ "react-hook-form": "^7.92.0",
31
+ "server-only": "^0.0.1",
32
+ "sonner": "^2.0.8",
33
+ "tw-animate-css": "^1.4.0",
34
+ "zod": "^4.6.7"
35
+ },
36
+ "devDependencies": {
37
+ "@tailwindcss/turbopack": "4.3.3",
38
+ "@types/node": "^20",
39
+ "@types/react": "^19",
40
+ "@types/react-dom": "^19",
41
+ "eslint": "^9",
42
+ "eslint-config-next": "16.4.6",
43
+ "eslint-config-prettier": "^10.1.8",
44
+ "prettier": "^3.10.1",
45
+ "prettier-plugin-tailwindcss": "^0.8.1",
46
+ "shadcn": "^4.23.0",
47
+ "tailwindcss": "4.3.3",
48
+ "typescript": "^5"
49
+ },
50
+ "engines": {
51
+ "node": ">=20.19.0"
52
+ }
53
+ }
@@ -0,0 +1,6 @@
1
+ User-agent: *
2
+ Allow: /
3
+ Disallow: /api/
4
+ Disallow: /admin
5
+ Disallow: /dashboard
6
+ Disallow: /reports
@@ -0,0 +1,53 @@
1
+ import { Eye } from "lucide-react";
2
+ import type { Metadata } from "next";
3
+
4
+ import { UsersTable } from "@/components/admin/users-table";
5
+ import { Can } from "@/components/auth/can";
6
+ import { PageHeader } from "@/components/layout/page-header";
7
+ import { Badge } from "@/components/ui/badge";
8
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
9
+ import { requirePermission } from "@/lib/dal";
10
+ import { listUsers } from "@/lib/users";
11
+
12
+ export const metadata: Metadata = { title: "Admin" };
13
+
14
+ export default async function AdminPage() {
15
+ // Managers (users:read) can view; mutations need users:update-role / users:delete,
16
+ // which are enforced again by the API routes.
17
+ const user = await requirePermission("users:read");
18
+ const { users, total } = await listUsers({ limit: 100 });
19
+
20
+ return (
21
+ <>
22
+ <PageHeader
23
+ title="User management"
24
+ description="Everyone with an account. Role changes apply on the user's next request."
25
+ actions={
26
+ <Can
27
+ permission="users:update-role"
28
+ fallback={
29
+ <Badge variant="outline" className="gap-1">
30
+ <Eye /> Read-only access
31
+ </Badge>
32
+ }
33
+ >
34
+ <Badge variant="outline">Full access</Badge>
35
+ </Can>
36
+ }
37
+ />
38
+
39
+ <Card>
40
+ <CardHeader>
41
+ <CardTitle>Users</CardTitle>
42
+ <CardDescription>
43
+ {total} {total === 1 ? "account" : "accounts"}
44
+ {total > users.length && ` (showing the ${users.length} most recent)`}
45
+ </CardDescription>
46
+ </CardHeader>
47
+ <CardContent className="px-0">
48
+ <UsersTable users={users} currentUserId={user.id} />
49
+ </CardContent>
50
+ </Card>
51
+ </>
52
+ );
53
+ }