stackkit-cli 0.4.3 → 0.4.5
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 +26 -2
- package/bin/stackkit.js +10 -1
- package/dist/commands/add.js +128 -10
- package/dist/commands/doctor.d.ts +11 -0
- package/dist/commands/doctor.js +483 -0
- package/dist/commands/list.d.ts +1 -1
- package/dist/commands/list.js +59 -38
- package/dist/index.js +11 -13
- package/dist/types/index.d.ts +29 -2
- package/dist/utils/config-utils.d.ts +2 -0
- package/dist/utils/config-utils.js +88 -0
- package/dist/utils/detect.js +12 -2
- package/dist/utils/env-editor.d.ts +0 -1
- package/dist/utils/env-editor.js +50 -25
- package/dist/utils/files.d.ts +8 -0
- package/dist/utils/files.js +51 -0
- package/dist/utils/js-conversion.d.ts +1 -0
- package/dist/utils/js-conversion.js +244 -0
- package/dist/utils/module-utils.d.ts +2 -0
- package/dist/utils/module-utils.js +461 -0
- package/dist/utils/package-manager.js +15 -31
- package/modules/auth/authjs/files/api/auth/[...nextauth]/route.ts +6 -0
- package/modules/auth/authjs/files/lib/auth-client.ts +11 -0
- package/modules/auth/authjs/files/lib/auth.ts +41 -0
- package/modules/auth/authjs/files/schemas/prisma-schema.prisma +45 -0
- package/modules/auth/authjs/module.json +95 -0
- package/modules/auth/better-auth/files/lib/auth-client.ts +7 -0
- package/modules/auth/better-auth/files/lib/auth.ts +75 -0
- package/modules/auth/better-auth/files/lib/email-service.ts +34 -0
- package/modules/auth/better-auth/files/lib/email-templates.ts +89 -0
- package/modules/auth/better-auth/files/schemas/prisma-schema.prisma +63 -0
- package/modules/auth/better-auth/module.json +191 -0
- package/modules/database/mongoose/files/lib/db.ts +68 -0
- package/modules/database/mongoose/files/models/User.ts +34 -0
- package/modules/database/mongoose/module.json +55 -0
- package/modules/database/prisma/files/lib/prisma.ts +4 -0
- package/modules/database/prisma/files/prisma/schema.prisma +8 -0
- package/modules/database/prisma/files/prisma.config.ts +12 -0
- package/modules/database/prisma/module.json +122 -0
- package/package.json +1 -1
- package/templates/express/.env.example +1 -10
- package/templates/express/package.json +15 -21
- package/templates/express/src/app.ts +9 -29
- package/templates/express/src/config/env.ts +3 -14
- package/templates/express/src/features/health/health.controller.ts +18 -0
- package/templates/express/src/features/health/health.route.ts +9 -0
- package/templates/express/src/features/health/health.service.ts +6 -0
- package/templates/express/src/middlewares/error.middleware.ts +2 -2
- package/templates/express/src/server.ts +1 -1
- package/templates/express/template.json +1 -5
- package/templates/express/tsconfig.json +0 -1
- package/templates/nextjs/lib/env.ts +8 -0
- package/templates/nextjs/package.json +7 -7
- package/templates/react-vite/.env.example +1 -2
- package/templates/react-vite/.prettierignore +4 -0
- package/templates/react-vite/.prettierrc +9 -0
- package/templates/react-vite/README.md +22 -0
- package/templates/react-vite/package.json +16 -16
- package/templates/react-vite/src/router.tsx +0 -12
- package/templates/react-vite/vite.config.ts +0 -6
- package/dist/commands/init.d.ts +0 -10
- package/dist/commands/init.js +0 -157
- package/dist/utils/code-inject.d.ts +0 -14
- package/dist/utils/code-inject.js +0 -70
- package/dist/utils/json-editor.d.ts +0 -8
- package/dist/utils/json-editor.js +0 -45
- package/modules/auth/better-auth-express/adapters/mongoose-mongodb.ts +0 -13
- package/modules/auth/better-auth-express/adapters/prisma-mongodb.ts +0 -15
- package/modules/auth/better-auth-express/adapters/prisma-postgresql.ts +0 -15
- package/modules/auth/better-auth-express/files/lib/auth.ts +0 -16
- package/modules/auth/better-auth-express/files/routes/auth.ts +0 -12
- package/modules/auth/better-auth-express/files/schemas/prisma-mongodb-schema.prisma +0 -72
- package/modules/auth/better-auth-express/files/schemas/prisma-postgresql-schema.prisma +0 -72
- package/modules/auth/better-auth-express/module.json +0 -61
- package/modules/auth/better-auth-nextjs/adapters/mongoose-mongodb.ts +0 -24
- package/modules/auth/better-auth-nextjs/adapters/prisma-mongodb.ts +0 -26
- package/modules/auth/better-auth-nextjs/adapters/prisma-postgresql.ts +0 -26
- package/modules/auth/better-auth-nextjs/files/lib/auth.ts +0 -26
- package/modules/auth/better-auth-nextjs/files/schemas/prisma-mongodb-schema.prisma +0 -72
- package/modules/auth/better-auth-nextjs/files/schemas/prisma-postgresql-schema.prisma +0 -72
- package/modules/auth/better-auth-nextjs/module.json +0 -62
- package/modules/auth/better-auth-react/files/lib/auth-client.ts +0 -9
- package/modules/auth/better-auth-react/module.json +0 -28
- package/modules/auth/clerk-express/files/lib/auth.ts +0 -7
- package/modules/auth/clerk-express/module.json +0 -34
- package/modules/auth/clerk-nextjs/files/lib/auth-provider.tsx +0 -5
- package/modules/auth/clerk-nextjs/files/middleware.ts +0 -9
- package/modules/auth/clerk-nextjs/module.json +0 -64
- package/modules/auth/clerk-react/files/lib/auth-provider.tsx +0 -15
- package/modules/auth/clerk-react/module.json +0 -28
- package/modules/database/mongoose-mongodb/files/lib/db.ts +0 -40
- package/modules/database/mongoose-mongodb/module.json +0 -55
- package/modules/database/prisma-mongodb/files/lib/db.ts +0 -9
- package/modules/database/prisma-mongodb/files/prisma/schema.prisma +0 -17
- package/modules/database/prisma-mongodb/module.json +0 -60
- package/modules/database/prisma-postgresql/files/lib/db.ts +0 -9
- package/modules/database/prisma-postgresql/files/prisma/schema.prisma +0 -17
- package/modules/database/prisma-postgresql/module.json +0 -60
- package/templates/react-vite/src/api/services/user.service.ts +0 -18
- package/templates/react-vite/src/pages/UserProfile.tsx +0 -40
- package/templates/react-vite/src/types/user.d.ts +0 -6
- /package/modules/auth/{better-auth-nextjs → better-auth}/files/api/auth/[...all]/route.ts +0 -0
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import tailwindcss from "@tailwindcss/vite";
|
|
2
2
|
import react from "@vitejs/plugin-react";
|
|
3
|
-
import path from "path";
|
|
4
3
|
import { defineConfig } from "vite";
|
|
5
4
|
|
|
6
5
|
export default defineConfig({
|
|
7
6
|
plugins: [react(), tailwindcss()],
|
|
8
|
-
resolve: {
|
|
9
|
-
alias: {
|
|
10
|
-
"@": path.resolve(__dirname, "./src"),
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
7
|
});
|
package/dist/commands/init.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PackageManager } from "../utils/package-manager";
|
|
2
|
-
interface InitOptions {
|
|
3
|
-
template?: string;
|
|
4
|
-
pm?: PackageManager;
|
|
5
|
-
install?: boolean;
|
|
6
|
-
git?: boolean;
|
|
7
|
-
yes?: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function initCommand(projectName: string | undefined, options: InitOptions): Promise<void>;
|
|
10
|
-
export {};
|
package/dist/commands/init.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.initCommand = initCommand;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
|
12
|
-
const files_1 = require("../utils/files");
|
|
13
|
-
const logger_1 = require("../utils/logger");
|
|
14
|
-
const package_manager_1 = require("../utils/package-manager");
|
|
15
|
-
async function initCommand(projectName, options) {
|
|
16
|
-
try {
|
|
17
|
-
// Validate package manager option
|
|
18
|
-
if (options.pm && !["npm", "yarn", "pnpm", "bun"].includes(options.pm)) {
|
|
19
|
-
logger_1.logger.error(`Invalid package manager: ${options.pm}. Use npm, yarn, pnpm, or bun.`);
|
|
20
|
-
process.exit(1);
|
|
21
|
-
}
|
|
22
|
-
// Get available templates
|
|
23
|
-
const templatesDir = path_1.default.join(__dirname, "..", "..", "templates");
|
|
24
|
-
const templates = await getAvailableTemplates(templatesDir);
|
|
25
|
-
if (templates.length === 0) {
|
|
26
|
-
logger_1.logger.error("No templates found");
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
29
|
-
// Prompt for project details if not using --yes
|
|
30
|
-
let answers;
|
|
31
|
-
if (options.yes) {
|
|
32
|
-
answers = {
|
|
33
|
-
projectName: projectName || "my-app",
|
|
34
|
-
template: options.template || templates[0].name,
|
|
35
|
-
packageManager: options.pm || "pnpm",
|
|
36
|
-
install: options.install !== false,
|
|
37
|
-
git: options.git !== false,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const prompted = await inquirer_1.default.prompt([
|
|
42
|
-
{
|
|
43
|
-
type: "input",
|
|
44
|
-
name: "projectName",
|
|
45
|
-
message: "Project name:",
|
|
46
|
-
default: projectName || "my-app",
|
|
47
|
-
when: !projectName,
|
|
48
|
-
validate: (input) => {
|
|
49
|
-
const validation = (0, validate_npm_package_name_1.default)(input);
|
|
50
|
-
if (!validation.validForNewPackages) {
|
|
51
|
-
return validation.errors?.[0] || "Invalid package name";
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
type: "list",
|
|
58
|
-
name: "template",
|
|
59
|
-
message: "Select a template:",
|
|
60
|
-
choices: templates.map((t) => ({
|
|
61
|
-
name: t.displayName,
|
|
62
|
-
value: t.name,
|
|
63
|
-
})),
|
|
64
|
-
when: !options.template,
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
type: "list",
|
|
68
|
-
name: "packageManager",
|
|
69
|
-
message: "Select a package manager:",
|
|
70
|
-
choices: [
|
|
71
|
-
{ name: "pnpm (recommended)", value: "pnpm" },
|
|
72
|
-
{ name: "npm", value: "npm" },
|
|
73
|
-
{ name: "yarn", value: "yarn" },
|
|
74
|
-
{ name: "bun", value: "bun" },
|
|
75
|
-
],
|
|
76
|
-
default: "pnpm",
|
|
77
|
-
when: !options.pm,
|
|
78
|
-
},
|
|
79
|
-
{
|
|
80
|
-
type: "confirm",
|
|
81
|
-
name: "install",
|
|
82
|
-
message: "Install dependencies?",
|
|
83
|
-
default: true,
|
|
84
|
-
when: options.install !== false,
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
type: "confirm",
|
|
88
|
-
name: "git",
|
|
89
|
-
message: "Initialize git repository?",
|
|
90
|
-
default: true,
|
|
91
|
-
when: options.git !== false,
|
|
92
|
-
},
|
|
93
|
-
]);
|
|
94
|
-
answers = {
|
|
95
|
-
projectName: projectName || prompted.projectName,
|
|
96
|
-
template: options.template || prompted.template,
|
|
97
|
-
packageManager: options.pm || prompted.packageManager,
|
|
98
|
-
install: options.install !== false && (prompted.install ?? true),
|
|
99
|
-
git: options.git !== false && (prompted.git ?? true),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const targetDir = path_1.default.join(process.cwd(), answers.projectName);
|
|
103
|
-
// Check if directory exists
|
|
104
|
-
if (await fs_extra_1.default.pathExists(targetDir)) {
|
|
105
|
-
logger_1.logger.error(`Directory "${answers.projectName}" already exists`);
|
|
106
|
-
logger_1.logger.info("Please choose a different name or remove the existing directory.");
|
|
107
|
-
process.exit(1);
|
|
108
|
-
}
|
|
109
|
-
// Validate template exists
|
|
110
|
-
const selectedTemplate = templates.find((t) => t.name === answers.template);
|
|
111
|
-
if (!selectedTemplate) {
|
|
112
|
-
logger_1.logger.error(`Template "${answers.template}" not found`);
|
|
113
|
-
process.exit(1);
|
|
114
|
-
}
|
|
115
|
-
logger_1.logger.newLine();
|
|
116
|
-
// Copy template
|
|
117
|
-
const templatePath = path_1.default.join(templatesDir, answers.template);
|
|
118
|
-
await (0, files_1.copyTemplate)(templatePath, targetDir, answers.projectName);
|
|
119
|
-
// Install dependencies
|
|
120
|
-
if (answers.install) {
|
|
121
|
-
await (0, package_manager_1.installDependencies)(targetDir, answers.packageManager);
|
|
122
|
-
}
|
|
123
|
-
// Initialize git
|
|
124
|
-
if (answers.git) {
|
|
125
|
-
await (0, package_manager_1.initGit)(targetDir);
|
|
126
|
-
}
|
|
127
|
-
logger_1.logger.newLine();
|
|
128
|
-
logger_1.logger.success(`Created ${chalk_1.default.bold(answers.projectName)}`);
|
|
129
|
-
logger_1.logger.newLine();
|
|
130
|
-
logger_1.logger.log(`Next steps:`);
|
|
131
|
-
logger_1.logger.log(` ${chalk_1.default.cyan("cd")} ${answers.projectName}`);
|
|
132
|
-
if (!answers.install) {
|
|
133
|
-
logger_1.logger.log(` ${chalk_1.default.cyan(answers.packageManager)} install`);
|
|
134
|
-
}
|
|
135
|
-
logger_1.logger.log(` ${chalk_1.default.cyan(answers.packageManager)} ${answers.packageManager === "npm" ? "run " : ""}dev`);
|
|
136
|
-
logger_1.logger.newLine();
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
logger_1.logger.error(`Failed to create project: ${error.message}`);
|
|
140
|
-
process.exit(1);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async function getAvailableTemplates(templatesDir) {
|
|
144
|
-
if (!(await fs_extra_1.default.pathExists(templatesDir))) {
|
|
145
|
-
return [];
|
|
146
|
-
}
|
|
147
|
-
const templateDirs = await fs_extra_1.default.readdir(templatesDir);
|
|
148
|
-
const templates = [];
|
|
149
|
-
for (const dir of templateDirs) {
|
|
150
|
-
const metadataPath = path_1.default.join(templatesDir, dir, "template.json");
|
|
151
|
-
if (await fs_extra_1.default.pathExists(metadataPath)) {
|
|
152
|
-
const metadata = await fs_extra_1.default.readJSON(metadataPath);
|
|
153
|
-
templates.push(metadata);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return templates;
|
|
157
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export interface CodeInjection {
|
|
2
|
-
id: string;
|
|
3
|
-
code: string;
|
|
4
|
-
description: string;
|
|
5
|
-
}
|
|
6
|
-
export declare function injectCode(filePath: string, injection: CodeInjection, position: "append" | "prepend" | {
|
|
7
|
-
after: string;
|
|
8
|
-
} | {
|
|
9
|
-
before: string;
|
|
10
|
-
}, options?: {
|
|
11
|
-
force?: boolean;
|
|
12
|
-
}): Promise<void>;
|
|
13
|
-
export declare function removeInjection(content: string, id: string): string;
|
|
14
|
-
export declare function hasInjection(content: string, id: string): boolean;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.injectCode = injectCode;
|
|
7
|
-
exports.removeInjection = removeInjection;
|
|
8
|
-
exports.hasInjection = hasInjection;
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
const CODE_MARKER_START = (id) => `// StackKit:${id}:start`;
|
|
11
|
-
const CODE_MARKER_END = (id) => `// StackKit:${id}:end`;
|
|
12
|
-
async function injectCode(filePath, injection, position, options = {}) {
|
|
13
|
-
if (!(await fs_extra_1.default.pathExists(filePath))) {
|
|
14
|
-
throw new Error(`File not found: ${filePath}`);
|
|
15
|
-
}
|
|
16
|
-
let content = await fs_extra_1.default.readFile(filePath, "utf-8");
|
|
17
|
-
// Check if already injected
|
|
18
|
-
const startMarker = CODE_MARKER_START(injection.id);
|
|
19
|
-
if (content.includes(startMarker) && !options.force) {
|
|
20
|
-
return; // Already injected, skip
|
|
21
|
-
}
|
|
22
|
-
// Remove old injection if force is true
|
|
23
|
-
if (options.force) {
|
|
24
|
-
content = removeInjection(content, injection.id);
|
|
25
|
-
}
|
|
26
|
-
// Prepare the code block with markers
|
|
27
|
-
const markedCode = `\n${startMarker}\n${injection.code}\n${CODE_MARKER_END(injection.id)}\n`;
|
|
28
|
-
// Inject based on position
|
|
29
|
-
if (position === "append") {
|
|
30
|
-
content += markedCode;
|
|
31
|
-
}
|
|
32
|
-
else if (position === "prepend") {
|
|
33
|
-
content = markedCode + content;
|
|
34
|
-
}
|
|
35
|
-
else if ("after" in position) {
|
|
36
|
-
const index = content.indexOf(position.after);
|
|
37
|
-
if (index === -1) {
|
|
38
|
-
throw new Error(`Could not find marker: ${position.after}`);
|
|
39
|
-
}
|
|
40
|
-
const insertPos = index + position.after.length;
|
|
41
|
-
content = content.slice(0, insertPos) + markedCode + content.slice(insertPos);
|
|
42
|
-
}
|
|
43
|
-
else if ("before" in position) {
|
|
44
|
-
const index = content.indexOf(position.before);
|
|
45
|
-
if (index === -1) {
|
|
46
|
-
throw new Error(`Could not find marker: ${position.before}`);
|
|
47
|
-
}
|
|
48
|
-
content = content.slice(0, index) + markedCode + content.slice(index);
|
|
49
|
-
}
|
|
50
|
-
await fs_extra_1.default.writeFile(filePath, content, "utf-8");
|
|
51
|
-
}
|
|
52
|
-
function removeInjection(content, id) {
|
|
53
|
-
const startMarker = CODE_MARKER_START(id);
|
|
54
|
-
const endMarker = CODE_MARKER_END(id);
|
|
55
|
-
const startIndex = content.indexOf(startMarker);
|
|
56
|
-
if (startIndex === -1) {
|
|
57
|
-
return content;
|
|
58
|
-
}
|
|
59
|
-
const endIndex = content.indexOf(endMarker, startIndex);
|
|
60
|
-
if (endIndex === -1) {
|
|
61
|
-
return content;
|
|
62
|
-
}
|
|
63
|
-
// Remove everything from start marker to end marker (inclusive)
|
|
64
|
-
const before = content.slice(0, startIndex);
|
|
65
|
-
const after = content.slice(endIndex + endMarker.length);
|
|
66
|
-
return before + after;
|
|
67
|
-
}
|
|
68
|
-
function hasInjection(content, id) {
|
|
69
|
-
return content.includes(CODE_MARKER_START(id));
|
|
70
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function modifyJson(filePath: string, modifier: (_json: Record<string, unknown>) => Record<string, unknown>, options?: {
|
|
2
|
-
create?: boolean;
|
|
3
|
-
force?: boolean;
|
|
4
|
-
}): Promise<void>;
|
|
5
|
-
export declare function addToPackageJson(filePath: string, section: "dependencies" | "devDependencies" | "scripts", additions: Record<string, string>): Promise<void>;
|
|
6
|
-
export declare function setJsonValue(filePath: string, path: string, value: unknown, options?: {
|
|
7
|
-
merge?: boolean;
|
|
8
|
-
}): Promise<void>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.modifyJson = modifyJson;
|
|
7
|
-
exports.addToPackageJson = addToPackageJson;
|
|
8
|
-
exports.setJsonValue = setJsonValue;
|
|
9
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
-
async function modifyJson(filePath, modifier, options = {}) {
|
|
11
|
-
const exists = await fs_extra_1.default.pathExists(filePath);
|
|
12
|
-
if (!exists && !options.create) {
|
|
13
|
-
throw new Error(`File not found: ${filePath}`);
|
|
14
|
-
}
|
|
15
|
-
const modified = modifier(exists ? await fs_extra_1.default.readJSON(filePath) : {});
|
|
16
|
-
await fs_extra_1.default.writeJSON(filePath, modified, { spaces: 2 });
|
|
17
|
-
}
|
|
18
|
-
async function addToPackageJson(filePath, section, additions) {
|
|
19
|
-
await modifyJson(filePath, (_json) => {
|
|
20
|
-
_json[section] = _json[section] || {};
|
|
21
|
-
Object.assign(_json[section], additions);
|
|
22
|
-
return _json;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
async function setJsonValue(filePath, path, value, options = {}) {
|
|
26
|
-
await modifyJson(filePath, (_json) => {
|
|
27
|
-
const keys = path.split(".");
|
|
28
|
-
let current = _json;
|
|
29
|
-
for (let i = 0; i < keys.length - 1; i++) {
|
|
30
|
-
const key = keys[i];
|
|
31
|
-
if (!current[key]) {
|
|
32
|
-
current[key] = {};
|
|
33
|
-
}
|
|
34
|
-
current = current[key];
|
|
35
|
-
}
|
|
36
|
-
const lastKey = keys[keys.length - 1];
|
|
37
|
-
if (options.merge && typeof current[lastKey] === "object" && typeof value === "object") {
|
|
38
|
-
current[lastKey] = { ...current[lastKey], ...value };
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
current[lastKey] = value;
|
|
42
|
-
}
|
|
43
|
-
return _json;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
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;
|
|
@@ -1,15 +0,0 @@
|
|
|
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;
|
|
@@ -1,15 +0,0 @@
|
|
|
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,16 +0,0 @@
|
|
|
1
|
-
import { betterAuth } from "better-auth";
|
|
2
|
-
|
|
3
|
-
export const auth = betterAuth({
|
|
4
|
-
secret: process.env.BETTER_AUTH_SECRET!,
|
|
5
|
-
baseURL: process.env.BETTER_AUTH_URL!,
|
|
6
|
-
|
|
7
|
-
emailAndPassword: {
|
|
8
|
-
enabled: true,
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
// Uncomment to add database adapter
|
|
12
|
-
// database: {
|
|
13
|
-
// provider: "pg", // or "mongodb", "mysql"
|
|
14
|
-
// url: process.env.DATABASE_URL!,
|
|
15
|
-
// },
|
|
16
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Router } from "express";
|
|
2
|
-
import { auth } from "../lib/auth";
|
|
3
|
-
|
|
4
|
-
const router = Router();
|
|
5
|
-
|
|
6
|
-
// Mount Better Auth handlers
|
|
7
|
-
router.all("/auth/*", async (req, res) => {
|
|
8
|
-
const response = await auth.handler(req);
|
|
9
|
-
return res.status(response.status).json(response.body);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
export default router;
|
|
@@ -1,72 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
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,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "better-auth-express",
|
|
3
|
-
"displayName": "Better Auth (Express)",
|
|
4
|
-
"description": "Modern authentication with Better Auth for Express",
|
|
5
|
-
"category": "auth",
|
|
6
|
-
"supportedFrameworks": ["express"],
|
|
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
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"envVars": [
|
|
34
|
-
{
|
|
35
|
-
"key": "BETTER_AUTH_SECRET",
|
|
36
|
-
"value": "",
|
|
37
|
-
"description": "Secret key for Better Auth. Generate with: openssl rand -base64 32",
|
|
38
|
-
"required": true
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
"key": "BETTER_AUTH_URL",
|
|
42
|
-
"value": "http://localhost:3000",
|
|
43
|
-
"description": "Base URL of your application (change in production)",
|
|
44
|
-
"required": true
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
"patches": [
|
|
48
|
-
{
|
|
49
|
-
"type": "create-file",
|
|
50
|
-
"description": "Create Better Auth configuration",
|
|
51
|
-
"source": "lib/auth.ts",
|
|
52
|
-
"destination": "src/lib/auth.ts"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"type": "create-file",
|
|
56
|
-
"description": "Create auth routes",
|
|
57
|
-
"source": "routes/auth.ts",
|
|
58
|
-
"destination": "src/routes/auth.ts"
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
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;
|
|
@@ -1,26 +0,0 @@
|
|
|
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;
|