create-mohit-next 1.0.0 → 2.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 (220) hide show
  1. package/README.md +96 -65
  2. package/index.js +195 -195
  3. package/lib/features.js +358 -0
  4. package/lib/scaffold.js +471 -0
  5. package/package.json +10 -6
  6. package/templates/common/_editorconfig +12 -0
  7. package/templates/common/_gitattributes +5 -0
  8. package/templates/common/_github/dependabot.yml +14 -0
  9. package/templates/common/_github/workflows/ci.yml +66 -0
  10. package/templates/common/_husky/commit-msg +1 -0
  11. package/templates/common/_husky/pre-commit +1 -0
  12. package/templates/common/_nvmrc +1 -0
  13. package/{template → templates/common}/_prettierignore +4 -0
  14. package/templates/common/commitlint.config.mjs +10 -0
  15. package/templates/next/README.md +328 -0
  16. package/{template → templates/next}/_env.example +10 -1
  17. package/{template → templates/next}/_gitignore +8 -0
  18. package/templates/next/e2e/rbac.spec.ts +69 -0
  19. package/templates/next/e2e/server.mjs +35 -0
  20. package/{template → templates/next}/eslint.config.mjs +12 -0
  21. package/{template → templates/next}/next.config.ts +2 -0
  22. package/{template → templates/next}/package.json +18 -3
  23. package/templates/next/playwright.config.ts +30 -0
  24. package/templates/next/scripts/seed.ts +111 -0
  25. package/templates/next/src/app/(app)/admin/audit/page.tsx +99 -0
  26. package/templates/next/src/app/(app)/admin/page.tsx +92 -0
  27. package/{template → templates/next}/src/app/(app)/dashboard/page.tsx +22 -29
  28. package/{template → templates/next}/src/app/(app)/error.tsx +7 -7
  29. package/{template → templates/next}/src/app/(app)/layout.tsx +25 -2
  30. package/templates/next/src/app/(app)/reports/page.tsx +128 -0
  31. package/templates/next/src/app/(app)/settings/page.tsx +66 -0
  32. package/templates/next/src/app/(auth)/forgot-password/page.tsx +17 -0
  33. package/templates/next/src/app/(auth)/layout.tsx +18 -0
  34. package/{template → templates/next}/src/app/(auth)/register/page.tsx +2 -4
  35. package/templates/next/src/app/(auth)/reset-password/page.tsx +18 -0
  36. package/templates/next/src/app/api/account/password/route.ts +45 -0
  37. package/templates/next/src/app/api/account/route.ts +25 -0
  38. package/templates/next/src/app/api/account/sessions/route.ts +12 -0
  39. package/templates/next/src/app/api/admin/audit/route.ts +13 -0
  40. package/{template → templates/next}/src/app/api/admin/users/[id]/route.ts +25 -4
  41. package/templates/next/src/app/api/auth/forgot-password/route.ts +47 -0
  42. package/{template → templates/next}/src/app/api/auth/login/route.ts +19 -2
  43. package/{template → templates/next}/src/app/api/auth/me/route.ts +4 -2
  44. package/{template → templates/next}/src/app/api/auth/register/route.ts +38 -4
  45. package/templates/next/src/app/api/auth/resend-verification/route.ts +25 -0
  46. package/templates/next/src/app/api/auth/reset-password/route.ts +43 -0
  47. package/templates/next/src/app/api/auth/verify-email/route.ts +29 -0
  48. package/{template → templates/next}/src/app/forbidden/page.tsx +11 -13
  49. package/{template → templates/next}/src/app/layout.tsx +9 -6
  50. package/templates/next/src/app/not-found.tsx +20 -0
  51. package/templates/next/src/app/opengraph-image.tsx +49 -0
  52. package/templates/next/src/app/page.tsx +165 -0
  53. package/templates/next/src/app/robots.ts +15 -0
  54. package/templates/next/src/app/sitemap.ts +13 -0
  55. package/templates/next/src/app/verify-email/page.tsx +23 -0
  56. package/templates/next/src/components/admin/user-actions.tsx +124 -0
  57. package/templates/next/src/components/admin/users-data-table.tsx +221 -0
  58. package/templates/next/src/components/admin/users-table.tsx +67 -0
  59. package/{template → templates/next}/src/components/auth/auth-card.tsx +8 -8
  60. package/templates/next/src/components/auth/forgot-password-form.tsx +76 -0
  61. package/templates/next/src/components/auth/form-field.tsx +40 -0
  62. package/{template → templates/next}/src/components/auth/login-form.tsx +14 -9
  63. package/templates/next/src/components/auth/password-input.tsx +43 -0
  64. package/{template → templates/next}/src/components/auth/register-form.tsx +22 -19
  65. package/templates/next/src/components/auth/reset-password-form.tsx +80 -0
  66. package/{template → templates/next}/src/components/auth/session-refresher.tsx +1 -1
  67. package/templates/next/src/components/auth/verify-email-banner.tsx +43 -0
  68. package/templates/next/src/components/auth/verify-email-status.tsx +44 -0
  69. package/templates/next/src/components/layout/nav-links.tsx +37 -0
  70. package/templates/next/src/components/layout/navbar.tsx +27 -0
  71. package/templates/next/src/components/layout/page-header.tsx +21 -0
  72. package/templates/next/src/components/layout/sidebar.tsx +83 -0
  73. package/templates/next/src/components/layout/skeletons.tsx +57 -0
  74. package/templates/next/src/components/layout/user-menu.tsx +118 -0
  75. package/{template → templates/next}/src/components/logo.tsx +3 -6
  76. package/{template → templates/next}/src/components/reports/animated-bar.tsx +1 -5
  77. package/templates/next/src/components/reports/role-chart.tsx +61 -0
  78. package/templates/next/src/components/reports/signups-chart.tsx +64 -0
  79. package/templates/next/src/components/role-badge.tsx +11 -0
  80. package/templates/next/src/components/settings/password-form.tsx +80 -0
  81. package/templates/next/src/components/settings/profile-form.tsx +63 -0
  82. package/templates/next/src/components/settings/sessions-card.tsx +70 -0
  83. package/templates/next/src/components/theme-toggle.tsx +61 -0
  84. package/templates/next/src/config/rbac.test.ts +89 -0
  85. package/{template → templates/next}/src/config/rbac.ts +35 -5
  86. package/{template → templates/next}/src/lib/api.ts +40 -4
  87. package/templates/next/src/lib/audit.ts +66 -0
  88. package/{template → templates/next}/src/lib/auth.ts +10 -2
  89. package/{template → templates/next}/src/lib/dal.ts +8 -5
  90. package/templates/next/src/lib/email-templates.ts +55 -0
  91. package/templates/next/src/lib/email.ts +53 -0
  92. package/templates/next/src/lib/env.ts +90 -0
  93. package/templates/next/src/lib/password-strength.test.ts +20 -0
  94. package/templates/next/src/lib/password-strength.ts +24 -0
  95. package/templates/next/src/lib/rate-limit.test.ts +47 -0
  96. package/templates/next/src/lib/rate-limit.ts +70 -0
  97. package/templates/next/src/lib/redirect.test.ts +23 -0
  98. package/{template → templates/next}/src/lib/session.ts +5 -1
  99. package/templates/next/src/lib/theme.ts +32 -0
  100. package/templates/next/src/lib/tokens.ts +63 -0
  101. package/{template → templates/next}/src/lib/users.ts +49 -12
  102. package/templates/next/src/lib/validations/account.ts +20 -0
  103. package/templates/next/src/lib/validations/auth.test.ts +39 -0
  104. package/{template → templates/next}/src/lib/validations/auth.ts +24 -2
  105. package/templates/next/src/models/audit-log.ts +33 -0
  106. package/templates/next/src/models/auth-token.ts +26 -0
  107. package/{template → templates/next}/src/models/user.ts +5 -0
  108. package/{template → templates/next}/src/proxy.ts +1 -1
  109. package/templates/next/src/styles/app.css +1092 -0
  110. package/{template → templates/next}/src/types/user.ts +3 -0
  111. package/templates/next/vitest.config.mts +13 -0
  112. package/templates/styles/css.css +580 -0
  113. package/templates/styles/tailwind.css +140 -0
  114. package/templates/ui/css/components/alert-dialog.tsx +172 -0
  115. package/templates/ui/css/components/avatar.tsx +17 -0
  116. package/templates/ui/css/components/badge.tsx +18 -0
  117. package/templates/ui/css/components/button.tsx +41 -0
  118. package/templates/ui/css/components/card.tsx +33 -0
  119. package/templates/ui/css/components/dropdown-menu.tsx +230 -0
  120. package/templates/ui/css/components/input.tsx +7 -0
  121. package/templates/ui/css/components/label.tsx +7 -0
  122. package/templates/ui/css/components/native-select.tsx +23 -0
  123. package/templates/ui/css/components/skeleton.tsx +7 -0
  124. package/templates/ui/css/components/slot.tsx +30 -0
  125. package/templates/ui/css/components/table.tsx +31 -0
  126. package/templates/ui/css/utils.ts +16 -0
  127. package/templates/ui/shadcn/components/alert-dialog.tsx +199 -0
  128. package/templates/ui/shadcn/components/avatar.tsx +111 -0
  129. package/templates/ui/shadcn/components/dropdown-menu.tsx +268 -0
  130. package/templates/ui/shadcn/components/table.tsx +115 -0
  131. package/templates/ui/tailwind/components/alert-dialog.tsx +177 -0
  132. package/templates/ui/tailwind/components/avatar.tsx +36 -0
  133. package/templates/ui/tailwind/components/badge.tsx +29 -0
  134. package/templates/ui/tailwind/components/button.tsx +65 -0
  135. package/templates/ui/tailwind/components/card.tsx +70 -0
  136. package/templates/ui/tailwind/components/dropdown-menu.tsx +236 -0
  137. package/templates/ui/tailwind/components/input.tsx +17 -0
  138. package/templates/ui/tailwind/components/label.tsx +16 -0
  139. package/templates/ui/tailwind/components/native-select.tsx +32 -0
  140. package/templates/ui/tailwind/components/skeleton.tsx +13 -0
  141. package/templates/ui/tailwind/components/slot.tsx +34 -0
  142. package/templates/ui/tailwind/components/table.tsx +56 -0
  143. package/templates/ui/tailwind/utils.ts +1 -0
  144. package/templates/vite/Dockerfile +29 -0
  145. package/templates/vite/README.md +142 -0
  146. package/templates/vite/_dockerignore +14 -0
  147. package/templates/vite/_env.example +8 -0
  148. package/templates/vite/_gitignore +37 -0
  149. package/templates/vite/e2e/app.spec.ts +41 -0
  150. package/templates/vite/index.html +32 -0
  151. package/templates/vite/nginx.conf +26 -0
  152. package/templates/vite/package.json +61 -0
  153. package/templates/vite/playwright.config.ts +27 -0
  154. package/templates/vite/public/favicon.svg +1 -0
  155. package/templates/vite/src/App.test.tsx +28 -0
  156. package/templates/vite/src/App.tsx +26 -0
  157. package/templates/vite/src/components/home.tsx +121 -0
  158. package/templates/vite/src/components/layout/root-layout.tsx +18 -0
  159. package/templates/vite/src/components/layout/site-footer.tsx +10 -0
  160. package/templates/vite/src/components/layout/site-header.tsx +49 -0
  161. package/templates/vite/src/components/theme-toggle.tsx +90 -0
  162. package/templates/vite/src/env.ts +36 -0
  163. package/templates/vite/src/lib/theme.ts +26 -0
  164. package/templates/vite/src/main.tsx +13 -0
  165. package/templates/vite/src/pages/about.tsx +52 -0
  166. package/templates/vite/src/pages/not-found.tsx +33 -0
  167. package/templates/vite/src/router.ts +24 -0
  168. package/templates/vite/src/styles/app.css +281 -0
  169. package/templates/vite/src/test/setup.ts +21 -0
  170. package/templates/vite/tsconfig.app.json +31 -0
  171. package/templates/vite/tsconfig.json +7 -0
  172. package/templates/vite/tsconfig.node.json +23 -0
  173. package/templates/vite/vite.config.ts +30 -0
  174. package/template/README.md +0 -262
  175. package/template/_prettierrc +0 -9
  176. package/template/components.json +0 -25
  177. package/template/src/app/(app)/admin/page.tsx +0 -53
  178. package/template/src/app/(app)/reports/page.tsx +0 -109
  179. package/template/src/app/(auth)/layout.tsx +0 -22
  180. package/template/src/app/not-found.tsx +0 -18
  181. package/template/src/app/page.tsx +0 -187
  182. package/template/src/components/admin/users-table.tsx +0 -162
  183. package/template/src/components/auth/form-field.tsx +0 -32
  184. package/template/src/components/layout/logout-button.tsx +0 -34
  185. package/template/src/components/layout/navbar.tsx +0 -67
  186. package/template/src/components/layout/page-header.tsx +0 -21
  187. package/template/src/components/layout/skeletons.tsx +0 -35
  188. package/template/src/components/role-badge.tsx +0 -17
  189. package/template/src/components/theme-toggle.tsx +0 -25
  190. package/template/src/lib/env.ts +0 -36
  191. package/template/src/lib/theme.ts +0 -8
  192. /package/{template → templates/next}/AGENTS.md +0 -0
  193. /package/{template → templates/next}/Dockerfile +0 -0
  194. /package/{template → templates/next}/_dockerignore +0 -0
  195. /package/{template → templates/next}/docker-compose.yml +0 -0
  196. /package/{template → templates/next}/public/robots.txt +0 -0
  197. /package/{template → templates/next}/src/app/(app)/loading.tsx +0 -0
  198. /package/{template → templates/next}/src/app/(auth)/login/page.tsx +0 -0
  199. /package/{template → templates/next}/src/app/api/admin/users/route.ts +0 -0
  200. /package/{template → templates/next}/src/app/api/auth/logout/route.ts +0 -0
  201. /package/{template → templates/next}/src/app/api/health/route.ts +0 -0
  202. /package/{template → templates/next}/src/app/favicon.ico +0 -0
  203. /package/{template → templates/next}/src/components/auth/can.tsx +0 -0
  204. /package/{template → templates/next}/src/components/motion/fade-in.tsx +0 -0
  205. /package/{template → templates/next}/src/components/providers/user-provider.tsx +0 -0
  206. /package/{template → templates/next}/src/config/site.ts +0 -0
  207. /package/{template → templates/next}/src/lib/db.ts +0 -0
  208. /package/{template → templates/next}/src/lib/http.ts +0 -0
  209. /package/{template → templates/next}/src/lib/redirect.ts +0 -0
  210. /package/{template → templates/next}/src/lib/validations/user.ts +0 -0
  211. /package/{template → templates/next}/tsconfig.json +0 -0
  212. /package/{template/src/app/globals.css → templates/styles/shadcn.css} +0 -0
  213. /package/{template/src/components/ui → templates/ui/shadcn/components}/badge.tsx +0 -0
  214. /package/{template/src/components/ui → templates/ui/shadcn/components}/button.tsx +0 -0
  215. /package/{template/src/components/ui → templates/ui/shadcn/components}/card.tsx +0 -0
  216. /package/{template/src/components/ui → templates/ui/shadcn/components}/input.tsx +0 -0
  217. /package/{template/src/components/ui → templates/ui/shadcn/components}/label.tsx +0 -0
  218. /package/{template/src/components/ui → templates/ui/shadcn/components}/native-select.tsx +0 -0
  219. /package/{template/src/components/ui → templates/ui/shadcn/components}/skeleton.tsx +0 -0
  220. /package/{template/src/lib → templates/ui/shadcn}/utils.ts +0 -0
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Seeds the database with demo accounts: npm run seed (add --reset to wipe first)
3
+ *
4
+ * Self-contained on purpose (plain mongoose + bcryptjs, no app imports), so it
5
+ * runs outside Next.js. Reads MONGODB_URI from .env.local / .env.
6
+ */
7
+ import fs from "node:fs";
8
+
9
+ import bcrypt from "bcryptjs";
10
+ import mongoose from "mongoose";
11
+
12
+ for (const file of [".env.local", ".env"]) {
13
+ if (fs.existsSync(file)) process.loadEnvFile(file);
14
+ }
15
+
16
+ const reset = process.argv.includes("--reset");
17
+ const uri = process.env.MONGODB_URI;
18
+
19
+ if (!uri) {
20
+ console.error("MONGODB_URI is not set (check .env.local).");
21
+ process.exit(1);
22
+ }
23
+ if (process.env.NODE_ENV === "production" && !process.argv.includes("--force")) {
24
+ console.error("Refusing to seed with NODE_ENV=production (pass --force to override).");
25
+ process.exit(1);
26
+ }
27
+
28
+ const PASSWORD = "Password123!";
29
+ const DEMO_ACCOUNTS = [
30
+ { name: "Ada Admin", email: "admin@example.com", role: "admin" },
31
+ { name: "Max Manager", email: "manager@example.com", role: "manager" },
32
+ { name: "Uma User", email: "user@example.com", role: "user" },
33
+ ];
34
+ const FIRST_NAMES = ["Liam", "Noah", "Emma", "Olivia", "Aarav", "Mia", "Lucas", "Zara", "Ethan", "Isla"];
35
+ const LAST_NAMES = ["Sharma", "Garcia", "Chen", "Smith", "Khan", "Rossi", "Kim", "Silva"];
36
+
37
+ function daysAgo(days: number): Date {
38
+ const date = new Date();
39
+ date.setUTCDate(date.getUTCDate() - days);
40
+ date.setUTCHours(9 + Math.floor(Math.random() * 10), Math.floor(Math.random() * 60));
41
+ return date;
42
+ }
43
+
44
+ async function main() {
45
+ await mongoose.connect(uri as string);
46
+ const db = mongoose.connection.db!;
47
+ const users = db.collection("users");
48
+
49
+ if (reset) {
50
+ await Promise.all(
51
+ ["users", "app_meta", "authtokens", "auditlogs"].map((name) =>
52
+ db.collection(name).deleteMany({}),
53
+ ),
54
+ );
55
+ console.log("Cleared users, tokens and audit log.");
56
+ }
57
+
58
+ const hash = await bcrypt.hash(PASSWORD, 12);
59
+ const now = new Date();
60
+ const docs = [
61
+ ...DEMO_ACCOUNTS.map((account, i) => ({ ...account, createdAt: daysAgo(14 - i) })),
62
+ // Extra users spread over the last two weeks, so the reports page has data.
63
+ ...Array.from({ length: 24 }, (_, i) => {
64
+ const first = FIRST_NAMES[i % FIRST_NAMES.length];
65
+ const last = LAST_NAMES[(i * 3) % LAST_NAMES.length];
66
+ return {
67
+ name: `${first} ${last}`,
68
+ email: `${first}.${last}.${i}@example.com`.toLowerCase(),
69
+ role: i % 8 === 0 ? "manager" : "user",
70
+ createdAt: daysAgo(i % 14),
71
+ };
72
+ }),
73
+ ];
74
+
75
+ let created = 0;
76
+ for (const doc of docs) {
77
+ const result = await users.updateOne(
78
+ { email: doc.email },
79
+ {
80
+ $setOnInsert: {
81
+ ...doc,
82
+ password: hash,
83
+ tokenVersion: 0,
84
+ emailVerifiedAt: now,
85
+ updatedAt: now,
86
+ },
87
+ },
88
+ { upsert: true },
89
+ );
90
+ if (result.upsertedCount) created++;
91
+ }
92
+
93
+ // An admin exists now, so new sign-ups must not become admin.
94
+ await db
95
+ .collection<{ _id: string; claimedAt: Date }>("app_meta")
96
+ .updateOne(
97
+ { _id: "first-admin-claimed" },
98
+ { $setOnInsert: { claimedAt: now } },
99
+ { upsert: true },
100
+ );
101
+
102
+ console.log(`Seeded ${created} new users (${docs.length - created} already existed).\n`);
103
+ console.table(DEMO_ACCOUNTS.map(({ email, role }) => ({ email, role, password: PASSWORD })));
104
+ await mongoose.disconnect();
105
+ }
106
+
107
+ main().catch(async (error) => {
108
+ console.error(error);
109
+ await mongoose.disconnect();
110
+ process.exit(1);
111
+ });
@@ -0,0 +1,99 @@
1
+ import { ArrowLeft } from "lucide-react";
2
+ import type { Metadata } from "next";
3
+ import Link from "next/link";
4
+
5
+ import { PageHeader } from "@/components/layout/page-header";
6
+ import { RoleBadge } from "@/components/role-badge";
7
+ import { Button } from "@/components/ui/button";
8
+ import { Card, CardContent } from "@/components/ui/card";
9
+ import {
10
+ Table,
11
+ TableBody,
12
+ TableCell,
13
+ TableHead,
14
+ TableHeader,
15
+ TableRow,
16
+ } from "@/components/ui/table";
17
+ import { isRole } from "@/config/rbac";
18
+ import { listAuditEntries, type AuditEntry } from "@/lib/audit";
19
+ import { requirePermission } from "@/lib/dal";
20
+
21
+ export const metadata: Metadata = { title: "Audit log" };
22
+
23
+ const timeFormat = new Intl.DateTimeFormat("en-US", {
24
+ dateStyle: "medium",
25
+ timeStyle: "short",
26
+ timeZone: "UTC",
27
+ });
28
+
29
+ function Change({ entry }: { entry: AuditEntry }) {
30
+ if (entry.action === "user.role_changed") {
31
+ const { from, to } = entry.details;
32
+ return (
33
+ <span className="cluster">
34
+ Role {isRole(from) ? <RoleBadge role={from} /> : String(from)} →{" "}
35
+ {isRole(to) ? <RoleBadge role={to} /> : String(to)}
36
+ </span>
37
+ );
38
+ }
39
+ return <span>Deleted account</span>;
40
+ }
41
+
42
+ export default async function AuditLogPage() {
43
+ await requirePermission("audit:read");
44
+ const entries = await listAuditEntries(100);
45
+
46
+ return (
47
+ <>
48
+ <PageHeader
49
+ title="Audit log"
50
+ description="The 100 most recent admin actions (times in UTC)."
51
+ actions={
52
+ <Button asChild variant="outline" size="sm">
53
+ <Link href="/admin">
54
+ <ArrowLeft /> Back to users
55
+ </Link>
56
+ </Button>
57
+ }
58
+ />
59
+ <Card>
60
+ <CardContent>
61
+ {entries.length === 0 ? (
62
+ <p className="empty-state">No admin actions recorded yet.</p>
63
+ ) : (
64
+ <Table>
65
+ <TableHeader>
66
+ <TableRow>
67
+ <TableHead>When</TableHead>
68
+ <TableHead>Who</TableHead>
69
+ <TableHead>Target</TableHead>
70
+ <TableHead>Change</TableHead>
71
+ </TableRow>
72
+ </TableHeader>
73
+ <TableBody>
74
+ {entries.map((entry) => (
75
+ <TableRow key={entry.id}>
76
+ <TableCell className="muted tabular nowrap">
77
+ {timeFormat.format(new Date(entry.createdAt))}
78
+ </TableCell>
79
+ <TableCell>
80
+ <div className="font-medium">{entry.actor.name}</div>
81
+ <div className="muted text-xs">{entry.actor.email}</div>
82
+ </TableCell>
83
+ <TableCell>
84
+ <div className="font-medium">{entry.target.name}</div>
85
+ <div className="muted text-xs">{entry.target.email}</div>
86
+ </TableCell>
87
+ <TableCell>
88
+ <Change entry={entry} />
89
+ </TableCell>
90
+ </TableRow>
91
+ ))}
92
+ </TableBody>
93
+ </Table>
94
+ )}
95
+ </CardContent>
96
+ </Card>
97
+ </>
98
+ );
99
+ }
@@ -0,0 +1,92 @@
1
+ import {
2
+ Eye,
3
+ // @feature audit-log
4
+ History,
5
+ // @end audit-log
6
+ } from "lucide-react";
7
+ import type { Metadata } from "next";
8
+ // @feature audit-log
9
+ import Link from "next/link";
10
+ // @end audit-log
11
+
12
+ // @feature data-table
13
+ import { UsersDataTable } from "@/components/admin/users-data-table";
14
+ // @end data-table
15
+ // @feature !data-table
16
+ import { UsersTable } from "@/components/admin/users-table";
17
+ // @end !data-table
18
+ import { Can } from "@/components/auth/can";
19
+ import { PageHeader } from "@/components/layout/page-header";
20
+ import { Badge } from "@/components/ui/badge";
21
+ // @feature audit-log
22
+ import { Button } from "@/components/ui/button";
23
+ // @end audit-log
24
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
25
+ import { requirePermission } from "@/lib/dal";
26
+ import { listUsers } from "@/lib/users";
27
+
28
+ export const metadata: Metadata = { title: "Admin" };
29
+
30
+ // @feature data-table
31
+ const MAX_USERS = 500; // searched, sorted and paginated in the browser
32
+ // @end data-table
33
+ // @feature !data-table
34
+ const MAX_USERS = 100;
35
+ // @end !data-table
36
+
37
+ export default async function AdminPage() {
38
+ // Managers (users:read) can view; mutations need users:update-role / users:delete,
39
+ // which are enforced again by the API routes.
40
+ const user = await requirePermission("users:read");
41
+ const { users, total } = await listUsers({ limit: MAX_USERS });
42
+
43
+ return (
44
+ <>
45
+ <PageHeader
46
+ title="User management"
47
+ description="Everyone with an account. Role changes apply on the user's next request."
48
+ actions={
49
+ <>
50
+ {/* @feature audit-log */}
51
+ <Can permission="audit:read">
52
+ <Button asChild variant="outline" size="sm">
53
+ <Link href="/admin/audit">
54
+ <History /> Audit log
55
+ </Link>
56
+ </Button>
57
+ </Can>
58
+ {/* @end audit-log */}
59
+ <Can
60
+ permission="users:update-role"
61
+ fallback={
62
+ <Badge variant="outline">
63
+ <Eye /> Read-only access
64
+ </Badge>
65
+ }
66
+ >
67
+ <Badge variant="outline">Full access</Badge>
68
+ </Can>
69
+ </>
70
+ }
71
+ />
72
+
73
+ <Card>
74
+ <CardHeader>
75
+ <CardTitle>Users</CardTitle>
76
+ <CardDescription>
77
+ {total} {total === 1 ? "account" : "accounts"}
78
+ {total > users.length && ` (showing the ${users.length} most recent)`}
79
+ </CardDescription>
80
+ </CardHeader>
81
+ <CardContent>
82
+ {/* @feature data-table */}
83
+ <UsersDataTable users={users} currentUserId={user.id} />
84
+ {/* @end data-table */}
85
+ {/* @feature !data-table */}
86
+ <UsersTable users={users} currentUserId={user.id} />
87
+ {/* @end !data-table */}
88
+ </CardContent>
89
+ </Card>
90
+ </>
91
+ );
92
+ }
@@ -37,24 +37,22 @@ export default async function DashboardPage() {
37
37
  description="Here's what your role lets you do in this app."
38
38
  />
39
39
 
40
- <div className="grid gap-4 lg:grid-cols-3">
40
+ <div className="dashboard-grid">
41
41
  <FadeIn>
42
- <Card className="h-full">
42
+ <Card className="full-height">
43
43
  <CardHeader>
44
44
  <CardDescription>Your role</CardDescription>
45
- <CardTitle className="flex items-center gap-2 text-2xl">
45
+ <CardTitle className="role-heading">
46
46
  {ROLE_LABELS[user.role]} <RoleBadge role={user.role} />
47
47
  </CardTitle>
48
48
  </CardHeader>
49
- <CardContent className="space-y-4 text-sm text-muted-foreground">
50
- <p>{ROLE_DESCRIPTIONS[user.role]}</p>
51
- <ol className="flex items-center gap-1 text-xs" aria-label="Role hierarchy">
49
+ <CardContent className="stack">
50
+ <p className="muted text-sm">{ROLE_DESCRIPTIONS[user.role]}</p>
51
+ <ol className="role-ladder" aria-label="Role hierarchy">
52
52
  {ROLES.map((role, i) => (
53
- <li key={role} className="flex items-center gap-1">
53
+ <li key={role} className={cn(role === user.role && "role-ladder-current")}>
54
54
  {i > 0 && <span aria-hidden>›</span>}
55
- <span className={cn(role === user.role && "font-semibold text-foreground")}>
56
- {ROLE_LABELS[role]}
57
- </span>
55
+ {ROLE_LABELS[role]}
58
56
  </li>
59
57
  ))}
60
58
  </ol>
@@ -62,8 +60,8 @@ export default async function DashboardPage() {
62
60
  </Card>
63
61
  </FadeIn>
64
62
 
65
- <FadeIn delay={0.05} className="lg:col-span-2">
66
- <Card className="h-full">
63
+ <FadeIn delay={0.05} className="dashboard-span-2">
64
+ <Card className="full-height">
67
65
  <CardHeader>
68
66
  <CardTitle>Permissions</CardTitle>
69
67
  <CardDescription>
@@ -71,27 +69,22 @@ export default async function DashboardPage() {
71
69
  </CardDescription>
72
70
  </CardHeader>
73
71
  <CardContent>
74
- <ul className="grid gap-2 sm:grid-cols-2">
72
+ <ul className="permission-list">
75
73
  {PERMISSIONS.map((permission) => {
76
74
  const granted = hasPermission(user.role, permission);
77
75
  return (
78
76
  <li
79
77
  key={permission}
80
- className={cn(
81
- "flex items-center gap-3 rounded-lg border px-3 py-2",
82
- !granted && "opacity-50",
83
- )}
78
+ className={cn("permission-item", !granted && "permission-item--denied")}
84
79
  >
85
80
  {granted ? (
86
- <Check className="size-4 shrink-0 text-emerald-600 dark:text-emerald-400" />
81
+ <Check size={16} className="icon-success" />
87
82
  ) : (
88
- <Lock className="size-4 shrink-0 text-muted-foreground" />
83
+ <Lock size={16} className="muted" />
89
84
  )}
90
- <div className="min-w-0">
85
+ <div className="permission-text">
91
86
  <p className="text-sm font-medium">{PERMISSION_LABELS[permission]}</p>
92
- <code className="font-mono text-xs text-muted-foreground">
93
- {permission}
94
- </code>
87
+ <code className="mono muted text-xs">{permission}</code>
95
88
  </div>
96
89
  <span className="sr-only">{granted ? "granted" : "not granted"}</span>
97
90
  </li>
@@ -104,17 +97,17 @@ export default async function DashboardPage() {
104
97
  </div>
105
98
 
106
99
  {sections.length > 0 && (
107
- <FadeIn delay={0.1} className="mt-4 grid gap-4 sm:grid-cols-2">
100
+ <FadeIn delay={0.1} className="cards-grid cards-grid--2 section-gap">
108
101
  {sections.map((item) => (
109
- <Link key={item.href} href={item.href} className="group">
110
- <Card className="transition-colors group-hover:bg-muted/50">
102
+ <Link key={item.href} href={item.href} className="link-card">
103
+ <Card>
111
104
  <CardHeader>
112
- <CardTitle className="flex items-center justify-between">
105
+ <CardTitle className="link-card-title">
113
106
  {item.label}
114
- <ArrowRight className="size-4 transition-transform group-hover:translate-x-0.5" />
107
+ <ArrowRight size={16} />
115
108
  </CardTitle>
116
109
  <CardDescription>
117
- Requires <code className="font-mono text-xs">{item.permission}</code>
110
+ Requires <code className="mono text-xs">{item.permission}</code>
118
111
  </CardDescription>
119
112
  </CardHeader>
120
113
  </Card>
@@ -11,15 +11,15 @@ export default function AppError({ error, retry }: { error: unknown; retry: () =
11
11
  }, [error]);
12
12
 
13
13
  return (
14
- <div className="mx-auto flex max-w-md flex-col items-center gap-4 py-16 text-center">
15
- <div className="flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive">
16
- <TriangleAlert className="size-6" />
14
+ <div className="status-page-body">
15
+ <div className="status-icon status-icon--danger">
16
+ <TriangleAlert size={24} />
17
17
  </div>
18
- <div className="space-y-1">
19
- <h2 className="text-lg font-semibold">Something went wrong</h2>
20
- <p className="text-sm text-muted-foreground">
18
+ <div className="stack-sm">
19
+ <h2 className="status-title">Something went wrong</h2>
20
+ <p className="muted text-sm">
21
21
  We couldn&apos;t load this page. If it keeps happening, check that MongoDB is running and
22
- that <code className="font-mono">MONGODB_URI</code> is set.
22
+ that <code className="code">MONGODB_URI</code> is set.
23
23
  </p>
24
24
  </div>
25
25
  <Button onClick={() => retry()}>Try again</Button>
@@ -1,7 +1,15 @@
1
1
  import type { ReactNode } from "react";
2
2
  import { Suspense } from "react";
3
3
 
4
+ // @feature email
5
+ import { VerifyEmailBanner } from "@/components/auth/verify-email-banner";
6
+ // @end email
7
+ // @feature !sidebar
4
8
  import { Navbar } from "@/components/layout/navbar";
9
+ // @end !sidebar
10
+ // @feature sidebar
11
+ import { SidebarLayout } from "@/components/layout/sidebar";
12
+ // @end sidebar
5
13
  import { ShellSkeleton } from "@/components/layout/skeletons";
6
14
  import { UserProvider } from "@/components/providers/user-provider";
7
15
  import { isSessionStale, requireUser } from "@/lib/dal";
@@ -12,7 +20,7 @@ import { isSessionStale, requireUser } from "@/lib/dal";
12
20
  * With Cache Components, reading the session (cookies + DB) is request-time
13
21
  * work, so it must happen inside a <Suspense> boundary and never at the
14
22
  * layout's top level. The static fallback is prerendered and shown instantly;
15
- * the real navbar and page stream in once the user is loaded.
23
+ * the real shell and page stream in once the user is loaded.
16
24
  */
17
25
  export default function AppLayout({ children }: { children: ReactNode }) {
18
26
  return (
@@ -28,8 +36,23 @@ async function AuthenticatedShell({ children }: { children: ReactNode }) {
28
36
 
29
37
  return (
30
38
  <UserProvider user={user} sessionStale={sessionStale}>
39
+ {/* @feature sidebar */}
40
+ <SidebarLayout>
41
+ {/* @feature email */}
42
+ <VerifyEmailBanner />
43
+ {/* @end email */}
44
+ {children}
45
+ </SidebarLayout>
46
+ {/* @end sidebar */}
47
+ {/* @feature !sidebar */}
31
48
  <Navbar />
32
- <main className="mx-auto w-full max-w-6xl flex-1 px-4 py-8">{children}</main>
49
+ <main className="app-main">
50
+ {/* @feature email */}
51
+ <VerifyEmailBanner />
52
+ {/* @end email */}
53
+ {children}
54
+ </main>
55
+ {/* @end !sidebar */}
33
56
  </UserProvider>
34
57
  );
35
58
  }
@@ -0,0 +1,128 @@
1
+ import { Crown, ShieldCheck, UserPlus, Users } from "lucide-react";
2
+ import type { Metadata } from "next";
3
+
4
+ import { PageHeader } from "@/components/layout/page-header";
5
+ import { FadeIn } from "@/components/motion/fade-in";
6
+ // @feature !charts
7
+ import { AnimatedBar } from "@/components/reports/animated-bar";
8
+ import { RoleBadge } from "@/components/role-badge";
9
+ // @end !charts
10
+ // @feature charts
11
+ import { RoleChart } from "@/components/reports/role-chart";
12
+ import { SignupsChart } from "@/components/reports/signups-chart";
13
+ // @end charts
14
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
15
+ // @feature !charts
16
+ import { ROLES } from "@/config/rbac";
17
+ // @end !charts
18
+ import { requirePermission } from "@/lib/dal";
19
+ import { getUserStats, SIGNUP_DAYS } from "@/lib/users";
20
+
21
+ export const metadata: Metadata = { title: "Reports" };
22
+
23
+ // @feature !charts
24
+ const dayFormat = new Intl.DateTimeFormat("en-US", { day: "numeric", timeZone: "UTC" });
25
+ // @end !charts
26
+
27
+ export default async function ReportsPage() {
28
+ await requirePermission("reports:view");
29
+ const stats = await getUserStats();
30
+
31
+ const cards = [
32
+ { label: "Total users", value: stats.total, icon: Users },
33
+ { label: `New in the last ${SIGNUP_DAYS} days`, value: stats.newInPeriod, icon: UserPlus },
34
+ { label: "Managers", value: stats.byRole.manager, icon: ShieldCheck },
35
+ { label: "Admins", value: stats.byRole.admin, icon: Crown },
36
+ ];
37
+ // @feature !charts
38
+ const maxDaily = Math.max(1, ...stats.signupsByDay.map((d) => d.count));
39
+ // @end !charts
40
+
41
+ return (
42
+ <>
43
+ <PageHeader title="Reports" description="Sample analytics, visible to managers and admins." />
44
+
45
+ <div className="cards-grid cards-grid--4">
46
+ {cards.map(({ label, value, icon: Icon }, i) => (
47
+ <FadeIn key={label} delay={i * 0.04}>
48
+ <Card>
49
+ <CardHeader>
50
+ <CardDescription className="stat-label">
51
+ {label} <Icon size={16} />
52
+ </CardDescription>
53
+ <CardTitle className="stat-value">{value}</CardTitle>
54
+ </CardHeader>
55
+ </Card>
56
+ </FadeIn>
57
+ ))}
58
+ </div>
59
+
60
+ <div className="cards-grid cards-grid--2 section-gap">
61
+ <Card>
62
+ <CardHeader>
63
+ <CardTitle>Users by role</CardTitle>
64
+ <CardDescription>Share of all accounts.</CardDescription>
65
+ </CardHeader>
66
+ <CardContent>
67
+ {/* @feature charts */}
68
+ <RoleChart byRole={stats.byRole} />
69
+ {/* @end charts */}
70
+ {/* @feature !charts */}
71
+ <div className="stack">
72
+ {ROLES.map((role, i) => {
73
+ const count = stats.byRole[role];
74
+ const pct = stats.total ? (count / stats.total) * 100 : 0;
75
+ return (
76
+ <div key={role} className="stack-sm">
77
+ <div className="row-between text-sm">
78
+ <RoleBadge role={role} />
79
+ <span className="muted tabular">
80
+ {count} · {Math.round(pct)}%
81
+ </span>
82
+ </div>
83
+ <div className="bar-track">
84
+ <AnimatedBar value={pct} delay={i * 0.1} />
85
+ </div>
86
+ </div>
87
+ );
88
+ })}
89
+ </div>
90
+ {/* @end !charts */}
91
+ </CardContent>
92
+ </Card>
93
+
94
+ <Card>
95
+ <CardHeader>
96
+ <CardTitle>Sign-ups</CardTitle>
97
+ <CardDescription>New accounts per day (UTC), last {SIGNUP_DAYS} days.</CardDescription>
98
+ </CardHeader>
99
+ <CardContent>
100
+ {/* @feature charts */}
101
+ <SignupsChart data={stats.signupsByDay} />
102
+ {/* @end charts */}
103
+ {/* @feature !charts */}
104
+ <div className="column-chart" role="list">
105
+ {stats.signupsByDay.map((day, i) => (
106
+ <div
107
+ key={day.date}
108
+ role="listitem"
109
+ aria-label={`${day.date}: ${day.count} sign-ups`}
110
+ className="column-chart-item"
111
+ >
112
+ <span className="muted tabular text-xs">{day.count}</span>
113
+ <div className="column-chart-bar">
114
+ <AnimatedBar vertical value={(day.count / maxDaily) * 100} delay={i * 0.03} />
115
+ </div>
116
+ <span className="muted text-xs">
117
+ {dayFormat.format(new Date(`${day.date}T00:00:00Z`))}
118
+ </span>
119
+ </div>
120
+ ))}
121
+ </div>
122
+ {/* @end !charts */}
123
+ </CardContent>
124
+ </Card>
125
+ </div>
126
+ </>
127
+ );
128
+ }
@@ -0,0 +1,66 @@
1
+ import type { Metadata } from "next";
2
+
3
+ import { PageHeader } from "@/components/layout/page-header";
4
+ import { RoleBadge } from "@/components/role-badge";
5
+ import { PasswordForm } from "@/components/settings/password-form";
6
+ import { ProfileForm } from "@/components/settings/profile-form";
7
+ import { SignOutOtherSessions } from "@/components/settings/sessions-card";
8
+ // @feature email
9
+ import { Badge } from "@/components/ui/badge";
10
+ // @end email
11
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
12
+ import { requireUser } from "@/lib/dal";
13
+
14
+ export const metadata: Metadata = { title: "Settings" };
15
+
16
+ export default async function SettingsPage() {
17
+ const user = await requireUser();
18
+
19
+ return (
20
+ <>
21
+ <PageHeader title="Settings" description="Manage your profile, password and sessions." />
22
+ <div className="settings-grid">
23
+ <Card>
24
+ <CardHeader>
25
+ <CardTitle>Profile</CardTitle>
26
+ <CardDescription className="cluster">
27
+ Signed in as {user.email} <RoleBadge role={user.role} />
28
+ {/* @feature email */}
29
+ {user.emailVerified ? (
30
+ <Badge variant="secondary">Verified</Badge>
31
+ ) : (
32
+ <Badge variant="destructive">Unverified</Badge>
33
+ )}
34
+ {/* @end email */}
35
+ </CardDescription>
36
+ </CardHeader>
37
+ <CardContent>
38
+ <ProfileForm />
39
+ </CardContent>
40
+ </Card>
41
+
42
+ <Card>
43
+ <CardHeader>
44
+ <CardTitle>Password</CardTitle>
45
+ <CardDescription>Changing it signs you out on every other device.</CardDescription>
46
+ </CardHeader>
47
+ <CardContent>
48
+ <PasswordForm />
49
+ </CardContent>
50
+ </Card>
51
+
52
+ <Card>
53
+ <CardHeader>
54
+ <CardTitle>Sessions</CardTitle>
55
+ <CardDescription>
56
+ Lost a device or signed in somewhere public? Sign out everywhere except here.
57
+ </CardDescription>
58
+ </CardHeader>
59
+ <CardContent>
60
+ <SignOutOtherSessions />
61
+ </CardContent>
62
+ </Card>
63
+ </div>
64
+ </>
65
+ );
66
+ }