create-stackkit-app 0.4.1 → 0.4.3
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 +27 -7
- package/bin/create-stackkit.js +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/create-project.js +408 -139
- package/dist/lib/template-composer.js +22 -22
- package/modules/auth/better-auth-express/adapters/mongoose-mongodb.ts +13 -0
- package/modules/auth/better-auth-express/adapters/prisma-mongodb.ts +15 -0
- package/modules/auth/better-auth-express/adapters/prisma-postgresql.ts +15 -0
- package/modules/auth/better-auth-express/files/lib/auth.ts +1 -1
- package/modules/auth/better-auth-express/files/routes/auth.ts +3 -3
- package/modules/auth/better-auth-express/files/schemas/prisma-mongodb-schema.prisma +72 -0
- package/modules/auth/better-auth-express/files/schemas/prisma-postgresql-schema.prisma +72 -0
- package/modules/auth/better-auth-express/module.json +26 -3
- package/modules/auth/better-auth-nextjs/adapters/mongoose-mongodb.ts +24 -0
- package/modules/auth/better-auth-nextjs/adapters/prisma-mongodb.ts +26 -0
- package/modules/auth/better-auth-nextjs/adapters/prisma-postgresql.ts +26 -0
- package/modules/auth/better-auth-nextjs/files/api/auth/[...all]/route.ts +2 -3
- package/modules/auth/better-auth-nextjs/files/lib/auth.ts +4 -4
- package/modules/auth/better-auth-nextjs/files/schemas/prisma-mongodb-schema.prisma +72 -0
- package/modules/auth/better-auth-nextjs/files/schemas/prisma-postgresql-schema.prisma +72 -0
- package/modules/auth/better-auth-nextjs/module.json +26 -5
- package/modules/auth/better-auth-react/files/lib/auth-client.ts +2 -2
- package/modules/auth/better-auth-react/module.json +7 -5
- package/modules/auth/clerk-express/files/lib/auth.ts +1 -1
- package/modules/auth/clerk-express/module.json +23 -8
- package/modules/auth/clerk-nextjs/files/lib/auth-provider.tsx +1 -1
- package/modules/auth/clerk-nextjs/files/middleware.ts +3 -3
- package/modules/auth/clerk-nextjs/module.json +51 -14
- package/modules/auth/clerk-react/files/lib/auth-provider.tsx +2 -2
- package/modules/auth/clerk-react/module.json +17 -7
- package/modules/database/mongoose-mongodb/files/lib/db.ts +3 -3
- package/modules/database/mongoose-mongodb/module.json +44 -6
- package/modules/database/prisma-mongodb/files/lib/db.ts +2 -2
- package/modules/database/prisma-mongodb/files/prisma/schema.prisma +1 -1
- package/modules/database/prisma-mongodb/module.json +28 -4
- package/modules/database/prisma-postgresql/files/lib/db.ts +2 -2
- package/modules/database/prisma-postgresql/files/prisma/schema.prisma +1 -1
- package/modules/database/prisma-postgresql/module.json +28 -4
- package/package.json +8 -3
- package/templates/express/.env.example +11 -0
- package/templates/express/eslint.config.cjs +42 -0
- package/templates/express/package.json +39 -0
- package/templates/express/src/app.ts +71 -0
- package/templates/express/src/config/env.ts +23 -0
- package/templates/express/src/middlewares/error.middleware.ts +18 -0
- package/templates/{bases/express-base → express}/src/server.ts +2 -2
- package/templates/express/template.json +44 -0
- package/templates/express/tsconfig.json +31 -0
- package/templates/{bases/nextjs-base → nextjs}/app/layout.tsx +1 -5
- package/templates/nextjs/app/page.tsx +57 -0
- package/templates/{bases/nextjs-base → nextjs}/package.json +2 -1
- package/templates/{bases/nextjs-base → nextjs}/template.json +13 -1
- package/templates/react-vite/.env.example +2 -0
- package/templates/react-vite/README.md +85 -0
- package/templates/react-vite/eslint.config.js +23 -0
- package/templates/{bases/react-vite-base → react-vite}/index.html +1 -0
- package/templates/{bases/react-vite-base → react-vite}/package.json +16 -2
- package/templates/react-vite/src/api/client.ts +47 -0
- package/templates/react-vite/src/api/services/user.service.ts +18 -0
- package/templates/react-vite/src/components/ErrorBoundary.tsx +51 -0
- package/templates/react-vite/src/components/Layout.tsx +13 -0
- package/templates/react-vite/src/components/Loading.tsx +8 -0
- package/templates/react-vite/src/components/SEO.tsx +49 -0
- package/templates/react-vite/src/config/constants.ts +5 -0
- package/templates/react-vite/src/hooks/index.ts +64 -0
- package/templates/react-vite/src/index.css +1 -0
- package/templates/react-vite/src/lib/queryClient.ts +12 -0
- package/templates/react-vite/src/main.tsx +22 -0
- package/templates/react-vite/src/pages/About.tsx +78 -0
- package/templates/react-vite/src/pages/Home.tsx +49 -0
- package/templates/react-vite/src/pages/NotFound.tsx +24 -0
- package/templates/react-vite/src/pages/UserProfile.tsx +40 -0
- package/templates/react-vite/src/router.tsx +33 -0
- package/templates/react-vite/src/types/api.d.ts +20 -0
- package/templates/react-vite/src/types/user.d.ts +6 -0
- package/templates/react-vite/src/utils/helpers.ts +51 -0
- package/templates/react-vite/src/utils/storage.ts +35 -0
- package/templates/react-vite/src/vite-env.d.ts +11 -0
- package/templates/react-vite/template.json +46 -0
- package/templates/react-vite/tsconfig.json +4 -0
- package/templates/react-vite/vite.config.ts +13 -0
- package/modules/database/drizzle-postgresql/files/drizzle.config.ts +0 -10
- package/modules/database/drizzle-postgresql/files/lib/db.ts +0 -7
- package/modules/database/drizzle-postgresql/files/lib/schema.ts +0 -8
- package/modules/database/drizzle-postgresql/module.json +0 -34
- package/templates/bases/express-base/.env.example +0 -2
- package/templates/bases/express-base/package.json +0 -23
- package/templates/bases/express-base/src/app.ts +0 -34
- package/templates/bases/express-base/src/config/env.ts +0 -14
- package/templates/bases/express-base/src/middlewares/error.middleware.ts +0 -12
- package/templates/bases/express-base/template.json +0 -7
- package/templates/bases/express-base/tsconfig.json +0 -14
- package/templates/bases/nextjs-base/app/page.tsx +0 -65
- package/templates/bases/react-vite-base/README.md +0 -73
- package/templates/bases/react-vite-base/eslint.config.js +0 -23
- package/templates/bases/react-vite-base/src/App.css +0 -42
- package/templates/bases/react-vite-base/src/App.tsx +0 -35
- package/templates/bases/react-vite-base/src/index.css +0 -68
- package/templates/bases/react-vite-base/src/main.tsx +0 -10
- package/templates/bases/react-vite-base/template.json +0 -19
- package/templates/bases/react-vite-base/tsconfig.json +0 -7
- package/templates/bases/react-vite-base/vite.config.ts +0 -7
- /package/templates/{bases/nextjs-base → nextjs}/README.md +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/app/favicon.ico +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/app/globals.css +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/eslint.config.mjs +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/next.config.ts +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/postcss.config.mjs +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/public/file.svg +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/public/globe.svg +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/public/next.svg +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/public/vercel.svg +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/public/window.svg +0 -0
- /package/templates/{bases/nextjs-base → nextjs}/tsconfig.json +0 -0
- /package/templates/{bases/react-vite-base → react-vite}/public/vite.svg +0 -0
- /package/templates/{bases/react-vite-base → react-vite}/src/assets/react.svg +0 -0
- /package/templates/{bases/react-vite-base → react-vite}/tsconfig.app.json +0 -0
- /package/templates/{bases/react-vite-base → react-vite}/tsconfig.node.json +0 -0
|
@@ -17,14 +17,14 @@ class TemplateComposer {
|
|
|
17
17
|
const configs = [];
|
|
18
18
|
const filesToCopy = [];
|
|
19
19
|
// 1. Load base framework template
|
|
20
|
-
const baseConfig = await this.loadConfig(path_1.default.join(this.templatesDir,
|
|
20
|
+
const baseConfig = await this.loadConfig(path_1.default.join(this.templatesDir, framework));
|
|
21
21
|
configs.push(baseConfig);
|
|
22
22
|
// Copy base files
|
|
23
23
|
const baseFiles = await this.getBaseFiles(framework);
|
|
24
24
|
filesToCopy.push(...baseFiles);
|
|
25
25
|
// 2. Load database configuration if not "none"
|
|
26
|
-
if (database !==
|
|
27
|
-
const dbConfig = await this.loadConfig(path_1.default.join(this.templatesDir,
|
|
26
|
+
if (database !== "none") {
|
|
27
|
+
const dbConfig = await this.loadConfig(path_1.default.join(this.templatesDir, "databases", database));
|
|
28
28
|
// Check compatibility
|
|
29
29
|
if (dbConfig.compatibleWith?.frameworks &&
|
|
30
30
|
!dbConfig.compatibleWith.frameworks.includes(framework)) {
|
|
@@ -32,17 +32,17 @@ class TemplateComposer {
|
|
|
32
32
|
}
|
|
33
33
|
configs.push(dbConfig);
|
|
34
34
|
// Copy database files
|
|
35
|
-
const dbDir = path_1.default.join(this.templatesDir,
|
|
35
|
+
const dbDir = path_1.default.join(this.templatesDir, "databases", database);
|
|
36
36
|
const dbFiles = await this.collectFiles(dbDir);
|
|
37
37
|
filesToCopy.push(...dbFiles.map((f) => ({
|
|
38
38
|
source: f,
|
|
39
|
-
dest: path_1.default.join(targetDir, f.replace(dbDir + path_1.default.sep,
|
|
39
|
+
dest: path_1.default.join(targetDir, f.replace(dbDir + path_1.default.sep, "")),
|
|
40
40
|
})));
|
|
41
41
|
}
|
|
42
42
|
// 3. Load auth configuration if not "none"
|
|
43
|
-
if (auth !==
|
|
43
|
+
if (auth !== "none") {
|
|
44
44
|
const authKey = this.getAuthKey(framework, auth);
|
|
45
|
-
const authDir = path_1.default.join(this.templatesDir,
|
|
45
|
+
const authDir = path_1.default.join(this.templatesDir, "auth", authKey);
|
|
46
46
|
if (await fs_extra_1.default.pathExists(authDir)) {
|
|
47
47
|
const authConfig = await this.loadConfig(authDir);
|
|
48
48
|
// Check compatibility
|
|
@@ -59,7 +59,7 @@ class TemplateComposer {
|
|
|
59
59
|
const authFiles = await this.collectFiles(authDir);
|
|
60
60
|
filesToCopy.push(...authFiles.map((f) => ({
|
|
61
61
|
source: f,
|
|
62
|
-
dest: path_1.default.join(targetDir, f.replace(authDir + path_1.default.sep,
|
|
62
|
+
dest: path_1.default.join(targetDir, f.replace(authDir + path_1.default.sep, "")),
|
|
63
63
|
})));
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -73,8 +73,8 @@ class TemplateComposer {
|
|
|
73
73
|
await this.writeEnvFile(targetDir, mergedConfig);
|
|
74
74
|
}
|
|
75
75
|
async loadConfig(dir) {
|
|
76
|
-
const configPath = path_1.default.join(dir,
|
|
77
|
-
const templatePath = path_1.default.join(dir,
|
|
76
|
+
const configPath = path_1.default.join(dir, "config.json");
|
|
77
|
+
const templatePath = path_1.default.join(dir, "template.json");
|
|
78
78
|
if (await fs_extra_1.default.pathExists(configPath)) {
|
|
79
79
|
return await fs_extra_1.default.readJson(configPath);
|
|
80
80
|
}
|
|
@@ -86,14 +86,14 @@ class TemplateComposer {
|
|
|
86
86
|
async getBaseFiles(framework) {
|
|
87
87
|
// For now, use existing complete template
|
|
88
88
|
// In future, this will use minimal base templates
|
|
89
|
-
const baseDir = path_1.default.join(this.templatesDir,
|
|
89
|
+
const baseDir = path_1.default.join(this.templatesDir, "next-prisma-postgres-shadcn");
|
|
90
90
|
const files = await this.collectFiles(baseDir);
|
|
91
91
|
return files.map((source) => ({
|
|
92
92
|
source,
|
|
93
|
-
dest: source.replace(baseDir,
|
|
93
|
+
dest: source.replace(baseDir, ""),
|
|
94
94
|
}));
|
|
95
95
|
}
|
|
96
|
-
async collectFiles(dir, exclude = [
|
|
96
|
+
async collectFiles(dir, exclude = ["config.json", "template.json", "node_modules"]) {
|
|
97
97
|
const files = [];
|
|
98
98
|
if (!(await fs_extra_1.default.pathExists(dir))) {
|
|
99
99
|
return files;
|
|
@@ -143,7 +143,7 @@ class TemplateComposer {
|
|
|
143
143
|
}, {});
|
|
144
144
|
}
|
|
145
145
|
async writePackageJson(targetDir, config) {
|
|
146
|
-
const pkgPath = path_1.default.join(targetDir,
|
|
146
|
+
const pkgPath = path_1.default.join(targetDir, "package.json");
|
|
147
147
|
let pkg = {};
|
|
148
148
|
if (await fs_extra_1.default.pathExists(pkgPath)) {
|
|
149
149
|
pkg = await fs_extra_1.default.readJson(pkgPath);
|
|
@@ -164,16 +164,16 @@ class TemplateComposer {
|
|
|
164
164
|
if (!config.env || Object.keys(config.env).length === 0) {
|
|
165
165
|
return;
|
|
166
166
|
}
|
|
167
|
-
const envPath = path_1.default.join(targetDir,
|
|
168
|
-
const envExamplePath = path_1.default.join(targetDir,
|
|
167
|
+
const envPath = path_1.default.join(targetDir, ".env");
|
|
168
|
+
const envExamplePath = path_1.default.join(targetDir, ".env.example");
|
|
169
169
|
const envContent = Object.entries(config.env)
|
|
170
170
|
.map(([key, value]) => `${key}="${value}"`)
|
|
171
|
-
.join(
|
|
171
|
+
.join("\n") + "\n";
|
|
172
172
|
// Append or create .env.example
|
|
173
173
|
if (await fs_extra_1.default.pathExists(envExamplePath)) {
|
|
174
|
-
const existing = await fs_extra_1.default.readFile(envExamplePath,
|
|
174
|
+
const existing = await fs_extra_1.default.readFile(envExamplePath, "utf-8");
|
|
175
175
|
if (!existing.includes(envContent)) {
|
|
176
|
-
await fs_extra_1.default.appendFile(envExamplePath,
|
|
176
|
+
await fs_extra_1.default.appendFile(envExamplePath, "\n" + envContent);
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
else {
|
|
@@ -187,9 +187,9 @@ class TemplateComposer {
|
|
|
187
187
|
getAuthKey(framework, auth) {
|
|
188
188
|
// Map framework + auth to specific implementation
|
|
189
189
|
const mapping = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
190
|
+
"nextjs-nextauth": "nextauth",
|
|
191
|
+
"nextjs-better-auth": "better-auth-nextjs",
|
|
192
|
+
"express-better-auth": "better-auth-express",
|
|
193
193
|
};
|
|
194
194
|
return mapping[`${framework}-${auth}`] || auth;
|
|
195
195
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { betterAuth } from "better-auth";
|
|
2
|
+
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
|
3
|
+
import { client } from "./db";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: mongodbAdapter(client),
|
|
7
|
+
emailAndPassword: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export type Session = typeof auth.$Infer.Session;
|
|
13
|
+
export type User = typeof auth.$Infer.User;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { prismaAdapter } from "@better-auth/prisma";
|
|
2
|
+
import { betterAuth } from "better-auth";
|
|
3
|
+
import { prisma } from "./db";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: prismaAdapter(prisma, {
|
|
7
|
+
provider: "mongodb",
|
|
8
|
+
}),
|
|
9
|
+
emailAndPassword: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type Session = typeof auth.$Infer.Session;
|
|
15
|
+
export type User = typeof auth.$Infer.User;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { prismaAdapter } from "@better-auth/prisma";
|
|
2
|
+
import { betterAuth } from "better-auth";
|
|
3
|
+
import { prisma } from "./db";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: prismaAdapter(prisma, {
|
|
7
|
+
provider: "postgresql",
|
|
8
|
+
}),
|
|
9
|
+
emailAndPassword: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export type Session = typeof auth.$Infer.Session;
|
|
15
|
+
export type User = typeof auth.$Infer.User;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Router } from
|
|
2
|
-
import { auth } from
|
|
1
|
+
import { Router } from "express";
|
|
2
|
+
import { auth } from "../lib/auth";
|
|
3
3
|
|
|
4
4
|
const router = Router();
|
|
5
5
|
|
|
6
6
|
// Mount Better Auth handlers
|
|
7
|
-
router.all(
|
|
7
|
+
router.all("/auth/*", async (req, res) => {
|
|
8
8
|
const response = await auth.handler(req);
|
|
9
9
|
return res.status(response.status).json(response.body);
|
|
10
10
|
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "mongodb"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Better Auth models for MongoDB
|
|
11
|
+
model User {
|
|
12
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
13
|
+
name String
|
|
14
|
+
email String
|
|
15
|
+
emailVerified Boolean @default(false)
|
|
16
|
+
image String?
|
|
17
|
+
createdAt DateTime @default(now())
|
|
18
|
+
updatedAt DateTime @updatedAt
|
|
19
|
+
sessions Session[]
|
|
20
|
+
accounts Account[]
|
|
21
|
+
role String @default("USER")
|
|
22
|
+
|
|
23
|
+
@@unique([email])
|
|
24
|
+
@@map("user")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
model Session {
|
|
28
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
29
|
+
expiresAt DateTime
|
|
30
|
+
token String @unique
|
|
31
|
+
createdAt DateTime @default(now())
|
|
32
|
+
updatedAt DateTime @updatedAt
|
|
33
|
+
ipAddress String?
|
|
34
|
+
userAgent String?
|
|
35
|
+
userId String @db.ObjectId
|
|
36
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
37
|
+
|
|
38
|
+
@@index([userId])
|
|
39
|
+
@@map("session")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
model Account {
|
|
43
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
44
|
+
accountId String
|
|
45
|
+
providerId String
|
|
46
|
+
userId String @db.ObjectId
|
|
47
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
48
|
+
accessToken String?
|
|
49
|
+
refreshToken String?
|
|
50
|
+
idToken String?
|
|
51
|
+
accessTokenExpiresAt DateTime?
|
|
52
|
+
refreshTokenExpiresAt DateTime?
|
|
53
|
+
scope String?
|
|
54
|
+
password String?
|
|
55
|
+
createdAt DateTime @default(now())
|
|
56
|
+
updatedAt DateTime @updatedAt
|
|
57
|
+
|
|
58
|
+
@@index([userId])
|
|
59
|
+
@@map("account")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
model Verification {
|
|
63
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
64
|
+
identifier String
|
|
65
|
+
value String
|
|
66
|
+
expiresAt DateTime
|
|
67
|
+
createdAt DateTime @default(now())
|
|
68
|
+
updatedAt DateTime @updatedAt
|
|
69
|
+
|
|
70
|
+
@@index([identifier])
|
|
71
|
+
@@map("verification")
|
|
72
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "postgresql"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Better Auth models for PostgreSQL
|
|
11
|
+
model User {
|
|
12
|
+
id String @id @default(cuid())
|
|
13
|
+
name String
|
|
14
|
+
email String
|
|
15
|
+
emailVerified Boolean @default(false)
|
|
16
|
+
image String?
|
|
17
|
+
createdAt DateTime @default(now())
|
|
18
|
+
updatedAt DateTime @updatedAt
|
|
19
|
+
sessions Session[]
|
|
20
|
+
accounts Account[]
|
|
21
|
+
role String @default("USER")
|
|
22
|
+
|
|
23
|
+
@@unique([email])
|
|
24
|
+
@@map("user")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
model Session {
|
|
28
|
+
id String @id @default(cuid())
|
|
29
|
+
expiresAt DateTime
|
|
30
|
+
token String @unique
|
|
31
|
+
createdAt DateTime @default(now())
|
|
32
|
+
updatedAt DateTime @updatedAt
|
|
33
|
+
ipAddress String?
|
|
34
|
+
userAgent String?
|
|
35
|
+
userId String
|
|
36
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
37
|
+
|
|
38
|
+
@@index([userId])
|
|
39
|
+
@@map("session")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
model Account {
|
|
43
|
+
id String @id @default(cuid())
|
|
44
|
+
accountId String
|
|
45
|
+
providerId String
|
|
46
|
+
userId String
|
|
47
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
48
|
+
accessToken String?
|
|
49
|
+
refreshToken String?
|
|
50
|
+
idToken String?
|
|
51
|
+
accessTokenExpiresAt DateTime?
|
|
52
|
+
refreshTokenExpiresAt DateTime?
|
|
53
|
+
scope String?
|
|
54
|
+
password String?
|
|
55
|
+
createdAt DateTime @default(now())
|
|
56
|
+
updatedAt DateTime @updatedAt
|
|
57
|
+
|
|
58
|
+
@@index([userId])
|
|
59
|
+
@@map("account")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
model Verification {
|
|
63
|
+
id String @id @default(cuid())
|
|
64
|
+
identifier String
|
|
65
|
+
value String
|
|
66
|
+
expiresAt DateTime
|
|
67
|
+
createdAt DateTime @default(now())
|
|
68
|
+
updatedAt DateTime @updatedAt
|
|
69
|
+
|
|
70
|
+
@@index([identifier])
|
|
71
|
+
@@map("verification")
|
|
72
|
+
}
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "auth",
|
|
2
|
+
"name": "better-auth-express",
|
|
3
3
|
"displayName": "Better Auth (Express)",
|
|
4
4
|
"description": "Modern authentication with Better Auth for Express",
|
|
5
5
|
"category": "auth",
|
|
6
6
|
"supportedFrameworks": ["express"],
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"databaseAdapters": {
|
|
8
|
+
"prisma-postgresql": {
|
|
9
|
+
"adapter": "adapters/prisma-postgresql.ts",
|
|
10
|
+
"schema": "files/schemas/prisma-postgresql-schema.prisma",
|
|
11
|
+
"schemaDestination": "prisma/schema.prisma",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"better-auth": "^1.1.4",
|
|
14
|
+
"@better-auth/prisma": "^1.1.4"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"prisma-mongodb": {
|
|
18
|
+
"adapter": "adapters/prisma-mongodb.ts",
|
|
19
|
+
"schema": "files/schemas/prisma-mongodb-schema.prisma",
|
|
20
|
+
"schemaDestination": "prisma/schema.prisma",
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"better-auth": "^1.1.4",
|
|
23
|
+
"@better-auth/prisma": "^1.1.4"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"mongoose-mongodb": {
|
|
27
|
+
"adapter": "adapters/mongoose-mongodb.ts",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"better-auth": "^1.1.4"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
9
32
|
},
|
|
10
33
|
"envVars": [
|
|
11
34
|
{
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { client } from "@/lib/db";
|
|
2
|
+
import { betterAuth } from "better-auth";
|
|
3
|
+
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: mongodbAdapter(client),
|
|
7
|
+
emailAndPassword: {
|
|
8
|
+
enabled: true,
|
|
9
|
+
},
|
|
10
|
+
socialProviders: {
|
|
11
|
+
// Uncomment to add OAuth providers
|
|
12
|
+
// google: {
|
|
13
|
+
// clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
14
|
+
// clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
15
|
+
// },
|
|
16
|
+
// github: {
|
|
17
|
+
// clientId: process.env.GITHUB_CLIENT_ID!,
|
|
18
|
+
// clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
19
|
+
// },
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type Session = typeof auth.$Infer.Session;
|
|
24
|
+
export type User = typeof auth.$Infer.User;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { prisma } from "@/lib/db";
|
|
2
|
+
import { prismaAdapter } from "@better-auth/prisma";
|
|
3
|
+
import { betterAuth } from "better-auth";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: prismaAdapter(prisma, {
|
|
7
|
+
provider: "mongodb",
|
|
8
|
+
}),
|
|
9
|
+
emailAndPassword: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
},
|
|
12
|
+
socialProviders: {
|
|
13
|
+
// Uncomment to add OAuth providers
|
|
14
|
+
// google: {
|
|
15
|
+
// clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
16
|
+
// clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
17
|
+
// },
|
|
18
|
+
// github: {
|
|
19
|
+
// clientId: process.env.GITHUB_CLIENT_ID!,
|
|
20
|
+
// clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
21
|
+
// },
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Session = typeof auth.$Infer.Session;
|
|
26
|
+
export type User = typeof auth.$Infer.User;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { prisma } from "@/lib/db";
|
|
2
|
+
import { prismaAdapter } from "@better-auth/prisma";
|
|
3
|
+
import { betterAuth } from "better-auth";
|
|
4
|
+
|
|
5
|
+
export const auth = betterAuth({
|
|
6
|
+
database: prismaAdapter(prisma, {
|
|
7
|
+
provider: "postgresql",
|
|
8
|
+
}),
|
|
9
|
+
emailAndPassword: {
|
|
10
|
+
enabled: true,
|
|
11
|
+
},
|
|
12
|
+
socialProviders: {
|
|
13
|
+
// Uncomment to add OAuth providers
|
|
14
|
+
// google: {
|
|
15
|
+
// clientId: process.env.GOOGLE_CLIENT_ID!,
|
|
16
|
+
// clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
|
|
17
|
+
// },
|
|
18
|
+
// github: {
|
|
19
|
+
// clientId: process.env.GITHUB_CLIENT_ID!,
|
|
20
|
+
// clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
21
|
+
// },
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type Session = typeof auth.$Infer.Session;
|
|
26
|
+
export type User = typeof auth.$Infer.User;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { prismaAdapter } from
|
|
2
|
-
import { betterAuth } from
|
|
3
|
-
import { prisma } from
|
|
1
|
+
import { prismaAdapter } from "@better-auth/prisma";
|
|
2
|
+
import { betterAuth } from "better-auth";
|
|
3
|
+
import { prisma } from "./db";
|
|
4
4
|
|
|
5
5
|
export const auth = betterAuth({
|
|
6
6
|
database: prismaAdapter(prisma, {
|
|
7
|
-
provider:
|
|
7
|
+
provider: "postgresql", // Change to 'mongodb' if using MongoDB
|
|
8
8
|
}),
|
|
9
9
|
emailAndPassword: {
|
|
10
10
|
enabled: true,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "mongodb"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Better Auth models for MongoDB
|
|
11
|
+
model User {
|
|
12
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
13
|
+
name String
|
|
14
|
+
email String
|
|
15
|
+
emailVerified Boolean @default(false)
|
|
16
|
+
image String?
|
|
17
|
+
createdAt DateTime @default(now())
|
|
18
|
+
updatedAt DateTime @updatedAt
|
|
19
|
+
sessions Session[]
|
|
20
|
+
accounts Account[]
|
|
21
|
+
role String @default("USER")
|
|
22
|
+
|
|
23
|
+
@@unique([email])
|
|
24
|
+
@@map("user")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
model Session {
|
|
28
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
29
|
+
expiresAt DateTime
|
|
30
|
+
token String @unique
|
|
31
|
+
createdAt DateTime @default(now())
|
|
32
|
+
updatedAt DateTime @updatedAt
|
|
33
|
+
ipAddress String?
|
|
34
|
+
userAgent String?
|
|
35
|
+
userId String @db.ObjectId
|
|
36
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
37
|
+
|
|
38
|
+
@@index([userId])
|
|
39
|
+
@@map("session")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
model Account {
|
|
43
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
44
|
+
accountId String
|
|
45
|
+
providerId String
|
|
46
|
+
userId String @db.ObjectId
|
|
47
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
48
|
+
accessToken String?
|
|
49
|
+
refreshToken String?
|
|
50
|
+
idToken String?
|
|
51
|
+
accessTokenExpiresAt DateTime?
|
|
52
|
+
refreshTokenExpiresAt DateTime?
|
|
53
|
+
scope String?
|
|
54
|
+
password String?
|
|
55
|
+
createdAt DateTime @default(now())
|
|
56
|
+
updatedAt DateTime @updatedAt
|
|
57
|
+
|
|
58
|
+
@@index([userId])
|
|
59
|
+
@@map("account")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
model Verification {
|
|
63
|
+
id String @id @default(auto()) @map("_id") @db.ObjectId
|
|
64
|
+
identifier String
|
|
65
|
+
value String
|
|
66
|
+
expiresAt DateTime
|
|
67
|
+
createdAt DateTime @default(now())
|
|
68
|
+
updatedAt DateTime @updatedAt
|
|
69
|
+
|
|
70
|
+
@@index([identifier])
|
|
71
|
+
@@map("verification")
|
|
72
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "postgresql"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Better Auth models for PostgreSQL
|
|
11
|
+
model User {
|
|
12
|
+
id String @id @default(cuid())
|
|
13
|
+
name String
|
|
14
|
+
email String
|
|
15
|
+
emailVerified Boolean @default(false)
|
|
16
|
+
image String?
|
|
17
|
+
createdAt DateTime @default(now())
|
|
18
|
+
updatedAt DateTime @updatedAt
|
|
19
|
+
sessions Session[]
|
|
20
|
+
accounts Account[]
|
|
21
|
+
role String @default("USER")
|
|
22
|
+
|
|
23
|
+
@@unique([email])
|
|
24
|
+
@@map("user")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
model Session {
|
|
28
|
+
id String @id @default(cuid())
|
|
29
|
+
expiresAt DateTime
|
|
30
|
+
token String @unique
|
|
31
|
+
createdAt DateTime @default(now())
|
|
32
|
+
updatedAt DateTime @updatedAt
|
|
33
|
+
ipAddress String?
|
|
34
|
+
userAgent String?
|
|
35
|
+
userId String
|
|
36
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
37
|
+
|
|
38
|
+
@@index([userId])
|
|
39
|
+
@@map("session")
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
model Account {
|
|
43
|
+
id String @id @default(cuid())
|
|
44
|
+
accountId String
|
|
45
|
+
providerId String
|
|
46
|
+
userId String
|
|
47
|
+
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
48
|
+
accessToken String?
|
|
49
|
+
refreshToken String?
|
|
50
|
+
idToken String?
|
|
51
|
+
accessTokenExpiresAt DateTime?
|
|
52
|
+
refreshTokenExpiresAt DateTime?
|
|
53
|
+
scope String?
|
|
54
|
+
password String?
|
|
55
|
+
createdAt DateTime @default(now())
|
|
56
|
+
updatedAt DateTime @updatedAt
|
|
57
|
+
|
|
58
|
+
@@index([userId])
|
|
59
|
+
@@map("account")
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
model Verification {
|
|
63
|
+
id String @id @default(cuid())
|
|
64
|
+
identifier String
|
|
65
|
+
value String
|
|
66
|
+
expiresAt DateTime
|
|
67
|
+
createdAt DateTime @default(now())
|
|
68
|
+
updatedAt DateTime @updatedAt
|
|
69
|
+
|
|
70
|
+
@@index([identifier])
|
|
71
|
+
@@map("verification")
|
|
72
|
+
}
|
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "auth",
|
|
2
|
+
"name": "better-auth-nextjs",
|
|
3
3
|
"displayName": "Better Auth (Next.js)",
|
|
4
4
|
"description": "Modern authentication with Better Auth for Next.js App Router",
|
|
5
5
|
"category": "auth",
|
|
6
6
|
"provider": "better-auth",
|
|
7
7
|
"supportedFrameworks": ["nextjs"],
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
"databaseAdapters": {
|
|
9
|
+
"prisma-postgresql": {
|
|
10
|
+
"adapter": "adapters/prisma-postgresql.ts",
|
|
11
|
+
"schema": "files/schemas/prisma-postgresql-schema.prisma",
|
|
12
|
+
"schemaDestination": "prisma/schema.prisma",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"better-auth": "^1.1.4",
|
|
15
|
+
"@better-auth/prisma": "^1.1.4"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"prisma-mongodb": {
|
|
19
|
+
"adapter": "adapters/prisma-mongodb.ts",
|
|
20
|
+
"schema": "files/schemas/prisma-mongodb-schema.prisma",
|
|
21
|
+
"schemaDestination": "prisma/schema.prisma",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"better-auth": "^1.1.4",
|
|
24
|
+
"@better-auth/prisma": "^1.1.4"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"mongoose-mongodb": {
|
|
28
|
+
"adapter": "adapters/mongoose-mongodb.ts",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"better-auth": "^1.1.4"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
12
33
|
},
|
|
13
34
|
"envVars": [
|
|
14
35
|
{
|