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.
- package/README.md +96 -65
- package/index.js +195 -195
- package/lib/features.js +358 -0
- package/lib/scaffold.js +471 -0
- package/package.json +10 -6
- package/templates/common/_editorconfig +12 -0
- package/templates/common/_gitattributes +5 -0
- package/templates/common/_github/dependabot.yml +14 -0
- package/templates/common/_github/workflows/ci.yml +66 -0
- package/templates/common/_husky/commit-msg +1 -0
- package/templates/common/_husky/pre-commit +1 -0
- package/templates/common/_nvmrc +1 -0
- package/{template → templates/common}/_prettierignore +4 -0
- package/templates/common/commitlint.config.mjs +10 -0
- package/templates/next/README.md +328 -0
- package/{template → templates/next}/_env.example +10 -1
- package/{template → templates/next}/_gitignore +8 -0
- package/templates/next/e2e/rbac.spec.ts +69 -0
- package/templates/next/e2e/server.mjs +35 -0
- package/{template → templates/next}/eslint.config.mjs +12 -0
- package/{template → templates/next}/next.config.ts +2 -0
- package/{template → templates/next}/package.json +18 -3
- package/templates/next/playwright.config.ts +30 -0
- package/templates/next/scripts/seed.ts +111 -0
- package/templates/next/src/app/(app)/admin/audit/page.tsx +99 -0
- package/templates/next/src/app/(app)/admin/page.tsx +92 -0
- package/{template → templates/next}/src/app/(app)/dashboard/page.tsx +22 -29
- package/{template → templates/next}/src/app/(app)/error.tsx +7 -7
- package/{template → templates/next}/src/app/(app)/layout.tsx +25 -2
- package/templates/next/src/app/(app)/reports/page.tsx +128 -0
- package/templates/next/src/app/(app)/settings/page.tsx +66 -0
- package/templates/next/src/app/(auth)/forgot-password/page.tsx +17 -0
- package/templates/next/src/app/(auth)/layout.tsx +18 -0
- package/{template → templates/next}/src/app/(auth)/register/page.tsx +2 -4
- package/templates/next/src/app/(auth)/reset-password/page.tsx +18 -0
- package/templates/next/src/app/api/account/password/route.ts +45 -0
- package/templates/next/src/app/api/account/route.ts +25 -0
- package/templates/next/src/app/api/account/sessions/route.ts +12 -0
- package/templates/next/src/app/api/admin/audit/route.ts +13 -0
- package/{template → templates/next}/src/app/api/admin/users/[id]/route.ts +25 -4
- package/templates/next/src/app/api/auth/forgot-password/route.ts +47 -0
- package/{template → templates/next}/src/app/api/auth/login/route.ts +19 -2
- package/{template → templates/next}/src/app/api/auth/me/route.ts +4 -2
- package/{template → templates/next}/src/app/api/auth/register/route.ts +38 -4
- package/templates/next/src/app/api/auth/resend-verification/route.ts +25 -0
- package/templates/next/src/app/api/auth/reset-password/route.ts +43 -0
- package/templates/next/src/app/api/auth/verify-email/route.ts +29 -0
- package/{template → templates/next}/src/app/forbidden/page.tsx +11 -13
- package/{template → templates/next}/src/app/layout.tsx +9 -6
- package/templates/next/src/app/not-found.tsx +20 -0
- package/templates/next/src/app/opengraph-image.tsx +49 -0
- package/templates/next/src/app/page.tsx +165 -0
- package/templates/next/src/app/robots.ts +15 -0
- package/templates/next/src/app/sitemap.ts +13 -0
- package/templates/next/src/app/verify-email/page.tsx +23 -0
- package/templates/next/src/components/admin/user-actions.tsx +124 -0
- package/templates/next/src/components/admin/users-data-table.tsx +221 -0
- package/templates/next/src/components/admin/users-table.tsx +67 -0
- package/{template → templates/next}/src/components/auth/auth-card.tsx +8 -8
- package/templates/next/src/components/auth/forgot-password-form.tsx +76 -0
- package/templates/next/src/components/auth/form-field.tsx +40 -0
- package/{template → templates/next}/src/components/auth/login-form.tsx +14 -9
- package/templates/next/src/components/auth/password-input.tsx +43 -0
- package/{template → templates/next}/src/components/auth/register-form.tsx +22 -19
- package/templates/next/src/components/auth/reset-password-form.tsx +80 -0
- package/{template → templates/next}/src/components/auth/session-refresher.tsx +1 -1
- package/templates/next/src/components/auth/verify-email-banner.tsx +43 -0
- package/templates/next/src/components/auth/verify-email-status.tsx +44 -0
- package/templates/next/src/components/layout/nav-links.tsx +37 -0
- package/templates/next/src/components/layout/navbar.tsx +27 -0
- package/templates/next/src/components/layout/page-header.tsx +21 -0
- package/templates/next/src/components/layout/sidebar.tsx +83 -0
- package/templates/next/src/components/layout/skeletons.tsx +57 -0
- package/templates/next/src/components/layout/user-menu.tsx +118 -0
- package/{template → templates/next}/src/components/logo.tsx +3 -6
- package/{template → templates/next}/src/components/reports/animated-bar.tsx +1 -5
- package/templates/next/src/components/reports/role-chart.tsx +61 -0
- package/templates/next/src/components/reports/signups-chart.tsx +64 -0
- package/templates/next/src/components/role-badge.tsx +11 -0
- package/templates/next/src/components/settings/password-form.tsx +80 -0
- package/templates/next/src/components/settings/profile-form.tsx +63 -0
- package/templates/next/src/components/settings/sessions-card.tsx +70 -0
- package/templates/next/src/components/theme-toggle.tsx +61 -0
- package/templates/next/src/config/rbac.test.ts +89 -0
- package/{template → templates/next}/src/config/rbac.ts +35 -5
- package/{template → templates/next}/src/lib/api.ts +40 -4
- package/templates/next/src/lib/audit.ts +66 -0
- package/{template → templates/next}/src/lib/auth.ts +10 -2
- package/{template → templates/next}/src/lib/dal.ts +8 -5
- package/templates/next/src/lib/email-templates.ts +55 -0
- package/templates/next/src/lib/email.ts +53 -0
- package/templates/next/src/lib/env.ts +90 -0
- package/templates/next/src/lib/password-strength.test.ts +20 -0
- package/templates/next/src/lib/password-strength.ts +24 -0
- package/templates/next/src/lib/rate-limit.test.ts +47 -0
- package/templates/next/src/lib/rate-limit.ts +70 -0
- package/templates/next/src/lib/redirect.test.ts +23 -0
- package/{template → templates/next}/src/lib/session.ts +5 -1
- package/templates/next/src/lib/theme.ts +32 -0
- package/templates/next/src/lib/tokens.ts +63 -0
- package/{template → templates/next}/src/lib/users.ts +49 -12
- package/templates/next/src/lib/validations/account.ts +20 -0
- package/templates/next/src/lib/validations/auth.test.ts +39 -0
- package/{template → templates/next}/src/lib/validations/auth.ts +24 -2
- package/templates/next/src/models/audit-log.ts +33 -0
- package/templates/next/src/models/auth-token.ts +26 -0
- package/{template → templates/next}/src/models/user.ts +5 -0
- package/{template → templates/next}/src/proxy.ts +1 -1
- package/templates/next/src/styles/app.css +1092 -0
- package/{template → templates/next}/src/types/user.ts +3 -0
- package/templates/next/vitest.config.mts +13 -0
- package/templates/styles/css.css +580 -0
- package/templates/styles/tailwind.css +140 -0
- package/templates/ui/css/components/alert-dialog.tsx +172 -0
- package/templates/ui/css/components/avatar.tsx +17 -0
- package/templates/ui/css/components/badge.tsx +18 -0
- package/templates/ui/css/components/button.tsx +41 -0
- package/templates/ui/css/components/card.tsx +33 -0
- package/templates/ui/css/components/dropdown-menu.tsx +230 -0
- package/templates/ui/css/components/input.tsx +7 -0
- package/templates/ui/css/components/label.tsx +7 -0
- package/templates/ui/css/components/native-select.tsx +23 -0
- package/templates/ui/css/components/skeleton.tsx +7 -0
- package/templates/ui/css/components/slot.tsx +30 -0
- package/templates/ui/css/components/table.tsx +31 -0
- package/templates/ui/css/utils.ts +16 -0
- package/templates/ui/shadcn/components/alert-dialog.tsx +199 -0
- package/templates/ui/shadcn/components/avatar.tsx +111 -0
- package/templates/ui/shadcn/components/dropdown-menu.tsx +268 -0
- package/templates/ui/shadcn/components/table.tsx +115 -0
- package/templates/ui/tailwind/components/alert-dialog.tsx +177 -0
- package/templates/ui/tailwind/components/avatar.tsx +36 -0
- package/templates/ui/tailwind/components/badge.tsx +29 -0
- package/templates/ui/tailwind/components/button.tsx +65 -0
- package/templates/ui/tailwind/components/card.tsx +70 -0
- package/templates/ui/tailwind/components/dropdown-menu.tsx +236 -0
- package/templates/ui/tailwind/components/input.tsx +17 -0
- package/templates/ui/tailwind/components/label.tsx +16 -0
- package/templates/ui/tailwind/components/native-select.tsx +32 -0
- package/templates/ui/tailwind/components/skeleton.tsx +13 -0
- package/templates/ui/tailwind/components/slot.tsx +34 -0
- package/templates/ui/tailwind/components/table.tsx +56 -0
- package/templates/ui/tailwind/utils.ts +1 -0
- package/templates/vite/Dockerfile +29 -0
- package/templates/vite/README.md +142 -0
- package/templates/vite/_dockerignore +14 -0
- package/templates/vite/_env.example +8 -0
- package/templates/vite/_gitignore +37 -0
- package/templates/vite/e2e/app.spec.ts +41 -0
- package/templates/vite/index.html +32 -0
- package/templates/vite/nginx.conf +26 -0
- package/templates/vite/package.json +61 -0
- package/templates/vite/playwright.config.ts +27 -0
- package/templates/vite/public/favicon.svg +1 -0
- package/templates/vite/src/App.test.tsx +28 -0
- package/templates/vite/src/App.tsx +26 -0
- package/templates/vite/src/components/home.tsx +121 -0
- package/templates/vite/src/components/layout/root-layout.tsx +18 -0
- package/templates/vite/src/components/layout/site-footer.tsx +10 -0
- package/templates/vite/src/components/layout/site-header.tsx +49 -0
- package/templates/vite/src/components/theme-toggle.tsx +90 -0
- package/templates/vite/src/env.ts +36 -0
- package/templates/vite/src/lib/theme.ts +26 -0
- package/templates/vite/src/main.tsx +13 -0
- package/templates/vite/src/pages/about.tsx +52 -0
- package/templates/vite/src/pages/not-found.tsx +33 -0
- package/templates/vite/src/router.ts +24 -0
- package/templates/vite/src/styles/app.css +281 -0
- package/templates/vite/src/test/setup.ts +21 -0
- package/templates/vite/tsconfig.app.json +31 -0
- package/templates/vite/tsconfig.json +7 -0
- package/templates/vite/tsconfig.node.json +23 -0
- package/templates/vite/vite.config.ts +30 -0
- package/template/README.md +0 -262
- package/template/_prettierrc +0 -9
- package/template/components.json +0 -25
- package/template/src/app/(app)/admin/page.tsx +0 -53
- package/template/src/app/(app)/reports/page.tsx +0 -109
- package/template/src/app/(auth)/layout.tsx +0 -22
- package/template/src/app/not-found.tsx +0 -18
- package/template/src/app/page.tsx +0 -187
- package/template/src/components/admin/users-table.tsx +0 -162
- package/template/src/components/auth/form-field.tsx +0 -32
- package/template/src/components/layout/logout-button.tsx +0 -34
- package/template/src/components/layout/navbar.tsx +0 -67
- package/template/src/components/layout/page-header.tsx +0 -21
- package/template/src/components/layout/skeletons.tsx +0 -35
- package/template/src/components/role-badge.tsx +0 -17
- package/template/src/components/theme-toggle.tsx +0 -25
- package/template/src/lib/env.ts +0 -36
- package/template/src/lib/theme.ts +0 -8
- /package/{template → templates/next}/AGENTS.md +0 -0
- /package/{template → templates/next}/Dockerfile +0 -0
- /package/{template → templates/next}/_dockerignore +0 -0
- /package/{template → templates/next}/docker-compose.yml +0 -0
- /package/{template → templates/next}/public/robots.txt +0 -0
- /package/{template → templates/next}/src/app/(app)/loading.tsx +0 -0
- /package/{template → templates/next}/src/app/(auth)/login/page.tsx +0 -0
- /package/{template → templates/next}/src/app/api/admin/users/route.ts +0 -0
- /package/{template → templates/next}/src/app/api/auth/logout/route.ts +0 -0
- /package/{template → templates/next}/src/app/api/health/route.ts +0 -0
- /package/{template → templates/next}/src/app/favicon.ico +0 -0
- /package/{template → templates/next}/src/components/auth/can.tsx +0 -0
- /package/{template → templates/next}/src/components/motion/fade-in.tsx +0 -0
- /package/{template → templates/next}/src/components/providers/user-provider.tsx +0 -0
- /package/{template → templates/next}/src/config/site.ts +0 -0
- /package/{template → templates/next}/src/lib/db.ts +0 -0
- /package/{template → templates/next}/src/lib/http.ts +0 -0
- /package/{template → templates/next}/src/lib/redirect.ts +0 -0
- /package/{template → templates/next}/src/lib/validations/user.ts +0 -0
- /package/{template → templates/next}/tsconfig.json +0 -0
- /package/{template/src/app/globals.css → templates/styles/shadcn.css} +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/badge.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/button.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/card.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/input.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/label.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/native-select.tsx +0 -0
- /package/{template/src/components/ui → templates/ui/shadcn/components}/skeleton.tsx +0 -0
- /package/{template/src/lib → templates/ui/shadcn}/utils.ts +0 -0
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ArrowRight,
|
|
3
|
-
Container,
|
|
4
|
-
Database,
|
|
5
|
-
KeyRound,
|
|
6
|
-
Layers,
|
|
7
|
-
ShieldCheck,
|
|
8
|
-
Sparkles,
|
|
9
|
-
} from "lucide-react";
|
|
10
|
-
import Link from "next/link";
|
|
11
|
-
|
|
12
|
-
import { Logo } from "@/components/logo";
|
|
13
|
-
import { FadeIn } from "@/components/motion/fade-in";
|
|
14
|
-
import { ThemeToggle } from "@/components/theme-toggle";
|
|
15
|
-
import { Badge } from "@/components/ui/badge";
|
|
16
|
-
import { Button } from "@/components/ui/button";
|
|
17
|
-
import { Card, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
18
|
-
import { siteConfig } from "@/config/site";
|
|
19
|
-
|
|
20
|
-
const FEATURES = [
|
|
21
|
-
{
|
|
22
|
-
icon: ShieldCheck,
|
|
23
|
-
title: "Role-based access control",
|
|
24
|
-
description:
|
|
25
|
-
"User, manager and admin roles with permissions defined in one file and enforced in three layers.",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
icon: KeyRound,
|
|
29
|
-
title: "JWT authentication",
|
|
30
|
-
description:
|
|
31
|
-
"bcrypt-hashed passwords and HS256 tokens in httpOnly cookies. No auth vendor required.",
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
icon: Database,
|
|
35
|
-
title: "MongoDB + Mongoose",
|
|
36
|
-
description: "A cached connection that survives hot reloads, plus typed models.",
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
icon: Layers,
|
|
40
|
-
title: "shadcn/ui + Tailwind v4",
|
|
41
|
-
description:
|
|
42
|
-
"Accessible components, CSS-variable theming with dark mode, and motion animations.",
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
icon: Sparkles,
|
|
46
|
-
title: "Type-safe end to end",
|
|
47
|
-
description: "zod schemas shared by forms and API routes, plus a strict TypeScript setup.",
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
icon: Container,
|
|
51
|
-
title: "Ready to ship",
|
|
52
|
-
description:
|
|
53
|
-
"A multi-stage Docker build, docker-compose with MongoDB, security headers and a health check.",
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const LAYERS = [
|
|
58
|
-
{
|
|
59
|
-
step: "1",
|
|
60
|
-
title: "Proxy",
|
|
61
|
-
file: "src/proxy.ts",
|
|
62
|
-
text: "Fast redirects based on the signed JWT.",
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
step: "2",
|
|
66
|
-
title: "Data Access Layer",
|
|
67
|
-
file: "src/lib/dal.ts",
|
|
68
|
-
text: "Re-reads the user from MongoDB on every request.",
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
step: "3",
|
|
72
|
-
title: "API guard",
|
|
73
|
-
file: "src/lib/api.ts",
|
|
74
|
-
text: "withAuth() returns 401/403 JSON for route handlers.",
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
export default function HomePage() {
|
|
79
|
-
return (
|
|
80
|
-
<div className="flex flex-1 flex-col">
|
|
81
|
-
<header className="mx-auto flex h-14 w-full max-w-6xl items-center gap-2 px-4">
|
|
82
|
-
<Logo />
|
|
83
|
-
<div className="ml-auto flex items-center gap-2">
|
|
84
|
-
<ThemeToggle />
|
|
85
|
-
<Button asChild variant="ghost" size="sm">
|
|
86
|
-
<Link href="/login">Sign in</Link>
|
|
87
|
-
</Button>
|
|
88
|
-
<Button asChild size="sm">
|
|
89
|
-
<Link href="/register">Get started</Link>
|
|
90
|
-
</Button>
|
|
91
|
-
</div>
|
|
92
|
-
</header>
|
|
93
|
-
|
|
94
|
-
<main className="flex-1">
|
|
95
|
-
<section className="relative overflow-hidden">
|
|
96
|
-
<div
|
|
97
|
-
aria-hidden
|
|
98
|
-
className="pointer-events-none absolute inset-0 -z-10 bg-[radial-gradient(ellipse_at_top,var(--color-muted),transparent_65%)]"
|
|
99
|
-
/>
|
|
100
|
-
<div className="mx-auto flex max-w-3xl flex-col items-center gap-6 px-4 pt-20 pb-16 text-center sm:pt-28">
|
|
101
|
-
<FadeIn>
|
|
102
|
-
<Badge variant="outline" className="gap-1.5">
|
|
103
|
-
<Sparkles /> Next.js 16 · React 19 · Tailwind v4
|
|
104
|
-
</Badge>
|
|
105
|
-
</FadeIn>
|
|
106
|
-
<FadeIn delay={0.05}>
|
|
107
|
-
<h1 className="text-4xl font-semibold tracking-tight text-balance sm:text-6xl">
|
|
108
|
-
Ship your full-stack app with auth and roles built in
|
|
109
|
-
</h1>
|
|
110
|
-
</FadeIn>
|
|
111
|
-
<FadeIn delay={0.1}>
|
|
112
|
-
<p className="max-w-xl text-lg text-pretty text-muted-foreground">
|
|
113
|
-
{siteConfig.description}
|
|
114
|
-
</p>
|
|
115
|
-
</FadeIn>
|
|
116
|
-
<FadeIn delay={0.15} className="flex flex-wrap justify-center gap-3">
|
|
117
|
-
<Button asChild size="lg">
|
|
118
|
-
<Link href="/register">
|
|
119
|
-
Create an account <ArrowRight />
|
|
120
|
-
</Link>
|
|
121
|
-
</Button>
|
|
122
|
-
<Button asChild size="lg" variant="outline">
|
|
123
|
-
<Link href="/dashboard">Open dashboard</Link>
|
|
124
|
-
</Button>
|
|
125
|
-
</FadeIn>
|
|
126
|
-
<p className="text-xs text-muted-foreground">
|
|
127
|
-
The first account you register becomes the admin.
|
|
128
|
-
</p>
|
|
129
|
-
</div>
|
|
130
|
-
</section>
|
|
131
|
-
|
|
132
|
-
<section className="mx-auto max-w-6xl px-4 pb-20">
|
|
133
|
-
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
|
134
|
-
{FEATURES.map(({ icon: Icon, title, description }, i) => (
|
|
135
|
-
<FadeIn key={title} delay={0.05 * i}>
|
|
136
|
-
<Card className="h-full">
|
|
137
|
-
<CardHeader>
|
|
138
|
-
<div className="mb-2 flex size-9 items-center justify-center rounded-lg bg-secondary">
|
|
139
|
-
<Icon className="size-4" />
|
|
140
|
-
</div>
|
|
141
|
-
<CardTitle>{title}</CardTitle>
|
|
142
|
-
<CardDescription>{description}</CardDescription>
|
|
143
|
-
</CardHeader>
|
|
144
|
-
</Card>
|
|
145
|
-
</FadeIn>
|
|
146
|
-
))}
|
|
147
|
-
</div>
|
|
148
|
-
</section>
|
|
149
|
-
|
|
150
|
-
<section className="border-t bg-muted/30">
|
|
151
|
-
<div className="mx-auto max-w-6xl px-4 py-20">
|
|
152
|
-
<div className="mb-10 max-w-2xl space-y-2">
|
|
153
|
-
<h2 className="text-2xl font-semibold tracking-tight">
|
|
154
|
-
Defense in depth, by default
|
|
155
|
-
</h2>
|
|
156
|
-
<p className="text-muted-foreground">
|
|
157
|
-
Every request is checked at three layers, all driven by{" "}
|
|
158
|
-
<code className="font-mono text-sm">src/config/rbac.ts</code>.
|
|
159
|
-
</p>
|
|
160
|
-
</div>
|
|
161
|
-
<ol className="grid gap-4 md:grid-cols-3">
|
|
162
|
-
{LAYERS.map((layer) => (
|
|
163
|
-
<li key={layer.step} className="rounded-xl border bg-background p-5">
|
|
164
|
-
<span className="font-mono text-xs text-muted-foreground">
|
|
165
|
-
Layer {layer.step}
|
|
166
|
-
</span>
|
|
167
|
-
<h3 className="mt-1 font-medium">{layer.title}</h3>
|
|
168
|
-
<p className="mt-1 text-sm text-muted-foreground">{layer.text}</p>
|
|
169
|
-
<code className="mt-3 inline-block rounded bg-muted px-1.5 py-0.5 font-mono text-xs">
|
|
170
|
-
{layer.file}
|
|
171
|
-
</code>
|
|
172
|
-
</li>
|
|
173
|
-
))}
|
|
174
|
-
</ol>
|
|
175
|
-
</div>
|
|
176
|
-
</section>
|
|
177
|
-
</main>
|
|
178
|
-
|
|
179
|
-
<footer className="border-t">
|
|
180
|
-
<div className="mx-auto flex max-w-6xl items-center justify-between px-4 py-6 text-sm text-muted-foreground">
|
|
181
|
-
<span>{siteConfig.name}</span>
|
|
182
|
-
<span>Built with create-mohit-next</span>
|
|
183
|
-
</div>
|
|
184
|
-
</footer>
|
|
185
|
-
</div>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { LoaderCircle, Trash2 } from "lucide-react";
|
|
4
|
-
import { useRouter } from "next/navigation";
|
|
5
|
-
import { useEffect, useState, useTransition } from "react";
|
|
6
|
-
import { toast } from "sonner";
|
|
7
|
-
|
|
8
|
-
import { Can } from "@/components/auth/can";
|
|
9
|
-
import { RoleBadge } from "@/components/role-badge";
|
|
10
|
-
import { Badge } from "@/components/ui/badge";
|
|
11
|
-
import { Button } from "@/components/ui/button";
|
|
12
|
-
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";
|
|
13
|
-
import { isRole, ROLE_LABELS, ROLES, type Role } from "@/config/rbac";
|
|
14
|
-
import { apiFetch, getErrorMessage } from "@/lib/http";
|
|
15
|
-
import type { PublicUser } from "@/types/user";
|
|
16
|
-
|
|
17
|
-
// Fixed locale + time zone so server and client render the same string.
|
|
18
|
-
const dateFormat = new Intl.DateTimeFormat("en-US", { dateStyle: "medium", timeZone: "UTC" });
|
|
19
|
-
|
|
20
|
-
export function UsersTable({
|
|
21
|
-
users,
|
|
22
|
-
currentUserId,
|
|
23
|
-
}: {
|
|
24
|
-
users: PublicUser[];
|
|
25
|
-
currentUserId: string;
|
|
26
|
-
}) {
|
|
27
|
-
if (users.length === 0) {
|
|
28
|
-
return <p className="py-10 text-center text-sm text-muted-foreground">No users yet.</p>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<div className="overflow-x-auto">
|
|
33
|
-
<table className="w-full min-w-[640px] text-sm">
|
|
34
|
-
<thead>
|
|
35
|
-
<tr className="border-b text-left text-muted-foreground">
|
|
36
|
-
<th className="px-4 py-3 font-medium">User</th>
|
|
37
|
-
<th className="px-4 py-3 font-medium">Role</th>
|
|
38
|
-
<th className="px-4 py-3 font-medium">Joined</th>
|
|
39
|
-
<Can permission="users:delete">
|
|
40
|
-
<th className="px-4 py-3 text-right font-medium">
|
|
41
|
-
<span className="sr-only">Actions</span>
|
|
42
|
-
</th>
|
|
43
|
-
</Can>
|
|
44
|
-
</tr>
|
|
45
|
-
</thead>
|
|
46
|
-
<tbody>
|
|
47
|
-
{users.map((user) => (
|
|
48
|
-
// Keyed by role too, so a row resets its local state when fresh data arrives.
|
|
49
|
-
<UserRow
|
|
50
|
-
key={`${user.id}:${user.role}`}
|
|
51
|
-
user={user}
|
|
52
|
-
isSelf={user.id === currentUserId}
|
|
53
|
-
/>
|
|
54
|
-
))}
|
|
55
|
-
</tbody>
|
|
56
|
-
</table>
|
|
57
|
-
</div>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function UserRow({ user, isSelf }: { user: PublicUser; isSelf: boolean }) {
|
|
62
|
-
const router = useRouter();
|
|
63
|
-
const [pending, startTransition] = useTransition();
|
|
64
|
-
const [role, setRole] = useState<Role>(user.role);
|
|
65
|
-
const [confirming, setConfirming] = useState(false);
|
|
66
|
-
|
|
67
|
-
// Two-step delete: the confirmation resets after a few seconds.
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (!confirming) return;
|
|
70
|
-
const timeout = setTimeout(() => setConfirming(false), 4000);
|
|
71
|
-
return () => clearTimeout(timeout);
|
|
72
|
-
}, [confirming]);
|
|
73
|
-
|
|
74
|
-
function changeRole(next: string) {
|
|
75
|
-
if (!isRole(next) || next === role) return;
|
|
76
|
-
const previous = role;
|
|
77
|
-
setRole(next); // optimistic
|
|
78
|
-
startTransition(async () => {
|
|
79
|
-
try {
|
|
80
|
-
await apiFetch(`/api/admin/users/${user.id}`, { method: "PATCH", json: { role: next } });
|
|
81
|
-
toast.success(`${user.name} is now ${ROLE_LABELS[next].toLowerCase()}`);
|
|
82
|
-
router.refresh();
|
|
83
|
-
} catch (error) {
|
|
84
|
-
setRole(previous);
|
|
85
|
-
toast.error(getErrorMessage(error, "Could not update role"));
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function remove() {
|
|
91
|
-
if (!confirming) {
|
|
92
|
-
setConfirming(true);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
startTransition(async () => {
|
|
96
|
-
try {
|
|
97
|
-
await apiFetch(`/api/admin/users/${user.id}`, { method: "DELETE" });
|
|
98
|
-
toast.success(`Deleted ${user.name}`);
|
|
99
|
-
router.refresh();
|
|
100
|
-
} catch (error) {
|
|
101
|
-
toast.error(getErrorMessage(error, "Could not delete user"));
|
|
102
|
-
} finally {
|
|
103
|
-
setConfirming(false);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<tr className="border-b last:border-0">
|
|
110
|
-
<td className="px-4 py-3">
|
|
111
|
-
<div className="flex items-center gap-2 font-medium">
|
|
112
|
-
{user.name}
|
|
113
|
-
{isSelf && <Badge variant="secondary">You</Badge>}
|
|
114
|
-
</div>
|
|
115
|
-
<div className="text-muted-foreground">{user.email}</div>
|
|
116
|
-
</td>
|
|
117
|
-
<td className="px-4 py-3">
|
|
118
|
-
<Can permission="users:update-role" fallback={<RoleBadge role={user.role} />}>
|
|
119
|
-
{isSelf ? (
|
|
120
|
-
<RoleBadge role={user.role} />
|
|
121
|
-
) : (
|
|
122
|
-
<div className="flex items-center gap-2">
|
|
123
|
-
<NativeSelect
|
|
124
|
-
size="sm"
|
|
125
|
-
value={role}
|
|
126
|
-
disabled={pending}
|
|
127
|
-
onChange={(e) => changeRole(e.target.value)}
|
|
128
|
-
aria-label={`Role for ${user.name}`}
|
|
129
|
-
>
|
|
130
|
-
{ROLES.map((r) => (
|
|
131
|
-
<NativeSelectOption key={r} value={r}>
|
|
132
|
-
{ROLE_LABELS[r]}
|
|
133
|
-
</NativeSelectOption>
|
|
134
|
-
))}
|
|
135
|
-
</NativeSelect>
|
|
136
|
-
{pending && <LoaderCircle className="size-4 animate-spin text-muted-foreground" />}
|
|
137
|
-
</div>
|
|
138
|
-
)}
|
|
139
|
-
</Can>
|
|
140
|
-
</td>
|
|
141
|
-
<td className="px-4 py-3 text-muted-foreground tabular-nums">
|
|
142
|
-
{dateFormat.format(new Date(user.createdAt))}
|
|
143
|
-
</td>
|
|
144
|
-
<Can permission="users:delete">
|
|
145
|
-
<td className="px-4 py-3 text-right">
|
|
146
|
-
{!isSelf && (
|
|
147
|
-
<Button
|
|
148
|
-
variant="destructive"
|
|
149
|
-
size="sm"
|
|
150
|
-
onClick={remove}
|
|
151
|
-
disabled={pending}
|
|
152
|
-
aria-label={confirming ? `Confirm deleting ${user.name}` : `Delete ${user.name}`}
|
|
153
|
-
>
|
|
154
|
-
<Trash2 />
|
|
155
|
-
{confirming ? "Confirm" : "Delete"}
|
|
156
|
-
</Button>
|
|
157
|
-
)}
|
|
158
|
-
</td>
|
|
159
|
-
</Can>
|
|
160
|
-
</tr>
|
|
161
|
-
);
|
|
162
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { ComponentProps } from "react";
|
|
2
|
-
import type { FieldError } from "react-hook-form";
|
|
3
|
-
|
|
4
|
-
import { Input } from "@/components/ui/input";
|
|
5
|
-
import { Label } from "@/components/ui/label";
|
|
6
|
-
|
|
7
|
-
type FormFieldProps = ComponentProps<typeof Input> & {
|
|
8
|
-
id: string;
|
|
9
|
-
label: string;
|
|
10
|
-
error?: FieldError;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
/** Label + input + error message, wired up for accessibility. */
|
|
14
|
-
export function FormField({ id, label, error, ...inputProps }: FormFieldProps) {
|
|
15
|
-
const errorId = `${id}-error`;
|
|
16
|
-
return (
|
|
17
|
-
<div className="grid gap-2">
|
|
18
|
-
<Label htmlFor={id}>{label}</Label>
|
|
19
|
-
<Input
|
|
20
|
-
id={id}
|
|
21
|
-
aria-invalid={error ? true : undefined}
|
|
22
|
-
aria-describedby={error ? errorId : undefined}
|
|
23
|
-
{...inputProps}
|
|
24
|
-
/>
|
|
25
|
-
{error?.message && (
|
|
26
|
-
<p id={errorId} className="text-sm text-destructive">
|
|
27
|
-
{error.message}
|
|
28
|
-
</p>
|
|
29
|
-
)}
|
|
30
|
-
</div>
|
|
31
|
-
);
|
|
32
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { LoaderCircle, LogOut } from "lucide-react";
|
|
4
|
-
import { useRouter } from "next/navigation";
|
|
5
|
-
import { useState } from "react";
|
|
6
|
-
import { toast } from "sonner";
|
|
7
|
-
|
|
8
|
-
import { Button } from "@/components/ui/button";
|
|
9
|
-
import { apiFetch, getErrorMessage } from "@/lib/http";
|
|
10
|
-
|
|
11
|
-
export function LogoutButton() {
|
|
12
|
-
const router = useRouter();
|
|
13
|
-
const [pending, setPending] = useState(false);
|
|
14
|
-
|
|
15
|
-
async function logout() {
|
|
16
|
-
setPending(true);
|
|
17
|
-
try {
|
|
18
|
-
await apiFetch("/api/auth/logout", { method: "POST" });
|
|
19
|
-
toast.success("Signed out");
|
|
20
|
-
router.replace("/login");
|
|
21
|
-
router.refresh();
|
|
22
|
-
} catch (error) {
|
|
23
|
-
toast.error(getErrorMessage(error, "Could not sign out"));
|
|
24
|
-
setPending(false);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<Button variant="outline" size="sm" onClick={logout} disabled={pending}>
|
|
30
|
-
{pending ? <LoaderCircle className="animate-spin" /> : <LogOut />}
|
|
31
|
-
<span className="hidden sm:inline">Sign out</span>
|
|
32
|
-
</Button>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { ChartColumn, LayoutDashboard, Users, type LucideIcon } from "lucide-react";
|
|
4
|
-
import Link from "next/link";
|
|
5
|
-
import { usePathname } from "next/navigation";
|
|
6
|
-
|
|
7
|
-
import { LogoutButton } from "@/components/layout/logout-button";
|
|
8
|
-
import { Logo } from "@/components/logo";
|
|
9
|
-
import { useUser } from "@/components/providers/user-provider";
|
|
10
|
-
import { RoleBadge } from "@/components/role-badge";
|
|
11
|
-
import { ThemeToggle } from "@/components/theme-toggle";
|
|
12
|
-
import { getNavItems } from "@/config/rbac";
|
|
13
|
-
import { cn } from "@/lib/utils";
|
|
14
|
-
|
|
15
|
-
const ICONS: Record<string, LucideIcon> = {
|
|
16
|
-
"/dashboard": LayoutDashboard,
|
|
17
|
-
"/reports": ChartColumn,
|
|
18
|
-
"/admin": Users,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/** App navbar: only shows links the current role is permitted to open. */
|
|
22
|
-
export function Navbar() {
|
|
23
|
-
const user = useUser();
|
|
24
|
-
const pathname = usePathname();
|
|
25
|
-
const items = getNavItems(user.role);
|
|
26
|
-
|
|
27
|
-
const links = items.map((item) => {
|
|
28
|
-
const Icon = ICONS[item.href];
|
|
29
|
-
const active = pathname === item.href || pathname.startsWith(`${item.href}/`);
|
|
30
|
-
return (
|
|
31
|
-
<Link
|
|
32
|
-
key={item.href}
|
|
33
|
-
href={item.href}
|
|
34
|
-
aria-current={active ? "page" : undefined}
|
|
35
|
-
className={cn(
|
|
36
|
-
"flex shrink-0 items-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors",
|
|
37
|
-
active
|
|
38
|
-
? "bg-secondary text-foreground"
|
|
39
|
-
: "text-muted-foreground hover:bg-secondary/60 hover:text-foreground",
|
|
40
|
-
)}
|
|
41
|
-
>
|
|
42
|
-
{Icon && <Icon className="size-4" />}
|
|
43
|
-
{item.label}
|
|
44
|
-
</Link>
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return (
|
|
49
|
-
<header className="sticky top-0 z-40 border-b bg-background/80 backdrop-blur supports-backdrop-filter:bg-background/60">
|
|
50
|
-
<div className="mx-auto flex h-14 w-full max-w-6xl items-center gap-4 px-4">
|
|
51
|
-
<Logo href="/dashboard" />
|
|
52
|
-
<nav className="hidden items-center gap-1 md:flex">{links}</nav>
|
|
53
|
-
<div className="ml-auto flex items-center gap-2">
|
|
54
|
-
<div className="hidden min-w-0 items-center gap-2 sm:flex">
|
|
55
|
-
<span className="max-w-40 truncate text-sm font-medium">{user.name}</span>
|
|
56
|
-
<RoleBadge role={user.role} />
|
|
57
|
-
</div>
|
|
58
|
-
<ThemeToggle />
|
|
59
|
-
<LogoutButton />
|
|
60
|
-
</div>
|
|
61
|
-
</div>
|
|
62
|
-
<nav className="no-scrollbar flex items-center gap-1 overflow-x-auto border-t px-4 py-2 md:hidden">
|
|
63
|
-
{links}
|
|
64
|
-
</nav>
|
|
65
|
-
</header>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
export function PageHeader({
|
|
4
|
-
title,
|
|
5
|
-
description,
|
|
6
|
-
actions,
|
|
7
|
-
}: {
|
|
8
|
-
title: string;
|
|
9
|
-
description?: ReactNode;
|
|
10
|
-
actions?: ReactNode;
|
|
11
|
-
}) {
|
|
12
|
-
return (
|
|
13
|
-
<div className="mb-8 flex flex-col gap-4 sm:flex-row sm:items-end sm:justify-between">
|
|
14
|
-
<div className="space-y-1">
|
|
15
|
-
<h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
|
|
16
|
-
{description && <p className="text-sm text-muted-foreground">{description}</p>}
|
|
17
|
-
</div>
|
|
18
|
-
{actions && <div className="flex items-center gap-2">{actions}</div>}
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Skeleton } from "@/components/ui/skeleton";
|
|
2
|
-
|
|
3
|
-
export function PageSkeleton() {
|
|
4
|
-
return (
|
|
5
|
-
<div className="space-y-6" aria-busy="true" aria-label="Loading">
|
|
6
|
-
<div className="space-y-2">
|
|
7
|
-
<Skeleton className="h-8 w-56" />
|
|
8
|
-
<Skeleton className="h-4 w-80 max-w-full" />
|
|
9
|
-
</div>
|
|
10
|
-
<div className="grid gap-4 md:grid-cols-3">
|
|
11
|
-
<Skeleton className="h-32" />
|
|
12
|
-
<Skeleton className="h-32" />
|
|
13
|
-
<Skeleton className="h-32" />
|
|
14
|
-
</div>
|
|
15
|
-
<Skeleton className="h-64" />
|
|
16
|
-
</div>
|
|
17
|
-
);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function ShellSkeleton() {
|
|
21
|
-
return (
|
|
22
|
-
<>
|
|
23
|
-
<div className="border-b">
|
|
24
|
-
<div className="mx-auto flex h-14 w-full max-w-6xl items-center gap-4 px-4">
|
|
25
|
-
<Skeleton className="h-7 w-32" />
|
|
26
|
-
<Skeleton className="hidden h-7 w-64 md:block" />
|
|
27
|
-
<Skeleton className="ml-auto h-7 w-40" />
|
|
28
|
-
</div>
|
|
29
|
-
</div>
|
|
30
|
-
<div className="mx-auto w-full max-w-6xl flex-1 px-4 py-8">
|
|
31
|
-
<PageSkeleton />
|
|
32
|
-
</div>
|
|
33
|
-
</>
|
|
34
|
-
);
|
|
35
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ROLE_LABELS, type Role } from "@/config/rbac";
|
|
2
|
-
import { Badge } from "@/components/ui/badge";
|
|
3
|
-
import { cn } from "@/lib/utils";
|
|
4
|
-
|
|
5
|
-
const ROLE_STYLES: Record<Role, string> = {
|
|
6
|
-
user: "border-border bg-secondary text-secondary-foreground",
|
|
7
|
-
manager: "border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-300",
|
|
8
|
-
admin: "border-violet-500/30 bg-violet-500/10 text-violet-700 dark:text-violet-300",
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export function RoleBadge({ role, className }: { role: Role; className?: string }) {
|
|
12
|
-
return (
|
|
13
|
-
<Badge variant="outline" className={cn(ROLE_STYLES[role], className)}>
|
|
14
|
-
{ROLE_LABELS[role]}
|
|
15
|
-
</Badge>
|
|
16
|
-
);
|
|
17
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import { Moon, Sun } from "lucide-react";
|
|
4
|
-
|
|
5
|
-
import { Button } from "@/components/ui/button";
|
|
6
|
-
import { THEME_STORAGE_KEY } from "@/lib/theme";
|
|
7
|
-
|
|
8
|
-
/** Toggles light/dark. Stateless: the icons are swapped purely with CSS, so there's no hydration mismatch. */
|
|
9
|
-
export function ThemeToggle() {
|
|
10
|
-
function toggle() {
|
|
11
|
-
const isDark = document.documentElement.classList.toggle("dark");
|
|
12
|
-
try {
|
|
13
|
-
localStorage.setItem(THEME_STORAGE_KEY, isDark ? "dark" : "light");
|
|
14
|
-
} catch {
|
|
15
|
-
// Storage unavailable (private mode); the choice just won't persist.
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<Button variant="ghost" size="icon" onClick={toggle} aria-label="Toggle theme">
|
|
21
|
-
<Sun className="hidden dark:block" />
|
|
22
|
-
<Moon className="dark:hidden" />
|
|
23
|
-
</Button>
|
|
24
|
-
);
|
|
25
|
-
}
|
package/template/src/lib/env.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Server environment variables, validated with zod.
|
|
5
|
-
*
|
|
6
|
-
* Validation is lazy (on first use, not at import time) so `next build` and
|
|
7
|
-
* the Docker build work without any secrets present. Never import this from
|
|
8
|
-
* a Client Component: these values must stay on the server.
|
|
9
|
-
*/
|
|
10
|
-
const envSchema = z.object({
|
|
11
|
-
NODE_ENV: z.enum(["development", "production", "test"]).default("development"),
|
|
12
|
-
MONGODB_URI: z
|
|
13
|
-
.string({ error: "MONGODB_URI is required" })
|
|
14
|
-
.regex(/^mongodb(\+srv)?:\/\//, "MONGODB_URI must start with mongodb:// or mongodb+srv://"),
|
|
15
|
-
JWT_SECRET: z
|
|
16
|
-
.string({ error: "JWT_SECRET is required" })
|
|
17
|
-
.min(32, "JWT_SECRET must be at least 32 characters long"),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export type Env = z.infer<typeof envSchema>;
|
|
21
|
-
|
|
22
|
-
let cached: Env | undefined;
|
|
23
|
-
|
|
24
|
-
export function env(): Env {
|
|
25
|
-
if (cached) return cached;
|
|
26
|
-
const parsed = envSchema.safeParse(process.env);
|
|
27
|
-
if (!parsed.success) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Invalid environment variables (check .env.local):\n${z.prettifyError(parsed.error)}`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
cached = parsed.data;
|
|
33
|
-
return cached;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const isProduction = () => process.env.NODE_ENV === "production";
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const THEME_STORAGE_KEY = "theme";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Runs in <head> before first paint so the page never flashes the wrong theme.
|
|
5
|
-
* Uses the saved choice, falling back to the OS preference.
|
|
6
|
-
* See node_modules/next/dist/docs/01-app/02-guides/preventing-flash-before-hydration.md
|
|
7
|
-
*/
|
|
8
|
-
export const themeScript = `(function(){try{var t=localStorage.getItem("${THEME_STORAGE_KEY}");var d=t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches;document.documentElement.classList.toggle("dark",d)}catch(e){}})()`;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|