@thinhnguyencth1204/nextcli 0.8.0 → 0.9.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 (85) hide show
  1. package/README.md +27 -24
  2. package/dist/cli.js +168 -107
  3. package/package.json +1 -1
  4. package/templates/next-base/.env +16 -0
  5. package/templates/next-base/.env.development +16 -0
  6. package/templates/next-base/.env.example +16 -0
  7. package/templates/next-base/SETUP.md +62 -10
  8. package/templates/next-base/messages/vi/auth.json +42 -0
  9. package/templates/next-base/messages/vi/common.json +34 -0
  10. package/templates/next-base/messages/vi/example.json +10 -0
  11. package/templates/next-base/next.config.ts +4 -1
  12. package/templates/next-base/nextcli.json +12 -4
  13. package/templates/next-base/package.json +24 -5
  14. package/templates/next-base/prisma/schema.prisma +84 -0
  15. package/templates/next-base/prisma.config.ts +16 -0
  16. package/templates/next-base/src/app/(auth)/.gitkeep +1 -0
  17. package/templates/next-base/src/app/(auth)/change-password/layout.tsx +21 -0
  18. package/templates/next-base/src/app/(auth)/change-password/page.tsx +14 -0
  19. package/templates/next-base/src/app/(auth)/layout.tsx +9 -0
  20. package/templates/next-base/src/app/(auth)/sign-in/layout.tsx +17 -0
  21. package/templates/next-base/src/app/(auth)/sign-in/page.tsx +14 -0
  22. package/templates/next-base/src/app/(dashboard)/account/page.tsx +18 -0
  23. package/templates/next-base/src/app/(dashboard)/dashboard/page.tsx +17 -0
  24. package/templates/next-base/src/app/(dashboard)/example/page.tsx +13 -0
  25. package/templates/next-base/src/app/(dashboard)/layout.tsx +22 -0
  26. package/templates/next-base/src/app/api/auth/[...all]/route.ts +4 -0
  27. package/templates/next-base/src/app/api/v1/auth/change-password/route.ts +55 -0
  28. package/templates/next-base/src/app/api/v1/auth/login/route.ts +70 -0
  29. package/templates/next-base/src/app/api/v1/auth/logout/route.ts +28 -0
  30. package/templates/next-base/src/app/api/v1/auth/me/route.ts +24 -0
  31. package/templates/next-base/src/app/api/v1/auth/refresh/route.ts +32 -0
  32. package/templates/next-base/src/app/api/v1/example/route.ts +34 -0
  33. package/templates/next-base/src/app/api/v1/users/[id]/route.ts +104 -0
  34. package/templates/next-base/src/app/api/v1/users/route.ts +58 -0
  35. package/templates/next-base/src/app/layout.tsx +14 -6
  36. package/templates/next-base/src/app/page.tsx +2 -25
  37. package/templates/next-base/src/components/layout/private/app-sidebar.tsx +44 -0
  38. package/templates/next-base/src/components/layout/private/dashboard-layout.tsx +54 -0
  39. package/templates/next-base/src/components/layout/private/locale-switcher.tsx +45 -0
  40. package/templates/next-base/src/components/layout/private/nav-sidebar.tsx +55 -0
  41. package/templates/next-base/src/components/layout/private/nav-user.tsx +99 -0
  42. package/templates/next-base/src/components/providers/query-provider.tsx +17 -0
  43. package/templates/next-base/src/components/ui/data-table/data-table-column-header.tsx +23 -0
  44. package/templates/next-base/src/components/ui/data-table/data-table-filter-list.tsx +3 -0
  45. package/templates/next-base/src/components/ui/data-table/data-table-pagination.tsx +35 -0
  46. package/templates/next-base/src/components/ui/data-table/data-table-skeleton.tsx +11 -0
  47. package/templates/next-base/src/components/ui/data-table/data-table-toolbar.tsx +14 -0
  48. package/templates/next-base/src/components/ui/data-table/data-table-view-options.tsx +3 -0
  49. package/templates/next-base/src/components/ui/data-table/data-table.tsx +72 -0
  50. package/templates/next-base/src/components/ui/sidebar.tsx +215 -0
  51. package/templates/next-base/src/data/sidebar-modules.ts +11 -0
  52. package/templates/next-base/src/example/api/use-example.ts +21 -0
  53. package/templates/next-base/src/example/api/use-mutations.ts +20 -0
  54. package/templates/next-base/src/example/components/example-table.tsx +51 -0
  55. package/templates/next-base/src/example/services.ts +9 -0
  56. package/templates/next-base/src/example/validations.ts +8 -0
  57. package/templates/next-base/src/features/auth/components/account-panel.tsx +80 -0
  58. package/templates/next-base/src/features/auth/components/change-password-form.tsx +82 -0
  59. package/templates/next-base/src/features/auth/components/sign-in-form.tsx +95 -0
  60. package/templates/next-base/src/features/auth/validations.ts +14 -0
  61. package/templates/next-base/src/features/users/services.ts +132 -0
  62. package/templates/next-base/src/features/users/validations.ts +21 -0
  63. package/templates/next-base/src/hooks/table/use-data-table.ts +33 -0
  64. package/templates/next-base/src/hooks/use-mobile.ts +25 -0
  65. package/templates/next-base/src/i18n/config.ts +7 -0
  66. package/templates/next-base/src/i18n/namespaces.ts +5 -0
  67. package/templates/next-base/src/i18n/request.ts +25 -0
  68. package/templates/next-base/src/instrumentation.ts +14 -0
  69. package/templates/next-base/src/lib/api/axios.ts +145 -0
  70. package/templates/next-base/src/lib/api/response.ts +45 -0
  71. package/templates/next-base/src/lib/api/token-store.ts +13 -0
  72. package/templates/next-base/src/lib/auth/bootstrap.ts +95 -0
  73. package/templates/next-base/src/lib/auth/client.ts +7 -0
  74. package/templates/next-base/src/lib/auth/cookies.ts +15 -0
  75. package/templates/next-base/src/lib/auth/index.ts +1 -0
  76. package/templates/next-base/src/lib/auth/rbac.ts +59 -0
  77. package/templates/next-base/src/lib/auth/server.ts +21 -0
  78. package/templates/next-base/src/lib/constants.ts +10 -0
  79. package/templates/next-base/src/lib/db/prisma.ts +23 -0
  80. package/templates/next-base/src/lib/prisma.ts +23 -0
  81. package/templates/next-base/src/lib/supabase/client.ts +6 -0
  82. package/templates/next-base/src/lib/supabase/rich-text-image-sync.ts +28 -0
  83. package/templates/next-base/src/lib/supabase/storage-config.ts +69 -0
  84. package/templates/next-base/src/lib/supabase/storage.ts +164 -0
  85. package/templates/next-base/src/types/data-table.ts +4 -0
@@ -2,16 +2,18 @@
2
2
 
3
3
  Quick reference for env vars and branding after `nextcli create`.
4
4
 
5
- ## Minimal base project
5
+ ## Default stack
6
6
 
7
- The default template ships a lightweight Next.js shell with branding, theme, and UI primitives only. No database, auth, or dashboard code is included until you select modules at create time or run `nextcli add module`.
7
+ The base template ships with database (Prisma + Postgres), Supabase client + Storage, Better Auth + RBAC, API client (Axios + React Query), i18n (next-intl), dashboard shell, and an example CRUD demo. Optional modules (`chat`, `supabase-realtime`, `seo`, `email`) can be added at create time or via `nextcli add module`.
8
8
 
9
9
  ## First run
10
10
 
11
- 1. `bun run dev` (or your package manager equivalent)
12
- 2. Open `http://localhost:3000`
11
+ 1. Fill env keys in `.env` (see tables below).
12
+ 2. `bun run db:migrate` (or your package manager equivalent)
13
+ 3. `bun run dev`
14
+ 4. Open `http://localhost:3000` (redirects to `/dashboard`)
13
15
 
14
- When you add the `database` module, run `bun run db:migrate` before relying on Prisma models.
16
+ Bootstrap seeds `admin` / `admin1234` on first dev start.
15
17
 
16
18
  ## Branding (edit in repo, not env)
17
19
 
@@ -29,21 +31,71 @@ Set in `.env` / `.env.development`.
29
31
  | --------------------- | ---------------------- | ------------------------------------- |
30
32
  | `NEXT_PUBLIC_APP_URL` | Client-visible app URL | Your public site URL (e.g. localhost) |
31
33
 
32
- ## Optional module environment
33
-
34
- Reference for all optional modules. Matching keys are merged into `.env` when selected at `nextcli create` or via `nextcli add module`.
34
+ ## Base module environment
35
35
 
36
36
  <!-- nextcli:enabled-modules:start -->
37
37
 
38
- **Enabled modules:** none
38
+ **Enabled modules:** `database`, `supabase`, `auth`, `api`, `i18n`, `dashboard`, `example`
39
39
 
40
40
  <!-- nextcli:enabled-modules:end -->
41
41
 
42
42
  <!-- nextcli:module-env:start -->
43
43
 
44
+ ### Module: Database (Prisma + Postgres) (`database`)
45
+
46
+ | Variable | Where to get |
47
+ | -------------- | -------------------------------------------------------------------------------------- |
48
+ | `DATABASE_URL` | Supabase Dashboard → Connect → ORMs → Prisma → pooled URL (`:6543`, `?pgbouncer=true`) |
49
+ | `DIRECT_URL` | Supabase Dashboard → Connect → direct/session URL (`:5432`) |
50
+
51
+ Run `bun run db:migrate` after setting `DATABASE_URL`.
52
+
53
+ ### Module: Supabase client + Storage (`supabase`)
54
+
55
+ | Variable | Where to get |
56
+ | ------------------------------------- | --------------------------------------------------------- |
57
+ | `NEXT_PUBLIC_SUPABASE_URL` | Supabase Dashboard → Project Settings → API → Project URL |
58
+ | `NEXT_PUBLIC_SUPABASE_ANON_KEY` | Same page → `anon` `public` key |
59
+ | `NEXT_PUBLIC_SUPABASE_STORAGE_BUCKET` | Storage bucket name (default scaffold: `public`) |
60
+
61
+ Create the bucket and RLS policies in Supabase Dashboard before uploads.
62
+
63
+ ### Module: Auth (Better Auth + RBAC) (`auth`)
64
+
65
+ | Variable | Where to get |
66
+ | -------------------- | ---------------------------------------------- |
67
+ | `BETTER_AUTH_SECRET` | Auto-generated on create; rotate in production |
68
+ | `BETTER_AUTH_URL` | Your app URL (e.g. `http://localhost:3000`) |
69
+
70
+ Requires `database` (included in base). Bootstrap seeds `admin` / `admin1234` on first dev start.
71
+
72
+ ### Module: API client (Axios + React Query) (`api`)
73
+
74
+ No extra env keys. Use `publicApi` / `protectedApi` from `src/lib/api/axios.ts` and `ok` / `fail` from `src/lib/api/response.ts`.
75
+
76
+ ### Module: Internationalization (next-intl) (`i18n`)
77
+
78
+ | Variable | Where to get |
79
+ | ---------------------------- | ------------------------------------ |
80
+ | `NEXT_PUBLIC_DEFAULT_LOCALE` | Default locale code (scaffold: `vi`) |
81
+
82
+ Add more locales with `nextcli add language`.
83
+
84
+ ### Module: Dashboard shell (`dashboard`)
85
+
86
+ Requires `auth`, `api`, and `i18n` (included in base). Protected routes redirect unauthenticated users to `/sign-in`.
87
+
88
+ ### Module: Example CRUD demo (`example`)
89
+
90
+ Requires `dashboard` and `database` (included in base). Includes demo `Example` model in `prisma/schema.prisma` — run `db:migrate` after create.
91
+
44
92
  <!-- nextcli:module-env:end -->
45
93
 
46
- ## After adding modules
94
+ ## Optional module environment
95
+
96
+ Additional keys are merged when optional modules are selected at `nextcli create` or via `nextcli add module`.
97
+
98
+ ## After adding optional modules
47
99
 
48
100
  1. Fill new env keys in `.env` and `.env.example`.
49
101
  2. Run `bun run db:migrate` when a module adds Prisma models.
@@ -0,0 +1,42 @@
1
+ {
2
+ "signInPage": {
3
+ "title": "Đăng nhập",
4
+ "description": "Dùng tên đăng nhập và mật khẩu để truy cập hệ thống."
5
+ },
6
+ "signInForm": {
7
+ "username": "Tên đăng nhập",
8
+ "password": "Mật khẩu",
9
+ "usernamePlaceholder": "admin",
10
+ "passwordPlaceholder": "********",
11
+ "submit": "Đăng nhập",
12
+ "submitting": "Đang đăng nhập...",
13
+ "invalidInput": "Vui lòng nhập tên đăng nhập và mật khẩu hợp lệ.",
14
+ "missingAccessToken": "Không tìm thấy access token.",
15
+ "success": "Đăng nhập thành công.",
16
+ "failed": "Đăng nhập thất bại."
17
+ },
18
+ "changePasswordPage": {
19
+ "title": "Đổi mật khẩu",
20
+ "description": "Bạn cần đổi mật khẩu trước khi tiếp tục sử dụng hệ thống."
21
+ },
22
+ "changePasswordForm": {
23
+ "currentPassword": "Mật khẩu hiện tại",
24
+ "newPassword": "Mật khẩu mới",
25
+ "submit": "Cập nhật mật khẩu",
26
+ "submitting": "Đang cập nhật...",
27
+ "invalidInput": "Vui lòng nhập mật khẩu hợp lệ (tối thiểu 8 ký tự).",
28
+ "success": "Đổi mật khẩu thành công.",
29
+ "failed": "Không thể đổi mật khẩu."
30
+ },
31
+ "account": {
32
+ "title": "Tài khoản",
33
+ "loading": "Đang tải thông tin tài khoản...",
34
+ "noSession": "Chưa có phiên đăng nhập hoạt động.",
35
+ "userId": "Mã người dùng",
36
+ "username": "Tên đăng nhập",
37
+ "email": "Email",
38
+ "name": "Tên",
39
+ "na": "N/A",
40
+ "goToSignIn": "Đi tới trang đăng nhập"
41
+ }
42
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "appName": "__PROJECT_NAME__",
3
+ "sidebar": {
4
+ "groupGeneral": "Tổng quan",
5
+ "dashboard": "Bảng điều khiển",
6
+ "example": "Ví dụ",
7
+ "account": "Tài khoản"
8
+ },
9
+ "header": {
10
+ "themeLight": "Sáng",
11
+ "themeDark": "Tối",
12
+ "themeSystem": "Theo hệ thống",
13
+ "toggleTheme": "Chuyển giao diện"
14
+ },
15
+ "userMenu": {
16
+ "title": "Tài khoản",
17
+ "anonymousName": "Người dùng",
18
+ "anonymousEmail": "user@example.com",
19
+ "appearance": "Giao diện",
20
+ "logout": "Đăng xuất"
21
+ },
22
+ "locale": {
23
+ "label": "Ngôn ngữ",
24
+ "vi": "Tiếng Việt",
25
+ "en": "English",
26
+ "ja": "日本語",
27
+ "ko": "한국어"
28
+ },
29
+ "table": {
30
+ "noResults": "Không có dữ liệu.",
31
+ "previous": "Trước",
32
+ "next": "Sau"
33
+ }
34
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "page": {
3
+ "title": "Ví dụ"
4
+ },
5
+ "table": {
6
+ "name": "Tên",
7
+ "description": "Mô tả",
8
+ "loading": "Đang tải dữ liệu ví dụ..."
9
+ }
10
+ }
@@ -1,4 +1,5 @@
1
1
  import type { NextConfig } from "next";
2
+ import createNextIntlPlugin from "next-intl/plugin";
2
3
  import path from "node:path";
3
4
  import { fileURLToPath } from "node:url";
4
5
 
@@ -11,4 +12,6 @@ const nextConfig: NextConfig = {
11
12
  },
12
13
  };
13
14
 
14
- export default nextConfig;
15
+ const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
16
+
17
+ export default withNextIntl(nextConfig);
@@ -1,8 +1,16 @@
1
1
  {
2
2
  "cli": "__NEXTCLI_VERSION__",
3
3
  "defaultLocale": "vi",
4
- "locales": [],
5
- "namespaces": [],
6
- "modules": [],
7
- "features": []
4
+ "locales": ["vi"],
5
+ "namespaces": ["common", "auth", "example"],
6
+ "modules": [
7
+ "database",
8
+ "supabase",
9
+ "auth",
10
+ "api",
11
+ "i18n",
12
+ "dashboard",
13
+ "example"
14
+ ],
15
+ "features": ["example"]
8
16
  }
@@ -7,9 +7,20 @@
7
7
  "dev": "next dev",
8
8
  "build": "next build",
9
9
  "start": "next start",
10
- "lint": "eslint ."
10
+ "lint": "eslint .",
11
+ "postinstall": "prisma generate",
12
+ "db:generate": "prisma generate",
13
+ "db:migrate": "prisma migrate dev",
14
+ "db:studio": "prisma studio"
11
15
  },
12
16
  "dependencies": {
17
+ "@dnd-kit/core": "^6.3.1",
18
+ "@lexical/history": "^0.45.0",
19
+ "@lexical/react": "^0.45.0",
20
+ "@lexical/rich-text": "^0.45.0",
21
+ "@lexical/utils": "^0.45.0",
22
+ "@prisma/adapter-pg": "^7.8.0",
23
+ "@prisma/client": "^7.8.0",
13
24
  "@radix-ui/react-avatar": "^1.1.10",
14
25
  "@radix-ui/react-dialog": "^1.1.15",
15
26
  "@radix-ui/react-dropdown-menu": "^2.1.16",
@@ -21,16 +32,22 @@
21
32
  "@radix-ui/react-slot": "^1.2.3",
22
33
  "@radix-ui/react-tabs": "^1.1.13",
23
34
  "@radix-ui/react-tooltip": "^1.2.8",
35
+ "@supabase/supabase-js": "^2.44.2",
36
+ "@tanstack/react-query": "^5.56.2",
37
+ "@tanstack/react-query-devtools": "^5.56.2",
38
+ "@tanstack/react-table": "^8.20.5",
39
+ "axios": "^1.7.7",
40
+ "better-auth": "^1.6.11",
24
41
  "class-variance-authority": "^0.7.0",
25
42
  "clsx": "^2.1.1",
26
- "@lexical/history": "^0.45.0",
27
- "@lexical/react": "^0.45.0",
28
- "@lexical/rich-text": "^0.45.0",
29
- "@lexical/utils": "^0.45.0",
43
+ "date-fns": "^3.6.0",
30
44
  "lexical": "^0.45.0",
31
45
  "lucide-react": "^0.525.0",
32
46
  "next": "^16.1.6",
47
+ "next-intl": "^4.13.0",
33
48
  "next-themes": "^0.4.6",
49
+ "nuqs": "^2.8.1",
50
+ "pg": "^8.16.3",
34
51
  "react": "^19.0.0",
35
52
  "react-dom": "^19.0.0",
36
53
  "sonner": "^1.7.1",
@@ -43,8 +60,10 @@
43
60
  "@types/node": "^22.7.4",
44
61
  "@types/react": "^19.0.0",
45
62
  "@types/react-dom": "^19.0.0",
63
+ "dotenv": "^17.4.2",
46
64
  "eslint": "^9.11.1",
47
65
  "eslint-config-next": "^16.1.6",
66
+ "prisma": "^7.8.0",
48
67
  "tailwindcss": "^4.1.11",
49
68
  "typescript": "^5.6.2"
50
69
  }
@@ -0,0 +1,84 @@
1
+ generator client {
2
+ provider = "prisma-client-js"
3
+ }
4
+
5
+ datasource db {
6
+ provider = "postgresql"
7
+ }
8
+
9
+ model Role {
10
+ id String @id @default(cuid())
11
+ name String @unique
12
+ level Int
13
+ createdAt DateTime @default(now())
14
+ updatedAt DateTime @updatedAt
15
+ users User[]
16
+ }
17
+
18
+ model User {
19
+ id String @id @default(cuid())
20
+ email String?
21
+ username String @unique
22
+ displayUsername String?
23
+ name String?
24
+ image String?
25
+ emailVerified Boolean @default(false)
26
+ requirePasswordChange Boolean @default(false)
27
+ roleId String?
28
+ role Role? @relation(fields: [roleId], references: [id], onDelete: SetNull)
29
+ createdAt DateTime @default(now())
30
+ updatedAt DateTime @updatedAt
31
+ sessions Session[]
32
+ accounts Account[]
33
+ }
34
+ model Session {
35
+ id String @id @default(cuid())
36
+ token String @unique
37
+ expiresAt DateTime
38
+ ipAddress String?
39
+ userAgent String?
40
+ userId String
41
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
42
+ createdAt DateTime @default(now())
43
+ updatedAt DateTime @updatedAt
44
+ }
45
+
46
+ model Account {
47
+ id String @id @default(cuid())
48
+ accountId String
49
+ providerId String
50
+ userId String
51
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
52
+ accessToken String?
53
+ refreshToken String?
54
+ idToken String?
55
+ accessTokenExpiresAt DateTime?
56
+ refreshTokenExpiresAt DateTime?
57
+ scope String?
58
+ password String?
59
+ createdAt DateTime @default(now())
60
+ updatedAt DateTime @updatedAt
61
+
62
+ @@unique([providerId, accountId])
63
+ }
64
+
65
+ model Verification {
66
+ id String @id @default(cuid())
67
+ identifier String
68
+ value String
69
+ expiresAt DateTime
70
+ createdAt DateTime? @default(now())
71
+ updatedAt DateTime? @updatedAt
72
+ }
73
+ // Optional Chatbox models are appended by NexTCLI only when adding the chat feature.
74
+ // Review generated schema changes before running migrations on production databases.
75
+
76
+ // Starter demo table for template onboarding only.
77
+ // Rename/remove this `Example` model before production migration.
78
+ model Example {
79
+ id String @id @default(cuid())
80
+ name String
81
+ description String?
82
+ createdAt DateTime @default(now())
83
+ updatedAt DateTime @updatedAt
84
+ }
@@ -0,0 +1,16 @@
1
+ import "dotenv/config";
2
+ import { defineConfig, env } from "prisma/config";
3
+
4
+ type Env = {
5
+ DIRECT_URL: string;
6
+ };
7
+
8
+ export default defineConfig({
9
+ schema: "prisma/schema.prisma",
10
+ migrations: {
11
+ path: "prisma/migrations",
12
+ },
13
+ datasource: {
14
+ url: env<Env>("DIRECT_URL"),
15
+ },
16
+ });
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from "react";
2
+ import { redirect } from "next/navigation";
3
+ import { getSessionUser } from "@/lib/auth/rbac";
4
+
5
+ export default async function ChangePasswordLayout({
6
+ children,
7
+ }: {
8
+ children: ReactNode;
9
+ }) {
10
+ const user = await getSessionUser();
11
+
12
+ if (!user) {
13
+ redirect("/sign-in");
14
+ }
15
+
16
+ if (!user.requirePasswordChange) {
17
+ redirect("/dashboard");
18
+ }
19
+
20
+ return <>{children}</>;
21
+ }
@@ -0,0 +1,14 @@
1
+ import { useTranslations } from "next-intl";
2
+ import { ChangePasswordForm } from "@/features/auth/components/change-password-form";
3
+
4
+ export default function ChangePasswordPage() {
5
+ const t = useTranslations("auth.changePasswordPage");
6
+
7
+ return (
8
+ <main className="space-y-3">
9
+ <h1 className="text-2xl font-semibold">{t("title")}</h1>
10
+ <p className="text-sm text-muted-foreground">{t("description")}</p>
11
+ <ChangePasswordForm />
12
+ </main>
13
+ );
14
+ }
@@ -0,0 +1,9 @@
1
+ import type { ReactNode } from "react";
2
+
3
+ export default function AuthRouteLayout({ children }: { children: ReactNode }) {
4
+ return (
5
+ <div className="flex min-h-screen items-center justify-center p-4">
6
+ <div className="w-full max-w-md">{children}</div>
7
+ </div>
8
+ );
9
+ }
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from "react";
2
+ import { redirect } from "next/navigation";
3
+ import { getSessionUser } from "@/lib/auth/rbac";
4
+
5
+ export default async function SignInLayout({ children }: { children: ReactNode }) {
6
+ const user = await getSessionUser();
7
+
8
+ if (user?.requirePasswordChange) {
9
+ redirect("/change-password");
10
+ }
11
+
12
+ if (user) {
13
+ redirect("/dashboard");
14
+ }
15
+
16
+ return children;
17
+ }
@@ -0,0 +1,14 @@
1
+ import { useTranslations } from "next-intl";
2
+ import { SignInForm } from "@/features/auth/components/sign-in-form";
3
+
4
+ export default function SignInPage() {
5
+ const t = useTranslations("auth.signInPage");
6
+
7
+ return (
8
+ <main className="space-y-3">
9
+ <h1 className="text-2xl font-semibold">{t("title")}</h1>
10
+ <p className="text-sm text-muted-foreground">{t("description")}</p>
11
+ <SignInForm />
12
+ </main>
13
+ );
14
+ }
@@ -0,0 +1,18 @@
1
+ import Link from "next/link";
2
+ import { useTranslations } from "next-intl";
3
+ import { AccountPanel } from "@/features/auth/components/account-panel";
4
+ import { Button } from "@/components/ui/button";
5
+
6
+ export default function AccountPage() {
7
+ const t = useTranslations("auth.account");
8
+
9
+ return (
10
+ <main className="space-y-4">
11
+ <h1 className="text-2xl font-semibold">{t("title")}</h1>
12
+ <AccountPanel />
13
+ <Button asChild variant="outline">
14
+ <Link href="/sign-in">{t("goToSignIn")}</Link>
15
+ </Button>
16
+ </main>
17
+ );
18
+ }
@@ -0,0 +1,17 @@
1
+ import { useTranslations } from "next-intl";
2
+ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
3
+
4
+ export default function DashboardPage() {
5
+ const t = useTranslations("common.sidebar");
6
+
7
+ return (
8
+ <Card>
9
+ <CardHeader>
10
+ <CardTitle>{t("dashboard")}</CardTitle>
11
+ </CardHeader>
12
+ <CardContent className="text-sm text-muted-foreground">
13
+ Starter dashboard page. Add your own widgets and metrics here.
14
+ </CardContent>
15
+ </Card>
16
+ );
17
+ }
@@ -0,0 +1,13 @@
1
+ import { useTranslations } from "next-intl";
2
+ import { ExampleTable } from "@/example/components/example-table";
3
+
4
+ export default function ExamplePage() {
5
+ const t = useTranslations("example.page");
6
+
7
+ return (
8
+ <main className="space-y-4">
9
+ <h1 className="text-2xl font-semibold">{t("title")}</h1>
10
+ <ExampleTable />
11
+ </main>
12
+ );
13
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactNode } from "react";
2
+ import { redirect } from "next/navigation";
3
+ import { DashboardLayout } from "@/components/layout/private/dashboard-layout";
4
+ import { getSessionUser } from "@/lib/auth/rbac";
5
+
6
+ export default async function DashboardRouteLayout({
7
+ children,
8
+ }: {
9
+ children: ReactNode;
10
+ }) {
11
+ const user = await getSessionUser();
12
+
13
+ if (!user) {
14
+ redirect("/sign-in");
15
+ }
16
+
17
+ if (user.requirePasswordChange) {
18
+ redirect("/change-password");
19
+ }
20
+
21
+ return <DashboardLayout>{children}</DashboardLayout>;
22
+ }
@@ -0,0 +1,4 @@
1
+ import { toNextJsHandler } from "better-auth/next-js";
2
+ import { auth } from "@/lib/auth";
3
+
4
+ export const { GET, POST } = toNextJsHandler(auth);
@@ -0,0 +1,55 @@
1
+ import { changePasswordSchema } from "@/features/auth/validations";
2
+ import { fail, ok } from "@/lib/api/response";
3
+ import { auth } from "@/lib/auth";
4
+ import { getSessionUser } from "@/lib/auth/rbac";
5
+ import prisma from "@/lib/db/prisma";
6
+
7
+ const authBaseUrl =
8
+ process.env.BETTER_AUTH_URL ??
9
+ process.env.NEXT_PUBLIC_APP_URL ??
10
+ "http://localhost:3000";
11
+
12
+ export async function POST(request: Request) {
13
+ const actor = await getSessionUser(request.headers);
14
+ if (!actor) {
15
+ return fail("UNAUTHORIZED", "Unauthorized", { status: 401 });
16
+ }
17
+
18
+ const payload = await request.json().catch(() => null);
19
+ const parsed = changePasswordSchema.safeParse(payload);
20
+
21
+ if (!parsed.success) {
22
+ return fail("VALIDATION_ERROR", "Invalid password payload.", {
23
+ status: 400,
24
+ details: parsed.error.flatten(),
25
+ });
26
+ }
27
+
28
+ const verifyResponse = await fetch(`${authBaseUrl}/api/auth/sign-in/username`, {
29
+ method: "POST",
30
+ headers: { "Content-Type": "application/json" },
31
+ body: JSON.stringify({
32
+ username: actor.username,
33
+ password: parsed.data.currentPassword,
34
+ }),
35
+ });
36
+
37
+ if (!verifyResponse.ok) {
38
+ return fail("UNAUTHORIZED", "Current password is incorrect.", { status: 401 });
39
+ }
40
+
41
+ await auth.api.changePassword({
42
+ body: {
43
+ currentPassword: parsed.data.currentPassword,
44
+ newPassword: parsed.data.newPassword,
45
+ },
46
+ headers: request.headers,
47
+ });
48
+
49
+ await prisma.user.update({
50
+ where: { id: actor.id },
51
+ data: { requirePasswordChange: false },
52
+ });
53
+
54
+ return ok({ updated: true });
55
+ }