authverse 1.0.4
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 +90 -0
- package/dist/index.cjs +827 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +799 -0
- package/dist/template/api/route.ts +4 -0
- package/dist/template/app-auth-uiDesign/forget/page.tsx +7 -0
- package/dist/template/app-auth-uiDesign/layout.tsx +9 -0
- package/dist/template/app-auth-uiDesign/login/page.tsx +7 -0
- package/dist/template/app-auth-uiDesign/reset-password/page.tsx +7 -0
- package/dist/template/app-auth-uiDesign/signup/page.tsx +7 -0
- package/dist/template/components/ForgetComponent.tsx +121 -0
- package/dist/template/components/GithubProviders.tsx +21 -0
- package/dist/template/components/GoogleProviders.tsx +21 -0
- package/dist/template/components/LoginComponent.tsx +145 -0
- package/dist/template/components/Logout.tsx +21 -0
- package/dist/template/components/ResetComponent.tsx +150 -0
- package/dist/template/components/SingUpComponent.tsx +173 -0
- package/dist/template/config/drizzle.config.ts +13 -0
- package/dist/template/config/prisma.config.ts +12 -0
- package/dist/template/db/drizzle.ts +6 -0
- package/dist/template/db/schema.ts +68 -0
- package/dist/template/email/reset-password.tsx +132 -0
- package/dist/template/lib/Mongodb/auth.ts +20 -0
- package/dist/template/lib/Mysql/auth.ts +27 -0
- package/dist/template/lib/Postgresql/auth.ts +20 -0
- package/dist/template/lib/auth-client.ts +5 -0
- package/dist/template/lib/auth-drizzle.ts +16 -0
- package/dist/template/prisma/mongodb/schema.prisma +70 -0
- package/dist/template/prisma/mysql/schema.prisma +68 -0
- package/dist/template/prisma/postgresql/schema.prisma +68 -0
- package/dist/template/proxy/proxy.ts +15 -0
- package/dist/template/server/user.ts +49 -0
- package/package.json +62 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
|
|
25
|
+
// index.ts
|
|
26
|
+
var import_commander = require("commander");
|
|
27
|
+
|
|
28
|
+
// cli/init.ts
|
|
29
|
+
var import_inquirer = __toESM(require("inquirer"), 1);
|
|
30
|
+
|
|
31
|
+
// script/prisma.ts
|
|
32
|
+
var import_url2 = require("url");
|
|
33
|
+
var import_path2 = __toESM(require("path"), 1);
|
|
34
|
+
var import_fs2 = __toESM(require("fs"), 1);
|
|
35
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
36
|
+
var import_child_process2 = require("child_process");
|
|
37
|
+
|
|
38
|
+
// function/GenerateSecret.ts
|
|
39
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
40
|
+
var GenerateSecret = async () => {
|
|
41
|
+
const secret = import_crypto.default.randomBytes(64).toString("hex");
|
|
42
|
+
return secret;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// script/authUi.ts
|
|
46
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
47
|
+
var import_child_process = require("child_process");
|
|
48
|
+
var import_path = __toESM(require("path"), 1);
|
|
49
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
50
|
+
var import_url = require("url");
|
|
51
|
+
var import_meta = {};
|
|
52
|
+
var authUiRun = async ({ folder }) => {
|
|
53
|
+
try {
|
|
54
|
+
console.log(import_chalk.default.yellow("\n Updating AuthUi Files\n"));
|
|
55
|
+
(0, import_child_process.execSync)("npx shadcn@latest add button sonner card field input", {
|
|
56
|
+
stdio: "inherit"
|
|
57
|
+
});
|
|
58
|
+
(0, import_child_process.execSync)("npm install react-hook-form @hookform/resolvers", {
|
|
59
|
+
stdio: "inherit"
|
|
60
|
+
});
|
|
61
|
+
const __filename = (0, import_url.fileURLToPath)(import_meta.url);
|
|
62
|
+
const __dirname = import_path.default.dirname(__filename);
|
|
63
|
+
const projectDir = process.cwd();
|
|
64
|
+
const componentPath = import_path.default.resolve(__dirname, "./template/components");
|
|
65
|
+
const destinationPath = import_path.default.join(
|
|
66
|
+
projectDir,
|
|
67
|
+
folder,
|
|
68
|
+
"components",
|
|
69
|
+
"authverse"
|
|
70
|
+
);
|
|
71
|
+
if (!import_fs.default.existsSync(destinationPath)) {
|
|
72
|
+
import_fs.default.mkdirSync(destinationPath, { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
const LoginDestinationPath = import_path.default.join(
|
|
75
|
+
destinationPath,
|
|
76
|
+
"LoginComponent.tsx"
|
|
77
|
+
);
|
|
78
|
+
import_fs.default.copyFileSync(
|
|
79
|
+
`${componentPath}/LoginComponent.tsx`,
|
|
80
|
+
LoginDestinationPath
|
|
81
|
+
);
|
|
82
|
+
const SignUpDestinationPath = import_path.default.join(
|
|
83
|
+
destinationPath,
|
|
84
|
+
"SingUpComponent.tsx"
|
|
85
|
+
);
|
|
86
|
+
import_fs.default.copyFileSync(
|
|
87
|
+
`${componentPath}/SingUpComponent.tsx`,
|
|
88
|
+
SignUpDestinationPath
|
|
89
|
+
);
|
|
90
|
+
const LogoutDestinationPath = import_path.default.join(destinationPath, "Logout.tsx");
|
|
91
|
+
import_fs.default.copyFileSync(`${componentPath}/Logout.tsx`, LogoutDestinationPath);
|
|
92
|
+
const authTemplatePath = import_path.default.resolve(
|
|
93
|
+
__dirname,
|
|
94
|
+
"./template/app-auth-uiDesign"
|
|
95
|
+
);
|
|
96
|
+
const appDestinationPath = import_path.default.join(projectDir, folder, "app", "auth");
|
|
97
|
+
if (!import_fs.default.existsSync(appDestinationPath)) {
|
|
98
|
+
import_fs.default.mkdirSync(appDestinationPath, { recursive: true });
|
|
99
|
+
}
|
|
100
|
+
const layoutDestinationPath = import_path.default.join(appDestinationPath, "layout.tsx");
|
|
101
|
+
import_fs.default.copyFileSync(`${authTemplatePath}/layout.tsx`, layoutDestinationPath);
|
|
102
|
+
const loginDestinationDir = import_path.default.join(appDestinationPath, "login");
|
|
103
|
+
if (!import_fs.default.existsSync(loginDestinationDir)) {
|
|
104
|
+
import_fs.default.mkdirSync(loginDestinationDir, { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
const loginPageDestinationPath = import_path.default.join(loginDestinationDir, "page.tsx");
|
|
107
|
+
import_fs.default.copyFileSync(
|
|
108
|
+
`${authTemplatePath}/login/page.tsx`,
|
|
109
|
+
loginPageDestinationPath
|
|
110
|
+
);
|
|
111
|
+
const signUpDestinationDir = import_path.default.join(appDestinationPath, "signup");
|
|
112
|
+
if (!import_fs.default.existsSync(signUpDestinationDir)) {
|
|
113
|
+
import_fs.default.mkdirSync(signUpDestinationDir, { recursive: true });
|
|
114
|
+
}
|
|
115
|
+
const signUpPageDestinationPath = import_path.default.join(
|
|
116
|
+
signUpDestinationDir,
|
|
117
|
+
"page.tsx"
|
|
118
|
+
);
|
|
119
|
+
import_fs.default.copyFileSync(
|
|
120
|
+
`${authTemplatePath}/signup/page.tsx`,
|
|
121
|
+
signUpPageDestinationPath
|
|
122
|
+
);
|
|
123
|
+
const layoutPath = import_path.default.join(projectDir, folder, "app", "layout.tsx");
|
|
124
|
+
if (import_fs.default.existsSync(layoutPath)) {
|
|
125
|
+
let layoutContent = import_fs.default.readFileSync(layoutPath, "utf-8");
|
|
126
|
+
if (!layoutContent.includes("Toaster")) {
|
|
127
|
+
layoutContent = `import { Toaster } from "@/components/ui/sonner";
|
|
128
|
+
${layoutContent}`;
|
|
129
|
+
}
|
|
130
|
+
if (!layoutContent.includes("<Toaster")) {
|
|
131
|
+
layoutContent = layoutContent.replace(
|
|
132
|
+
/<\/body>/,
|
|
133
|
+
" <Toaster />\n </body>"
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
import_fs.default.writeFileSync(layoutPath, layoutContent, "utf-8");
|
|
137
|
+
}
|
|
138
|
+
console.log(import_chalk.default.green("\nSetup completed!\n"));
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.log(import_chalk.default.red("\nauthUi setup failed:"), error);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// script/prisma.ts
|
|
145
|
+
var import_meta2 = {};
|
|
146
|
+
var prismaRun = async ({ authUi, database }) => {
|
|
147
|
+
try {
|
|
148
|
+
console.log(import_chalk2.default.cyan("\n\u2699\uFE0F Initializing Prisma...\n"));
|
|
149
|
+
if (database !== "Mongodb") {
|
|
150
|
+
(0, import_child_process2.execSync)("npm install prisma --save-dev", { stdio: "inherit" });
|
|
151
|
+
(0, import_child_process2.execSync)("npm install @prisma/client", { stdio: "inherit" });
|
|
152
|
+
if (database === "Mysql") {
|
|
153
|
+
(0, import_child_process2.execSync)("npm install @prisma/adapter-mariadb", { stdio: "inherit" });
|
|
154
|
+
}
|
|
155
|
+
if (database === "Postgresql") {
|
|
156
|
+
(0, import_child_process2.execSync)("npm install @prisma/adapter-pg", { stdio: "inherit" });
|
|
157
|
+
}
|
|
158
|
+
} else if (database === "Mongodb") {
|
|
159
|
+
(0, import_child_process2.execSync)("npm install prisma@6.19.0 --save-dev", { stdio: "inherit" });
|
|
160
|
+
(0, import_child_process2.execSync)("npm install @prisma/client@6.19.0", { stdio: "inherit" });
|
|
161
|
+
}
|
|
162
|
+
const projectDir = process.cwd();
|
|
163
|
+
const prismaDir = import_path2.default.join(projectDir, "prisma");
|
|
164
|
+
if (!import_fs2.default.existsSync(prismaDir)) {
|
|
165
|
+
console.log(import_chalk2.default.yellow("\n\u2699\uFE0F Initializing Prisma...\n"));
|
|
166
|
+
(0, import_child_process2.execSync)("npx prisma init", { stdio: "inherit" });
|
|
167
|
+
}
|
|
168
|
+
const __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
|
|
169
|
+
const __dirname = import_path2.default.dirname(__filename);
|
|
170
|
+
const templatePath = import_path2.default.resolve(
|
|
171
|
+
__dirname,
|
|
172
|
+
`./template/prisma/${database}/schema.prisma`
|
|
173
|
+
);
|
|
174
|
+
if (!import_fs2.default.existsSync(prismaDir)) {
|
|
175
|
+
import_fs2.default.mkdirSync(prismaDir, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
const destinationPath = import_path2.default.join(prismaDir, "schema.prisma");
|
|
178
|
+
import_fs2.default.copyFileSync(templatePath, destinationPath);
|
|
179
|
+
if (database === "Mongodb") {
|
|
180
|
+
const prismaConfigPath = import_path2.default.resolve(
|
|
181
|
+
__dirname,
|
|
182
|
+
`./template/config/prisma.config.ts`
|
|
183
|
+
);
|
|
184
|
+
const prismaConfigDestinationPath = import_path2.default.join("", "prisma.config.ts");
|
|
185
|
+
import_fs2.default.copyFileSync(prismaConfigPath, prismaConfigDestinationPath);
|
|
186
|
+
}
|
|
187
|
+
console.log(import_chalk2.default.yellow("\n\u2699\uFE0F Initializing better-auth...\n"));
|
|
188
|
+
(0, import_child_process2.execSync)("npm install better-auth", { stdio: "inherit" });
|
|
189
|
+
const secret = await GenerateSecret();
|
|
190
|
+
const envPath = import_path2.default.join(projectDir, ".env");
|
|
191
|
+
import_fs2.default.appendFileSync(envPath, `
|
|
192
|
+
|
|
193
|
+
BETTER_AUTH_SECRET=${secret}`);
|
|
194
|
+
import_fs2.default.appendFileSync(envPath, `
|
|
195
|
+
BETTER_AUTH_URL=http://localhost:3000
|
|
196
|
+
`);
|
|
197
|
+
console.log(import_chalk2.default.yellow("\n create folder...\n"));
|
|
198
|
+
const srcPath = import_path2.default.join(projectDir, "src");
|
|
199
|
+
const folder = srcPath ? "" : "src";
|
|
200
|
+
const libPath = import_path2.default.join(projectDir, folder, "lib");
|
|
201
|
+
if (!import_fs2.default.existsSync(libPath)) {
|
|
202
|
+
import_fs2.default.mkdirSync(libPath, { recursive: true });
|
|
203
|
+
}
|
|
204
|
+
const authTemplatePath = import_path2.default.resolve(
|
|
205
|
+
__dirname,
|
|
206
|
+
`./template/lib/${database}/auth.ts`
|
|
207
|
+
);
|
|
208
|
+
const authDestinationPath = import_path2.default.join(libPath, "auth.ts");
|
|
209
|
+
import_fs2.default.copyFileSync(authTemplatePath, authDestinationPath);
|
|
210
|
+
const authClientTemplatePath = import_path2.default.resolve(
|
|
211
|
+
__dirname,
|
|
212
|
+
"./template/lib/auth-client.ts"
|
|
213
|
+
);
|
|
214
|
+
const authClientDestinationPath = import_path2.default.join(libPath, "auth-client.ts");
|
|
215
|
+
import_fs2.default.copyFileSync(authClientTemplatePath, authClientDestinationPath);
|
|
216
|
+
const serverPath = import_path2.default.join(projectDir, folder, "server");
|
|
217
|
+
if (!import_fs2.default.existsSync(serverPath)) {
|
|
218
|
+
import_fs2.default.mkdirSync(serverPath, { recursive: true });
|
|
219
|
+
}
|
|
220
|
+
const userTemplatePath = import_path2.default.resolve(
|
|
221
|
+
__dirname,
|
|
222
|
+
"./template/server/user.ts"
|
|
223
|
+
);
|
|
224
|
+
const userDestinationPath = import_path2.default.join(serverPath, "user.ts");
|
|
225
|
+
import_fs2.default.copyFileSync(userTemplatePath, userDestinationPath);
|
|
226
|
+
const routeTemplatePath = import_path2.default.resolve(
|
|
227
|
+
__dirname,
|
|
228
|
+
"./template/api/route.ts"
|
|
229
|
+
);
|
|
230
|
+
const routeDestinationDir = import_path2.default.join(
|
|
231
|
+
projectDir,
|
|
232
|
+
"app",
|
|
233
|
+
"api",
|
|
234
|
+
"auth",
|
|
235
|
+
"[...all]"
|
|
236
|
+
);
|
|
237
|
+
if (!import_fs2.default.existsSync(routeDestinationDir)) {
|
|
238
|
+
import_fs2.default.mkdirSync(routeDestinationDir, { recursive: true });
|
|
239
|
+
}
|
|
240
|
+
const routeDestinationPath = import_path2.default.join(routeDestinationDir, "route.ts");
|
|
241
|
+
import_fs2.default.copyFileSync(routeTemplatePath, routeDestinationPath);
|
|
242
|
+
const proxyTemplatePath = import_path2.default.resolve(
|
|
243
|
+
__dirname,
|
|
244
|
+
"./template/proxy/proxy.ts"
|
|
245
|
+
);
|
|
246
|
+
const proxyDestinationDir = import_path2.default.join(projectDir, folder);
|
|
247
|
+
const proxyDestinationPath = import_path2.default.join(proxyDestinationDir, "proxy.ts");
|
|
248
|
+
import_fs2.default.copyFileSync(proxyTemplatePath, proxyDestinationPath);
|
|
249
|
+
if (authUi) {
|
|
250
|
+
await authUiRun({ folder });
|
|
251
|
+
} else {
|
|
252
|
+
console.log(
|
|
253
|
+
import_chalk2.default.green(
|
|
254
|
+
"\nPrisma setup completed successfully and better-auth installed\n"
|
|
255
|
+
)
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
} catch (err) {
|
|
259
|
+
console.error(import_chalk2.default.red("Prisma setup failed:"), err);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// script/drizzleRun.ts
|
|
264
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
265
|
+
var import_child_process3 = require("child_process");
|
|
266
|
+
var import_path3 = __toESM(require("path"), 1);
|
|
267
|
+
var import_url3 = require("url");
|
|
268
|
+
var import_fs3 = __toESM(require("fs"), 1);
|
|
269
|
+
var import_meta3 = {};
|
|
270
|
+
var drizzleRun = async (authUi) => {
|
|
271
|
+
try {
|
|
272
|
+
console.log(import_chalk3.default.cyan("\n\u2699\uFE0F Initializing better auth and drizzle...\n"));
|
|
273
|
+
(0, import_child_process3.execSync)("npm install better-auth", { stdio: "inherit" });
|
|
274
|
+
(0, import_child_process3.execSync)("npm install drizzle-orm @neondatabase/serverless dotenv", {
|
|
275
|
+
stdio: "inherit"
|
|
276
|
+
});
|
|
277
|
+
(0, import_child_process3.execSync)("npm install -D drizzle-kit", { stdio: "inherit" });
|
|
278
|
+
const __filename = (0, import_url3.fileURLToPath)(import_meta3.url);
|
|
279
|
+
const __dirname = import_path3.default.dirname(__filename);
|
|
280
|
+
const projectDir = process.cwd();
|
|
281
|
+
const envPath = import_path3.default.join(projectDir, ".env");
|
|
282
|
+
if (!import_fs3.default.existsSync(envPath)) {
|
|
283
|
+
import_fs3.default.writeFileSync(envPath, "DATABASE_URL=\n");
|
|
284
|
+
}
|
|
285
|
+
const secret = await GenerateSecret();
|
|
286
|
+
import_fs3.default.appendFileSync(envPath, `
|
|
287
|
+
|
|
288
|
+
BETTER_AUTH_SECRET=${secret}`);
|
|
289
|
+
import_fs3.default.appendFileSync(envPath, `
|
|
290
|
+
BETTER_AUTH_URL=http://localhost:3000
|
|
291
|
+
`);
|
|
292
|
+
const srcPath = import_path3.default.join(projectDir, "src");
|
|
293
|
+
const folder = srcPath ? "" : "src";
|
|
294
|
+
const libPath = import_path3.default.join(projectDir, folder, "lib");
|
|
295
|
+
if (!import_fs3.default.existsSync(libPath)) {
|
|
296
|
+
import_fs3.default.mkdirSync(libPath, { recursive: true });
|
|
297
|
+
}
|
|
298
|
+
const authTemplatePath = import_path3.default.resolve(
|
|
299
|
+
__dirname,
|
|
300
|
+
"./template/lib/auth-drizzle.ts"
|
|
301
|
+
);
|
|
302
|
+
const authDestinationPath = import_path3.default.join(libPath, "auth.ts");
|
|
303
|
+
import_fs3.default.copyFileSync(authTemplatePath, authDestinationPath);
|
|
304
|
+
const authClientTemplatePath = import_path3.default.resolve(
|
|
305
|
+
__dirname,
|
|
306
|
+
"./template/lib/auth-client.ts"
|
|
307
|
+
);
|
|
308
|
+
const authClientDestinationPath = import_path3.default.join(libPath, "auth-client.ts");
|
|
309
|
+
import_fs3.default.copyFileSync(authClientTemplatePath, authClientDestinationPath);
|
|
310
|
+
const dbTemplatePath = import_path3.default.resolve(__dirname, "./template/db");
|
|
311
|
+
const dbDir = import_path3.default.join(projectDir, folder, "db");
|
|
312
|
+
if (!import_fs3.default.existsSync(dbDir)) {
|
|
313
|
+
import_fs3.default.mkdirSync(dbDir, { recursive: true });
|
|
314
|
+
}
|
|
315
|
+
const dbDestinationPath = import_path3.default.join(dbDir, "drizzle.ts");
|
|
316
|
+
import_fs3.default.copyFileSync(`${dbTemplatePath}/drizzle.ts`, dbDestinationPath);
|
|
317
|
+
const schemaDestinationPath = import_path3.default.join(dbDir, "schema.ts");
|
|
318
|
+
import_fs3.default.copyFileSync(`${dbTemplatePath}/schema.ts`, schemaDestinationPath);
|
|
319
|
+
const drizzleConfigTemplatePath = import_path3.default.resolve(
|
|
320
|
+
__dirname,
|
|
321
|
+
"./template/config/drizzle.config.ts"
|
|
322
|
+
);
|
|
323
|
+
const drizzleConfigDestinationPath = import_path3.default.join(
|
|
324
|
+
projectDir,
|
|
325
|
+
"drizzle.config.ts"
|
|
326
|
+
);
|
|
327
|
+
import_fs3.default.copyFileSync(drizzleConfigTemplatePath, drizzleConfigDestinationPath);
|
|
328
|
+
const serverPath = import_path3.default.join(projectDir, folder, "server");
|
|
329
|
+
if (!import_fs3.default.existsSync(serverPath)) {
|
|
330
|
+
import_fs3.default.mkdirSync(serverPath, { recursive: true });
|
|
331
|
+
}
|
|
332
|
+
const userTemplatePath = import_path3.default.resolve(
|
|
333
|
+
__dirname,
|
|
334
|
+
"./template/server/user.ts"
|
|
335
|
+
);
|
|
336
|
+
const userDestinationPath = import_path3.default.join(serverPath, "user.ts");
|
|
337
|
+
import_fs3.default.copyFileSync(userTemplatePath, userDestinationPath);
|
|
338
|
+
const routeTemplatePath = import_path3.default.resolve(
|
|
339
|
+
__dirname,
|
|
340
|
+
"./template/api/route.ts"
|
|
341
|
+
);
|
|
342
|
+
const routeDestinationDir = import_path3.default.join(
|
|
343
|
+
projectDir,
|
|
344
|
+
"app",
|
|
345
|
+
"api",
|
|
346
|
+
"auth",
|
|
347
|
+
"[...all]"
|
|
348
|
+
);
|
|
349
|
+
if (!import_fs3.default.existsSync(routeDestinationDir)) {
|
|
350
|
+
import_fs3.default.mkdirSync(routeDestinationDir, { recursive: true });
|
|
351
|
+
}
|
|
352
|
+
const routeDestinationPath = import_path3.default.join(routeDestinationDir, "route.ts");
|
|
353
|
+
import_fs3.default.copyFileSync(routeTemplatePath, routeDestinationPath);
|
|
354
|
+
const proxyTemplatePath = import_path3.default.resolve(
|
|
355
|
+
__dirname,
|
|
356
|
+
"./template/proxy/proxy.ts"
|
|
357
|
+
);
|
|
358
|
+
const proxyDestinationDir = import_path3.default.join(projectDir, folder);
|
|
359
|
+
const proxyDestinationPath = import_path3.default.join(proxyDestinationDir, "proxy.ts");
|
|
360
|
+
import_fs3.default.copyFileSync(proxyTemplatePath, proxyDestinationPath);
|
|
361
|
+
if (authUi) {
|
|
362
|
+
await authUiRun({ folder });
|
|
363
|
+
} else {
|
|
364
|
+
console.log(
|
|
365
|
+
import_chalk3.default.green(
|
|
366
|
+
"\nDrizzle setup completed successfully and better-auth installed\n"
|
|
367
|
+
)
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
} catch (err) {
|
|
371
|
+
console.error(import_chalk3.default.red("Drizzle setup failed:"), err);
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
// cli/init.ts
|
|
376
|
+
var initAnswer = async () => {
|
|
377
|
+
const answers = await import_inquirer.default.prompt([
|
|
378
|
+
{
|
|
379
|
+
type: "list",
|
|
380
|
+
name: "orm",
|
|
381
|
+
message: "Choose Your ORM:",
|
|
382
|
+
choices: ["Prisma", "Drizzle"]
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
type: "list",
|
|
386
|
+
name: "database",
|
|
387
|
+
message: "Select Database:",
|
|
388
|
+
choices: ["Postgresql", "Mongodb", "Mysql"],
|
|
389
|
+
when: (ans) => ans.orm === "Prisma"
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
type: "confirm",
|
|
393
|
+
name: "authUi",
|
|
394
|
+
message: "Do you want to include auth UI design?",
|
|
395
|
+
default: true
|
|
396
|
+
}
|
|
397
|
+
]);
|
|
398
|
+
if (answers.orm === "Prisma") {
|
|
399
|
+
await prismaRun({
|
|
400
|
+
authUi: answers.authUi,
|
|
401
|
+
database: answers.database
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
if (answers.orm === "Drizzle") {
|
|
405
|
+
await drizzleRun(answers.authUi);
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// index.ts
|
|
410
|
+
var import_fs8 = require("fs");
|
|
411
|
+
|
|
412
|
+
// cli/provider.ts
|
|
413
|
+
var import_chalk6 = __toESM(require("chalk"), 1);
|
|
414
|
+
|
|
415
|
+
// script/googleRun.ts
|
|
416
|
+
var import_chalk4 = __toESM(require("chalk"), 1);
|
|
417
|
+
var import_child_process4 = require("child_process");
|
|
418
|
+
var import_fs4 = __toESM(require("fs"), 1);
|
|
419
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
420
|
+
var import_url4 = require("url");
|
|
421
|
+
var import_meta4 = {};
|
|
422
|
+
var googleRun = async () => {
|
|
423
|
+
try {
|
|
424
|
+
(0, import_child_process4.execSync)("npm install react-icons --save", { stdio: "inherit" });
|
|
425
|
+
const __filename = (0, import_url4.fileURLToPath)(import_meta4.url);
|
|
426
|
+
const __dirname = import_path4.default.dirname(__filename);
|
|
427
|
+
const projectDir = process.cwd();
|
|
428
|
+
const srcPath = import_path4.default.join(projectDir, "src");
|
|
429
|
+
const folder = srcPath ? "" : "src";
|
|
430
|
+
const authFilePath = import_path4.default.join(projectDir, folder, "lib", "auth.ts");
|
|
431
|
+
if (!import_fs4.default.existsSync(authFilePath)) {
|
|
432
|
+
console.log(import_chalk4.default.red("auth.ts file not found."));
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
let content = import_fs4.default.readFileSync(authFilePath, "utf8");
|
|
436
|
+
const socialProvidersCode = `
|
|
437
|
+
socialProviders: {
|
|
438
|
+
google: {
|
|
439
|
+
clientId: process.env.GOOGLE_CLIENT_ID as string,
|
|
440
|
+
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
|
|
441
|
+
},
|
|
442
|
+
}`;
|
|
443
|
+
if (content.includes("betterAuth({")) {
|
|
444
|
+
content = content.replace(/betterAuth\(\{([\s\S]*?)\}\)/, (inner) => {
|
|
445
|
+
return `
|
|
446
|
+
${inner.trimEnd()},${socialProvidersCode}`;
|
|
447
|
+
});
|
|
448
|
+
import_fs4.default.writeFileSync(authFilePath, content, "utf8");
|
|
449
|
+
const envPath = import_path4.default.join(projectDir, ".env");
|
|
450
|
+
import_fs4.default.appendFileSync(envPath, `
|
|
451
|
+
|
|
452
|
+
# Google OAuth Credentials`);
|
|
453
|
+
import_fs4.default.appendFileSync(envPath, `
|
|
454
|
+
GOOGLE_CLIENT_ID=`);
|
|
455
|
+
import_fs4.default.appendFileSync(envPath, `
|
|
456
|
+
GOOGLE_CLIENT_SECRET=`);
|
|
457
|
+
const componentPath = import_path4.default.resolve(
|
|
458
|
+
__dirname,
|
|
459
|
+
"./template/components/GoogleProviders.tsx"
|
|
460
|
+
);
|
|
461
|
+
const destinationPath = import_path4.default.join(
|
|
462
|
+
projectDir,
|
|
463
|
+
folder,
|
|
464
|
+
"components",
|
|
465
|
+
"authverse"
|
|
466
|
+
);
|
|
467
|
+
if (!import_fs4.default.existsSync(destinationPath)) {
|
|
468
|
+
import_fs4.default.mkdirSync(destinationPath, { recursive: true });
|
|
469
|
+
}
|
|
470
|
+
const LoginDestinationPath = import_path4.default.join(
|
|
471
|
+
destinationPath,
|
|
472
|
+
"GoogleProviders.tsx"
|
|
473
|
+
);
|
|
474
|
+
import_fs4.default.copyFileSync(componentPath, LoginDestinationPath);
|
|
475
|
+
console.log(
|
|
476
|
+
import_chalk4.default.green("Added socialProviders with Google provider successfully")
|
|
477
|
+
);
|
|
478
|
+
} else {
|
|
479
|
+
console.log(import_chalk4.default.red("Could not find betterAuth({ }) block in auth.ts"));
|
|
480
|
+
}
|
|
481
|
+
} catch (error) {
|
|
482
|
+
console.log(import_chalk4.default.red("Error adding socialProviders:"), error);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// script/githubRun.ts
|
|
487
|
+
var import_chalk5 = __toESM(require("chalk"), 1);
|
|
488
|
+
var import_child_process5 = require("child_process");
|
|
489
|
+
var import_fs5 = __toESM(require("fs"), 1);
|
|
490
|
+
var import_path5 = __toESM(require("path"), 1);
|
|
491
|
+
var import_url5 = require("url");
|
|
492
|
+
var import_meta5 = {};
|
|
493
|
+
var githubRun = async () => {
|
|
494
|
+
try {
|
|
495
|
+
(0, import_child_process5.execSync)("npm install react-icons --save", { stdio: "inherit" });
|
|
496
|
+
const __filename = (0, import_url5.fileURLToPath)(import_meta5.url);
|
|
497
|
+
const __dirname = import_path5.default.dirname(__filename);
|
|
498
|
+
const projectDir = process.cwd();
|
|
499
|
+
const srcPath = import_path5.default.join(projectDir, "src");
|
|
500
|
+
const folder = import_fs5.default.existsSync(srcPath) ? "src" : "";
|
|
501
|
+
const authFilePath = import_path5.default.join(projectDir, folder, "lib", "auth.ts");
|
|
502
|
+
if (!import_fs5.default.existsSync(authFilePath)) {
|
|
503
|
+
console.log(import_chalk5.default.red("auth.ts file not found."));
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
let content = import_fs5.default.readFileSync(authFilePath, "utf8");
|
|
507
|
+
const githubProviderCode = `github: {
|
|
508
|
+
clientId: process.env.GITHUB_CLIENT_ID as string,
|
|
509
|
+
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
|
|
510
|
+
},`;
|
|
511
|
+
if (content.includes("betterAuth({")) {
|
|
512
|
+
if (content.includes("socialProviders:")) {
|
|
513
|
+
const socialProvidersStart = content.indexOf("socialProviders: {");
|
|
514
|
+
let socialProvidersEnd = socialProvidersStart;
|
|
515
|
+
let braceCount = 0;
|
|
516
|
+
let inSocialProviders = false;
|
|
517
|
+
for (let i = socialProvidersStart; i < content.length; i++) {
|
|
518
|
+
if (content[i] === "{") {
|
|
519
|
+
braceCount++;
|
|
520
|
+
inSocialProviders = true;
|
|
521
|
+
} else if (content[i] === "}") {
|
|
522
|
+
braceCount--;
|
|
523
|
+
if (inSocialProviders && braceCount === 0) {
|
|
524
|
+
socialProvidersEnd = i;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
const before = content.substring(0, socialProvidersEnd);
|
|
530
|
+
const after = content.substring(socialProvidersEnd);
|
|
531
|
+
content = before + `${githubProviderCode}
|
|
532
|
+
` + after;
|
|
533
|
+
} else {
|
|
534
|
+
const insertPosition = content.search(
|
|
535
|
+
/(?=,\s*(plugins|emailAndPassword|session|database|$|\n\s*\}\)))/
|
|
536
|
+
);
|
|
537
|
+
if (insertPosition !== -1) {
|
|
538
|
+
const before = content.substring(0, insertPosition);
|
|
539
|
+
const after = content.substring(insertPosition);
|
|
540
|
+
content = before + `,
|
|
541
|
+
socialProviders: {
|
|
542
|
+
${githubProviderCode}
|
|
543
|
+
}` + after;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
import_fs5.default.writeFileSync(authFilePath, content, "utf8");
|
|
547
|
+
const envPath = import_path5.default.join(projectDir, ".env");
|
|
548
|
+
if (import_fs5.default.existsSync(envPath)) {
|
|
549
|
+
import_fs5.default.appendFileSync(envPath, `
|
|
550
|
+
|
|
551
|
+
# Github OAuth Credentials`);
|
|
552
|
+
import_fs5.default.appendFileSync(envPath, `
|
|
553
|
+
GITHUB_CLIENT_ID=`);
|
|
554
|
+
import_fs5.default.appendFileSync(envPath, `
|
|
555
|
+
GITHUB_CLIENT_SECRET=`);
|
|
556
|
+
}
|
|
557
|
+
const componentPath = import_path5.default.resolve(
|
|
558
|
+
__dirname,
|
|
559
|
+
"./template/components/GithubProviders.tsx"
|
|
560
|
+
);
|
|
561
|
+
const destinationPath = import_path5.default.join(
|
|
562
|
+
projectDir,
|
|
563
|
+
folder,
|
|
564
|
+
"components",
|
|
565
|
+
"authverse"
|
|
566
|
+
);
|
|
567
|
+
if (!import_fs5.default.existsSync(destinationPath)) {
|
|
568
|
+
import_fs5.default.mkdirSync(destinationPath, { recursive: true });
|
|
569
|
+
}
|
|
570
|
+
const LoginDestinationPath = import_path5.default.join(
|
|
571
|
+
destinationPath,
|
|
572
|
+
"GithubProviders.tsx"
|
|
573
|
+
);
|
|
574
|
+
if (import_fs5.default.existsSync(componentPath)) {
|
|
575
|
+
import_fs5.default.copyFileSync(componentPath, LoginDestinationPath);
|
|
576
|
+
}
|
|
577
|
+
console.log(
|
|
578
|
+
import_chalk5.default.green("Added socialProviders with Github provider successfully")
|
|
579
|
+
);
|
|
580
|
+
} else {
|
|
581
|
+
console.log(import_chalk5.default.red("Could not find betterAuth({ }) block in auth.ts"));
|
|
582
|
+
}
|
|
583
|
+
} catch (error) {
|
|
584
|
+
console.log(import_chalk5.default.red("Error adding socialProviders:"), error);
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
// cli/provider.ts
|
|
589
|
+
var providers = async ({ provider }) => {
|
|
590
|
+
try {
|
|
591
|
+
if (provider == "google") {
|
|
592
|
+
await googleRun();
|
|
593
|
+
} else if (provider == "github") {
|
|
594
|
+
await githubRun();
|
|
595
|
+
}
|
|
596
|
+
} catch (error) {
|
|
597
|
+
console.log(import_chalk6.default.red("Error adding provider:"), error);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
// cli/forget.ts
|
|
602
|
+
var import_chalk7 = __toESM(require("chalk"), 1);
|
|
603
|
+
var import_child_process6 = require("child_process");
|
|
604
|
+
var import_path6 = __toESM(require("path"), 1);
|
|
605
|
+
var import_url6 = require("url");
|
|
606
|
+
var import_fs6 = __toESM(require("fs"), 1);
|
|
607
|
+
var import_meta6 = {};
|
|
608
|
+
var forget = async () => {
|
|
609
|
+
try {
|
|
610
|
+
(0, import_child_process6.execSync)("npm install @react-email/components resend", {
|
|
611
|
+
stdio: "inherit"
|
|
612
|
+
});
|
|
613
|
+
const __filename = (0, import_url6.fileURLToPath)(import_meta6.url);
|
|
614
|
+
const __dirname = import_path6.default.dirname(__filename);
|
|
615
|
+
const projectDir = process.cwd();
|
|
616
|
+
const srcPath = import_path6.default.join(projectDir, "src");
|
|
617
|
+
const folder = import_fs6.default.existsSync(srcPath) ? "src" : "";
|
|
618
|
+
const authFilePath = import_path6.default.join(projectDir, folder, "lib", "auth.ts");
|
|
619
|
+
if (!import_fs6.default.existsSync(authFilePath)) {
|
|
620
|
+
console.log(import_chalk7.default.red("auth.ts file not found."));
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
let content = import_fs6.default.readFileSync(authFilePath, "utf8");
|
|
624
|
+
const codeAdded = `sendResetPassword: async ({ user, url, token }) => {
|
|
625
|
+
await resend.emails.send({
|
|
626
|
+
from: \`\${process.env.EMAIL_SENDER_NAME} <\${process.env.EMAIL_SENDER_ADDRESS}>\`,
|
|
627
|
+
to: user.email,
|
|
628
|
+
subject: "Reset your password",
|
|
629
|
+
react: ForgotPasswordEmail({
|
|
630
|
+
username: user.name,
|
|
631
|
+
resetUrl: url,
|
|
632
|
+
userEmail: user.email,
|
|
633
|
+
}),
|
|
634
|
+
});
|
|
635
|
+
},`;
|
|
636
|
+
if (content.includes("emailAndPassword: {")) {
|
|
637
|
+
const emailAndPasswordStart = content.indexOf("emailAndPassword: {");
|
|
638
|
+
let emailAndPasswordEnd = emailAndPasswordStart;
|
|
639
|
+
let braceCount = 0;
|
|
640
|
+
let inEmailAndPassword = false;
|
|
641
|
+
for (let i = emailAndPasswordStart; i < content.length; i++) {
|
|
642
|
+
if (content[i] === "{") {
|
|
643
|
+
braceCount++;
|
|
644
|
+
inEmailAndPassword = true;
|
|
645
|
+
} else if (content[i] === "}") {
|
|
646
|
+
braceCount--;
|
|
647
|
+
if (inEmailAndPassword && braceCount === 0) {
|
|
648
|
+
emailAndPasswordEnd = i;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
const emailAndPasswordContent = content.substring(
|
|
654
|
+
emailAndPasswordStart,
|
|
655
|
+
emailAndPasswordEnd
|
|
656
|
+
);
|
|
657
|
+
if (emailAndPasswordContent.includes("sendResetPassword:")) {
|
|
658
|
+
content = content.replace(
|
|
659
|
+
/sendResetPassword:\s*async\s*\([^)]*\)[^{]*\{[^}]*\}[^,]*/,
|
|
660
|
+
codeAdded
|
|
661
|
+
);
|
|
662
|
+
} else {
|
|
663
|
+
const before = content.substring(0, emailAndPasswordEnd);
|
|
664
|
+
const after = content.substring(emailAndPasswordEnd);
|
|
665
|
+
content = before + `
|
|
666
|
+
${codeAdded}` + after;
|
|
667
|
+
}
|
|
668
|
+
import_fs6.default.writeFileSync(authFilePath, content, "utf8");
|
|
669
|
+
if (!content.includes("import { Resend }") && !content.includes("const resend = new Resend")) {
|
|
670
|
+
const lastImportIndex = content.lastIndexOf("import");
|
|
671
|
+
const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
|
|
672
|
+
const beforeImports = content.substring(0, nextLineAfterLastImport);
|
|
673
|
+
const afterImports = content.substring(nextLineAfterLastImport);
|
|
674
|
+
const newImports = `import { Resend } from "resend";
|
|
675
|
+
import ForgotPasswordEmail from "@/components/email/reset-password";
|
|
676
|
+
|
|
677
|
+
const resend = new Resend(process.env.RESEND_API_KEY as string);
|
|
678
|
+
`;
|
|
679
|
+
content = beforeImports + newImports + afterImports;
|
|
680
|
+
import_fs6.default.writeFileSync(authFilePath, content, "utf8");
|
|
681
|
+
}
|
|
682
|
+
const envPath = import_path6.default.join(projectDir, ".env");
|
|
683
|
+
if (import_fs6.default.existsSync(envPath)) {
|
|
684
|
+
import_fs6.default.appendFileSync(envPath, `
|
|
685
|
+
|
|
686
|
+
# Resend API Key for sending emails`);
|
|
687
|
+
import_fs6.default.appendFileSync(envPath, `
|
|
688
|
+
RESEND_API_KEY=`);
|
|
689
|
+
import_fs6.default.appendFileSync(envPath, `
|
|
690
|
+
EMAIL_SENDER_NAME=Your Name`);
|
|
691
|
+
import_fs6.default.appendFileSync(envPath, `
|
|
692
|
+
EMAIL_SENDER_ADDRESS=`);
|
|
693
|
+
}
|
|
694
|
+
const componentPath = import_path6.default.resolve(
|
|
695
|
+
__dirname,
|
|
696
|
+
"./template/email/reset-password.tsx"
|
|
697
|
+
);
|
|
698
|
+
const destinationPath = import_path6.default.join(
|
|
699
|
+
projectDir,
|
|
700
|
+
folder,
|
|
701
|
+
"components",
|
|
702
|
+
"email"
|
|
703
|
+
);
|
|
704
|
+
if (!import_fs6.default.existsSync(destinationPath)) {
|
|
705
|
+
import_fs6.default.mkdirSync(destinationPath, { recursive: true });
|
|
706
|
+
}
|
|
707
|
+
const emailDestinationPath = import_path6.default.join(
|
|
708
|
+
destinationPath,
|
|
709
|
+
"reset-password.tsx"
|
|
710
|
+
);
|
|
711
|
+
if (import_fs6.default.existsSync(componentPath)) {
|
|
712
|
+
import_fs6.default.copyFileSync(componentPath, emailDestinationPath);
|
|
713
|
+
}
|
|
714
|
+
const forgetComponentPath = import_path6.default.resolve(
|
|
715
|
+
__dirname,
|
|
716
|
+
"./template/components/ForgetComponent.tsx"
|
|
717
|
+
);
|
|
718
|
+
const componentsDestinationPath = import_path6.default.join(
|
|
719
|
+
projectDir,
|
|
720
|
+
folder,
|
|
721
|
+
"components",
|
|
722
|
+
"authverse"
|
|
723
|
+
);
|
|
724
|
+
if (!import_fs6.default.existsSync(componentsDestinationPath)) {
|
|
725
|
+
import_fs6.default.mkdirSync(componentsDestinationPath, { recursive: true });
|
|
726
|
+
}
|
|
727
|
+
const forgetDestinationPath = import_path6.default.join(
|
|
728
|
+
componentsDestinationPath,
|
|
729
|
+
"ForgetComponent.tsx"
|
|
730
|
+
);
|
|
731
|
+
if (import_fs6.default.existsSync(forgetComponentPath)) {
|
|
732
|
+
import_fs6.default.copyFileSync(forgetComponentPath, forgetDestinationPath);
|
|
733
|
+
}
|
|
734
|
+
const resetComponentPath = import_path6.default.resolve(
|
|
735
|
+
__dirname,
|
|
736
|
+
"./template/components/ResetComponent.tsx"
|
|
737
|
+
);
|
|
738
|
+
const resetDestinationPath = import_path6.default.join(
|
|
739
|
+
componentsDestinationPath,
|
|
740
|
+
"ResetComponent.tsx"
|
|
741
|
+
);
|
|
742
|
+
if (import_fs6.default.existsSync(resetComponentPath)) {
|
|
743
|
+
import_fs6.default.copyFileSync(resetComponentPath, resetDestinationPath);
|
|
744
|
+
}
|
|
745
|
+
const authTemplatePath = import_path6.default.resolve(
|
|
746
|
+
__dirname,
|
|
747
|
+
"./template/app-auth-uiDesign"
|
|
748
|
+
);
|
|
749
|
+
const appDestinationPath = import_path6.default.join(projectDir, folder, "app", "auth");
|
|
750
|
+
if (!import_fs6.default.existsSync(appDestinationPath)) {
|
|
751
|
+
import_fs6.default.mkdirSync(appDestinationPath, { recursive: true });
|
|
752
|
+
}
|
|
753
|
+
const forgetDestinationDir = import_path6.default.join(appDestinationPath, "forget");
|
|
754
|
+
if (!import_fs6.default.existsSync(forgetDestinationDir)) {
|
|
755
|
+
import_fs6.default.mkdirSync(forgetDestinationDir, { recursive: true });
|
|
756
|
+
}
|
|
757
|
+
const forgetPageDestinationPath = import_path6.default.join(
|
|
758
|
+
forgetDestinationDir,
|
|
759
|
+
"page.tsx"
|
|
760
|
+
);
|
|
761
|
+
import_fs6.default.copyFileSync(
|
|
762
|
+
`${authTemplatePath}/forget/page.tsx`,
|
|
763
|
+
forgetPageDestinationPath
|
|
764
|
+
);
|
|
765
|
+
const resetDestinationDir = import_path6.default.join(
|
|
766
|
+
appDestinationPath,
|
|
767
|
+
"reset-password"
|
|
768
|
+
);
|
|
769
|
+
if (!import_fs6.default.existsSync(resetDestinationDir)) {
|
|
770
|
+
import_fs6.default.mkdirSync(resetDestinationDir, { recursive: true });
|
|
771
|
+
}
|
|
772
|
+
const resetPageDestinationPath = import_path6.default.join(
|
|
773
|
+
resetDestinationDir,
|
|
774
|
+
"page.tsx"
|
|
775
|
+
);
|
|
776
|
+
import_fs6.default.copyFileSync(
|
|
777
|
+
`${authTemplatePath}/reset-password/page.tsx`,
|
|
778
|
+
resetPageDestinationPath
|
|
779
|
+
);
|
|
780
|
+
console.log(
|
|
781
|
+
import_chalk7.default.green("Added sendResetPassword configuration successfully")
|
|
782
|
+
);
|
|
783
|
+
} else {
|
|
784
|
+
console.log(
|
|
785
|
+
import_chalk7.default.red("Could not find emailAndPassword configuration in auth.ts")
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
} catch (error) {
|
|
789
|
+
console.log(import_chalk7.default.red("Error adding sendResetPassword:"), error);
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
|
|
793
|
+
// script/detect-nextjs.ts
|
|
794
|
+
var import_fs7 = require("fs");
|
|
795
|
+
function isNextJsProject() {
|
|
796
|
+
if (!(0, import_fs7.existsSync)("./package.json")) return false;
|
|
797
|
+
try {
|
|
798
|
+
const pkg = JSON.parse((0, import_fs7.readFileSync)("./package.json", "utf8"));
|
|
799
|
+
const deps = {
|
|
800
|
+
...pkg.dependencies,
|
|
801
|
+
...pkg.devDependencies
|
|
802
|
+
};
|
|
803
|
+
return deps["next"] !== void 0;
|
|
804
|
+
} catch (err) {
|
|
805
|
+
return false;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
// index.ts
|
|
810
|
+
var import_chalk8 = __toESM(require("chalk"), 1);
|
|
811
|
+
var packageJson = JSON.parse((0, import_fs8.readFileSync)("./package.json", "utf8"));
|
|
812
|
+
var program = new import_commander.Command();
|
|
813
|
+
program.name("authverse").description("CLI tool for creating authverse projects").version(
|
|
814
|
+
packageJson.version || "1.0.0",
|
|
815
|
+
"-v, --version",
|
|
816
|
+
"display the version number"
|
|
817
|
+
);
|
|
818
|
+
program.command("init").description("Select project template and configuration").action(() => {
|
|
819
|
+
if (!isNextJsProject) {
|
|
820
|
+
console.log(import_chalk8.default.red("Only Next.js projects are supported."));
|
|
821
|
+
process.exit(1);
|
|
822
|
+
}
|
|
823
|
+
initAnswer();
|
|
824
|
+
});
|
|
825
|
+
program.command("add <provider>").description("Add a new authentication provider").action((provider) => providers({ provider }));
|
|
826
|
+
program.command("forget").description("Forget stored configurations").action(forget);
|
|
827
|
+
program.parse(process.argv);
|