@thinhnguyencth1204/nextcli 0.2.1 → 0.4.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 +6 -2
- package/dist/cli.js +778 -101
- package/package.json +2 -1
- package/templates/next-base/PROJECT_STRUCTURE.md +88 -0
- package/templates/next-base/SETUP.md +86 -0
- package/templates/next-base/bun.lock +1443 -0
- package/templates/next-base/components.json +21 -0
- package/templates/next-base/messages/vi/auth.json +42 -0
- package/templates/next-base/messages/vi/common.json +34 -0
- package/templates/next-base/messages/vi/example.json +10 -0
- package/templates/next-base/next-env.d.ts +3 -1
- package/templates/next-base/next.config.ts +11 -1
- package/templates/next-base/nextcli.json +8 -0
- package/templates/next-base/package.json +21 -1
- package/templates/next-base/postcss.config.mjs +5 -0
- package/templates/next-base/prisma/migrations/20260612000000_init/migration.sql +104 -0
- package/templates/next-base/prisma/migrations/migration_lock.toml +3 -0
- package/templates/next-base/prisma/schema.prisma +23 -9
- package/templates/next-base/public/logo.svg +4 -0
- package/templates/next-base/src/app/(auth)/change-password/layout.tsx +21 -0
- package/templates/next-base/src/app/(auth)/change-password/page.tsx +14 -0
- package/templates/next-base/src/app/(auth)/layout.tsx +9 -0
- package/templates/next-base/src/app/(auth)/sign-in/layout.tsx +17 -0
- package/templates/next-base/src/app/(auth)/sign-in/page.tsx +6 -3
- package/templates/next-base/src/app/(dashboard)/account/page.tsx +9 -5
- package/templates/next-base/src/app/(dashboard)/dashboard/page.tsx +17 -0
- package/templates/next-base/src/app/(dashboard)/example/page.tsx +5 -2
- package/templates/next-base/src/app/(dashboard)/layout.tsx +22 -0
- package/templates/next-base/src/app/api/v1/auth/change-password/route.ts +55 -0
- package/templates/next-base/src/app/api/v1/auth/login/route.ts +15 -5
- package/templates/next-base/src/app/api/v1/auth/me/route.ts +17 -19
- package/templates/next-base/src/app/api/v1/users/[id]/route.ts +104 -0
- package/templates/next-base/src/app/api/v1/users/route.ts +58 -0
- package/templates/next-base/src/app/globals.css +111 -0
- package/templates/next-base/src/app/layout.tsx +24 -10
- package/templates/next-base/src/app/page.tsx +2 -18
- package/templates/next-base/src/components/branding/logo.tsx +27 -0
- package/templates/next-base/src/components/layout/private/app-sidebar.tsx +44 -0
- package/templates/next-base/src/components/layout/private/dashboard-layout.tsx +54 -0
- package/templates/next-base/src/components/layout/private/locale-switcher.tsx +45 -0
- package/templates/next-base/src/components/layout/private/nav-sidebar.tsx +55 -0
- package/templates/next-base/src/components/layout/private/nav-user.tsx +99 -0
- package/templates/next-base/src/components/providers/theme-provider.tsx +11 -0
- package/templates/next-base/src/components/ui/alert-dialog.tsx +11 -0
- package/templates/next-base/src/components/ui/avatar.tsx +45 -0
- package/templates/next-base/src/components/ui/badge.tsx +29 -0
- package/templates/next-base/src/components/ui/button.tsx +47 -7
- package/templates/next-base/src/components/ui/card.tsx +54 -0
- package/templates/next-base/src/components/ui/data-table/data-table-column-header.tsx +23 -0
- package/templates/next-base/src/components/ui/data-table/data-table-filter-list.tsx +3 -0
- package/templates/next-base/src/components/ui/data-table/data-table-pagination.tsx +35 -0
- package/templates/next-base/src/components/ui/data-table/data-table-skeleton.tsx +11 -0
- package/templates/next-base/src/components/ui/data-table/data-table-toolbar.tsx +14 -0
- package/templates/next-base/src/components/ui/data-table/data-table-view-options.tsx +3 -0
- package/templates/next-base/src/components/ui/data-table/data-table.tsx +72 -0
- package/templates/next-base/src/components/ui/dialog.tsx +105 -0
- package/templates/next-base/src/components/ui/dropdown-menu.tsx +44 -0
- package/templates/next-base/src/components/ui/input.tsx +19 -0
- package/templates/next-base/src/components/ui/label.tsx +15 -0
- package/templates/next-base/src/components/ui/popover.tsx +30 -0
- package/templates/next-base/src/components/ui/scroll-area.tsx +47 -0
- package/templates/next-base/src/components/ui/select.tsx +76 -0
- package/templates/next-base/src/components/ui/separator.tsx +23 -0
- package/templates/next-base/src/components/ui/sheet.tsx +117 -0
- package/templates/next-base/src/components/ui/sidebar.tsx +215 -0
- package/templates/next-base/src/components/ui/skeleton.tsx +10 -0
- package/templates/next-base/src/components/ui/sonner.tsx +3 -0
- package/templates/next-base/src/components/ui/table.tsx +54 -0
- package/templates/next-base/src/components/ui/tabs.tsx +52 -0
- package/templates/next-base/src/components/ui/textarea.tsx +17 -0
- package/templates/next-base/src/components/ui/tooltip.tsx +26 -0
- package/templates/next-base/src/config/branding.ts +14 -0
- package/templates/next-base/src/data/sidebar-modules.ts +11 -0
- package/templates/next-base/src/example/components/example-table.tsx +25 -40
- package/templates/next-base/src/features/auth/components/account-panel.tsx +32 -14
- package/templates/next-base/src/features/auth/components/change-password-form.tsx +82 -0
- package/templates/next-base/src/features/auth/components/sign-in-form.tsx +53 -35
- package/templates/next-base/src/features/auth/validations.ts +7 -1
- package/templates/next-base/src/features/users/services.ts +132 -0
- package/templates/next-base/src/features/users/validations.ts +21 -0
- package/templates/next-base/src/hooks/index.ts +1 -1
- package/templates/next-base/src/hooks/table/use-data-table.ts +33 -0
- package/templates/next-base/src/hooks/use-mobile.ts +25 -0
- package/templates/next-base/src/i18n/config.ts +7 -0
- package/templates/next-base/src/i18n/namespaces.ts +5 -0
- package/templates/next-base/src/i18n/request.ts +19 -2
- package/templates/next-base/src/instrumentation.ts +14 -0
- package/templates/next-base/src/lib/auth-client.ts +2 -2
- package/templates/next-base/src/lib/auth.ts +2 -2
- package/templates/next-base/src/lib/bootstrap.ts +96 -0
- package/templates/next-base/src/lib/constants.ts +7 -0
- package/templates/next-base/src/lib/prisma.ts +11 -1
- package/templates/next-base/src/lib/rbac.ts +62 -0
- package/templates/next-base/src/types/data-table.ts +4 -0
- package/templates/next-base/src/types/index.ts +2 -0
- package/templates/next-base/tsconfig.json +29 -7
- package/templates/next-base/middleware.ts +0 -10
- package/templates/next-base/src/app/styles.css +0 -12
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": true,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/app/globals.css",
|
|
9
|
+
"baseColor": "neutral",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"iconLibrary": "lucide",
|
|
14
|
+
"aliases": {
|
|
15
|
+
"components": "@/components",
|
|
16
|
+
"utils": "@/utils/cn",
|
|
17
|
+
"ui": "@/components/ui",
|
|
18
|
+
"lib": "@/lib",
|
|
19
|
+
"hooks": "@/hooks"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="next" />
|
|
2
2
|
/// <reference types="next/image-types/global" />
|
|
3
|
+
import "./.next/dev/types/routes.d.ts";
|
|
3
4
|
|
|
4
|
-
// This file
|
|
5
|
+
// NOTE: This file should not be edited
|
|
6
|
+
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import type { NextConfig } from "next";
|
|
2
|
+
import createNextIntlPlugin from "next-intl/plugin";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const rootDir = path.dirname(fileURLToPath(import.meta.url));
|
|
2
7
|
|
|
3
8
|
const nextConfig: NextConfig = {
|
|
4
9
|
reactStrictMode: true,
|
|
10
|
+
turbopack: {
|
|
11
|
+
root: rootDir,
|
|
12
|
+
},
|
|
5
13
|
};
|
|
6
14
|
|
|
7
|
-
|
|
15
|
+
const withNextIntl = createNextIntlPlugin("./src/i18n/request.ts");
|
|
16
|
+
|
|
17
|
+
export default withNextIntl(nextConfig);
|
|
@@ -8,30 +8,50 @@
|
|
|
8
8
|
"build": "next build",
|
|
9
9
|
"start": "next start",
|
|
10
10
|
"lint": "eslint .",
|
|
11
|
+
"postinstall": "prisma generate",
|
|
11
12
|
"db:generate": "prisma generate",
|
|
12
13
|
"db:migrate": "prisma migrate dev",
|
|
13
14
|
"db:studio": "prisma studio"
|
|
14
15
|
},
|
|
15
16
|
"dependencies": {
|
|
16
17
|
"@prisma/client": "^7.8.0",
|
|
18
|
+
"@prisma/adapter-pg": "^7.8.0",
|
|
19
|
+
"@radix-ui/react-avatar": "^1.1.10",
|
|
20
|
+
"@radix-ui/react-dialog": "^1.1.15",
|
|
21
|
+
"@radix-ui/react-dropdown-menu": "^2.1.16",
|
|
22
|
+
"@radix-ui/react-label": "^2.1.7",
|
|
23
|
+
"@radix-ui/react-popover": "^1.1.15",
|
|
24
|
+
"@radix-ui/react-scroll-area": "^1.2.10",
|
|
25
|
+
"@radix-ui/react-select": "^2.2.6",
|
|
26
|
+
"@radix-ui/react-separator": "^1.1.7",
|
|
27
|
+
"@radix-ui/react-slot": "^1.2.3",
|
|
28
|
+
"@radix-ui/react-tabs": "^1.1.13",
|
|
29
|
+
"@radix-ui/react-tooltip": "^1.2.8",
|
|
17
30
|
"@tanstack/react-form": "^1.0.3",
|
|
18
31
|
"@tanstack/react-query": "^5.56.2",
|
|
19
32
|
"@tanstack/react-query-devtools": "^5.56.2",
|
|
20
33
|
"@tanstack/react-table": "^8.20.5",
|
|
34
|
+
"@dnd-kit/core": "^6.3.1",
|
|
21
35
|
"axios": "^1.7.7",
|
|
22
36
|
"better-auth": "^1.6.11",
|
|
23
37
|
"class-variance-authority": "^0.7.0",
|
|
24
38
|
"clsx": "^2.1.1",
|
|
25
39
|
"date-fns": "^3.6.0",
|
|
40
|
+
"lucide-react": "^0.525.0",
|
|
26
41
|
"next": "^16.1.6",
|
|
27
42
|
"next-intl": "^4.13.0",
|
|
43
|
+
"next-themes": "^0.4.6",
|
|
44
|
+
"nuqs": "^2.8.1",
|
|
28
45
|
"react": "^19.0.0",
|
|
29
46
|
"react-dom": "^19.0.0",
|
|
47
|
+
"pg": "^8.16.3",
|
|
30
48
|
"sonner": "^1.7.1",
|
|
31
49
|
"tailwind-merge": "^2.5.3",
|
|
50
|
+
"tw-animate-css": "^1.3.0",
|
|
32
51
|
"zod": "^3.23.8"
|
|
33
52
|
},
|
|
34
53
|
"devDependencies": {
|
|
54
|
+
"@tailwindcss/postcss": "^4.1.11",
|
|
35
55
|
"dotenv": "^17.4.2",
|
|
36
56
|
"@types/node": "^22.7.4",
|
|
37
57
|
"@types/react": "^19.0.0",
|
|
@@ -39,7 +59,7 @@
|
|
|
39
59
|
"eslint": "^9.11.1",
|
|
40
60
|
"eslint-config-next": "^16.1.6",
|
|
41
61
|
"prisma": "^7.8.0",
|
|
42
|
-
"tailwindcss": "^
|
|
62
|
+
"tailwindcss": "^4.1.11",
|
|
43
63
|
"typescript": "^5.6.2"
|
|
44
64
|
}
|
|
45
65
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
-- CreateTable
|
|
2
|
+
CREATE TABLE "Role" (
|
|
3
|
+
"id" TEXT NOT NULL,
|
|
4
|
+
"name" TEXT NOT NULL,
|
|
5
|
+
"level" INTEGER NOT NULL,
|
|
6
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
7
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
8
|
+
|
|
9
|
+
CONSTRAINT "Role_pkey" PRIMARY KEY ("id")
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- CreateTable
|
|
13
|
+
CREATE TABLE "User" (
|
|
14
|
+
"id" TEXT NOT NULL,
|
|
15
|
+
"email" TEXT,
|
|
16
|
+
"username" TEXT NOT NULL,
|
|
17
|
+
"displayUsername" TEXT,
|
|
18
|
+
"name" TEXT,
|
|
19
|
+
"image" TEXT,
|
|
20
|
+
"emailVerified" BOOLEAN NOT NULL DEFAULT false,
|
|
21
|
+
"requirePasswordChange" BOOLEAN NOT NULL DEFAULT false,
|
|
22
|
+
"roleId" TEXT,
|
|
23
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
24
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
25
|
+
|
|
26
|
+
CONSTRAINT "User_pkey" PRIMARY KEY ("id")
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
-- CreateTable
|
|
30
|
+
CREATE TABLE "Example" (
|
|
31
|
+
"id" TEXT NOT NULL,
|
|
32
|
+
"name" TEXT NOT NULL,
|
|
33
|
+
"description" TEXT,
|
|
34
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
35
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
36
|
+
|
|
37
|
+
CONSTRAINT "Example_pkey" PRIMARY KEY ("id")
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
-- CreateTable
|
|
41
|
+
CREATE TABLE "Session" (
|
|
42
|
+
"id" TEXT NOT NULL,
|
|
43
|
+
"token" TEXT NOT NULL,
|
|
44
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
45
|
+
"ipAddress" TEXT,
|
|
46
|
+
"userAgent" TEXT,
|
|
47
|
+
"userId" TEXT NOT NULL,
|
|
48
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
49
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
50
|
+
|
|
51
|
+
CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
-- CreateTable
|
|
55
|
+
CREATE TABLE "Account" (
|
|
56
|
+
"id" TEXT NOT NULL,
|
|
57
|
+
"accountId" TEXT NOT NULL,
|
|
58
|
+
"providerId" TEXT NOT NULL,
|
|
59
|
+
"userId" TEXT NOT NULL,
|
|
60
|
+
"accessToken" TEXT,
|
|
61
|
+
"refreshToken" TEXT,
|
|
62
|
+
"idToken" TEXT,
|
|
63
|
+
"accessTokenExpiresAt" TIMESTAMP(3),
|
|
64
|
+
"refreshTokenExpiresAt" TIMESTAMP(3),
|
|
65
|
+
"scope" TEXT,
|
|
66
|
+
"password" TEXT,
|
|
67
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
68
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
69
|
+
|
|
70
|
+
CONSTRAINT "Account_pkey" PRIMARY KEY ("id")
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
-- CreateTable
|
|
74
|
+
CREATE TABLE "Verification" (
|
|
75
|
+
"id" TEXT NOT NULL,
|
|
76
|
+
"identifier" TEXT NOT NULL,
|
|
77
|
+
"value" TEXT NOT NULL,
|
|
78
|
+
"expiresAt" TIMESTAMP(3) NOT NULL,
|
|
79
|
+
"createdAt" TIMESTAMP(3) DEFAULT CURRENT_TIMESTAMP,
|
|
80
|
+
"updatedAt" TIMESTAMP(3),
|
|
81
|
+
|
|
82
|
+
CONSTRAINT "Verification_pkey" PRIMARY KEY ("id")
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
-- CreateIndex
|
|
86
|
+
CREATE UNIQUE INDEX "Role_name_key" ON "Role"("name");
|
|
87
|
+
|
|
88
|
+
-- CreateIndex
|
|
89
|
+
CREATE UNIQUE INDEX "User_username_key" ON "User"("username");
|
|
90
|
+
|
|
91
|
+
-- CreateIndex
|
|
92
|
+
CREATE UNIQUE INDEX "Session_token_key" ON "Session"("token");
|
|
93
|
+
|
|
94
|
+
-- CreateIndex
|
|
95
|
+
CREATE UNIQUE INDEX "Account_providerId_accountId_key" ON "Account"("providerId", "accountId");
|
|
96
|
+
|
|
97
|
+
-- AddForeignKey
|
|
98
|
+
ALTER TABLE "User" ADD CONSTRAINT "User_roleId_fkey" FOREIGN KEY ("roleId") REFERENCES "Role"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
|
99
|
+
|
|
100
|
+
-- AddForeignKey
|
|
101
|
+
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
102
|
+
|
|
103
|
+
-- AddForeignKey
|
|
104
|
+
ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
@@ -6,16 +6,30 @@ datasource db {
|
|
|
6
6
|
provider = "postgresql"
|
|
7
7
|
}
|
|
8
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
|
+
|
|
9
18
|
model User {
|
|
10
|
-
id
|
|
11
|
-
email
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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[]
|
|
19
33
|
}
|
|
20
34
|
|
|
21
35
|
// Starter demo table for template onboarding only.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
|
|
2
|
+
<rect width="64" height="64" rx="12" fill="oklch(0.205 0 0)"/>
|
|
3
|
+
<path d="M18 44V20h10.5c5.2 0 8.5 2.8 8.5 7.2 0 3.1-1.7 5.4-4.5 6.5L38 44h-6.2l-4.8-9.2H24.2V44H18zm6.2-14.8h3.8c2.4 0 3.8-1.2 3.8-3.1s-1.4-3.1-3.8-3.1h-3.8v6.2z" fill="oklch(0.985 0 0)"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { redirect } from "next/navigation";
|
|
3
|
+
import { getSessionUser } from "@/lib/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/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
|
+
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { useTranslations } from "next-intl";
|
|
1
2
|
import { SignInForm } from "@/features/auth/components/sign-in-form";
|
|
2
3
|
|
|
3
4
|
export default function SignInPage() {
|
|
5
|
+
const t = useTranslations("auth.signInPage");
|
|
6
|
+
|
|
4
7
|
return (
|
|
5
|
-
<main
|
|
6
|
-
<h1>
|
|
7
|
-
<p
|
|
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>
|
|
8
11
|
<SignInForm />
|
|
9
12
|
</main>
|
|
10
13
|
);
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import Link from "next/link";
|
|
2
|
+
import { useTranslations } from "next-intl";
|
|
2
3
|
import { AccountPanel } from "@/features/auth/components/account-panel";
|
|
4
|
+
import { Button } from "@/components/ui/button";
|
|
3
5
|
|
|
4
6
|
export default function AccountPage() {
|
|
7
|
+
const t = useTranslations("auth.account");
|
|
8
|
+
|
|
5
9
|
return (
|
|
6
|
-
<main
|
|
7
|
-
<h1>
|
|
10
|
+
<main className="space-y-4">
|
|
11
|
+
<h1 className="text-2xl font-semibold">{t("title")}</h1>
|
|
8
12
|
<AccountPanel />
|
|
9
|
-
<
|
|
10
|
-
<Link href="/sign-in">
|
|
11
|
-
</
|
|
13
|
+
<Button asChild variant="outline">
|
|
14
|
+
<Link href="/sign-in">{t("goToSignIn")}</Link>
|
|
15
|
+
</Button>
|
|
12
16
|
</main>
|
|
13
17
|
);
|
|
14
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
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { useTranslations } from "next-intl";
|
|
1
2
|
import { ExampleTable } from "@/example/components/example-table";
|
|
2
3
|
|
|
3
4
|
export default function ExamplePage() {
|
|
5
|
+
const t = useTranslations("example.page");
|
|
6
|
+
|
|
4
7
|
return (
|
|
5
|
-
<main
|
|
6
|
-
<h1>
|
|
8
|
+
<main className="space-y-4">
|
|
9
|
+
<h1 className="text-2xl font-semibold">{t("title")}</h1>
|
|
7
10
|
<ExampleTable />
|
|
8
11
|
</main>
|
|
9
12
|
);
|
|
@@ -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/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,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/rbac";
|
|
5
|
+
import prisma from "@/lib/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
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getRefreshCookieName, refreshCookieOptions } from "@/lib/auth-cookies";
|
|
2
2
|
import { fail, ok } from "@/lib/api-response";
|
|
3
|
+
import prisma from "@/lib/prisma";
|
|
3
4
|
|
|
4
5
|
const authBaseUrl =
|
|
5
6
|
process.env.BETTER_AUTH_URL ??
|
|
@@ -8,21 +9,23 @@ const authBaseUrl =
|
|
|
8
9
|
|
|
9
10
|
export async function POST(request: Request) {
|
|
10
11
|
const payload = (await request.json().catch(() => ({}))) as {
|
|
11
|
-
|
|
12
|
+
username?: string;
|
|
12
13
|
password?: string;
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
if (!payload.
|
|
16
|
-
return fail("BAD_REQUEST", "
|
|
16
|
+
if (!payload.username || !payload.password) {
|
|
17
|
+
return fail("BAD_REQUEST", "Username and password are required.", {
|
|
18
|
+
status: 400,
|
|
19
|
+
});
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
const signInResponse = await fetch(`${authBaseUrl}/api/auth/sign-in/
|
|
22
|
+
const signInResponse = await fetch(`${authBaseUrl}/api/auth/sign-in/username`, {
|
|
20
23
|
method: "POST",
|
|
21
24
|
headers: {
|
|
22
25
|
"Content-Type": "application/json",
|
|
23
26
|
},
|
|
24
27
|
body: JSON.stringify({
|
|
25
|
-
|
|
28
|
+
username: payload.username,
|
|
26
29
|
password: payload.password,
|
|
27
30
|
}),
|
|
28
31
|
});
|
|
@@ -47,8 +50,15 @@ export async function POST(request: Request) {
|
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
const tokenPayload = await tokenResponse.json();
|
|
53
|
+
|
|
54
|
+
const dbUser = await prisma.user.findUnique({
|
|
55
|
+
where: { username: payload.username },
|
|
56
|
+
select: { requirePasswordChange: true },
|
|
57
|
+
});
|
|
58
|
+
|
|
50
59
|
const response = ok({
|
|
51
60
|
accessToken: tokenPayload.token,
|
|
61
|
+
requirePasswordChange: dbUser?.requirePasswordChange ?? false,
|
|
52
62
|
});
|
|
53
63
|
|
|
54
64
|
if (cookieHeader) {
|