authverse 1.0.4 → 1.0.6-canary.1

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/dist/index.cjs CHANGED
@@ -33,9 +33,8 @@ var import_url2 = require("url");
33
33
  var import_path2 = __toESM(require("path"), 1);
34
34
  var import_fs2 = __toESM(require("fs"), 1);
35
35
  var import_chalk2 = __toESM(require("chalk"), 1);
36
- var import_child_process2 = require("child_process");
37
36
 
38
- // function/GenerateSecret.ts
37
+ // utils/GenerateSecret.ts
39
38
  var import_crypto = __toESM(require("crypto"), 1);
40
39
  var GenerateSecret = async () => {
41
40
  const secret = import_crypto.default.randomBytes(64).toString("hex");
@@ -44,20 +43,53 @@ var GenerateSecret = async () => {
44
43
 
45
44
  // script/authUi.ts
46
45
  var import_chalk = __toESM(require("chalk"), 1);
47
- var import_child_process = require("child_process");
48
46
  var import_path = __toESM(require("path"), 1);
49
47
  var import_fs = __toESM(require("fs"), 1);
50
48
  var import_url = require("url");
49
+
50
+ // utils/packageManager.ts
51
+ var import_child_process = require("child_process");
52
+ var getPackageManager = () => {
53
+ const ua = process.env.npm_config_user_agent || "";
54
+ if (ua.includes("bun")) return "bun";
55
+ if (ua.includes("pnpm")) return "pnpm";
56
+ if (ua.includes("yarn")) return "yarn";
57
+ return "npm";
58
+ };
59
+ var pm = getPackageManager();
60
+ var packageManager = (pkg, dev = false) => {
61
+ if (pm === "pnpm") {
62
+ (0, import_child_process.execSync)(`pnpm add ${dev ? "-D " : ""}${pkg}`, { stdio: "inherit" });
63
+ } else if (pm === "yarn") {
64
+ (0, import_child_process.execSync)(`yarn add ${dev ? "--dev " : ""}${pkg}`, { stdio: "inherit" });
65
+ } else if (pm === "bun") {
66
+ (0, import_child_process.execSync)(`bun add ${dev ? "-d " : ""}${pkg}`, { stdio: "inherit" });
67
+ } else {
68
+ (0, import_child_process.execSync)(`npm install ${pkg} ${dev ? "--save-dev" : ""}`, {
69
+ stdio: "inherit"
70
+ });
71
+ }
72
+ };
73
+ var runCommand = (cmd) => {
74
+ const pm2 = getPackageManager();
75
+ if (pm2 === "pnpm") {
76
+ (0, import_child_process.execSync)(`pnpm dlx ${cmd}`, { stdio: "inherit" });
77
+ } else if (pm2 === "bun") {
78
+ (0, import_child_process.execSync)(`bunx ${cmd}`, { stdio: "inherit" });
79
+ } else if (pm2 === "yarn") {
80
+ (0, import_child_process.execSync)(`yarn dlx ${cmd}`, { stdio: "inherit" });
81
+ } else {
82
+ (0, import_child_process.execSync)(`npx ${cmd}`, { stdio: "inherit" });
83
+ }
84
+ };
85
+
86
+ // script/authUi.ts
51
87
  var import_meta = {};
52
88
  var authUiRun = async ({ folder }) => {
53
89
  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
- });
90
+ console.log(import_chalk.default.yellow("\n Installing shadcn ui Components\n"));
91
+ runCommand("shadcn@latest add button sonner card field input");
92
+ packageManager("react-hook-form @hookform/resolvers");
61
93
  const __filename = (0, import_url.fileURLToPath)(import_meta.url);
62
94
  const __dirname = import_path.default.dirname(__filename);
63
95
  const projectDir = process.cwd();
@@ -145,56 +177,74 @@ ${layoutContent}`;
145
177
  var import_meta2 = {};
146
178
  var prismaRun = async ({ authUi, database }) => {
147
179
  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" });
180
+ const projectDir = process.cwd();
181
+ const __filename = (0, import_url2.fileURLToPath)(import_meta2.url);
182
+ const __dirname = import_path2.default.dirname(__filename);
183
+ const packageJsonPath = import_path2.default.join(projectDir, "package.json");
184
+ const packageJson2 = JSON.parse(import_fs2.default.readFileSync(packageJsonPath, "utf-8"));
185
+ if (!packageJson2.devDependencies?.prisma && !packageJson2.dependencies?.["@prisma/client"]) {
186
+ console.log(import_chalk2.default.cyan("\n\u2699\uFE0F Initializing Prisma...\n"));
187
+ if (database !== "Mongodb") {
188
+ packageManager("prisma", true);
189
+ packageManager("@prisma/client");
190
+ if (database === "Mysql") {
191
+ packageManager("@prisma/adapter-mariadb");
192
+ }
193
+ if (database === "Postgresql") {
194
+ packageManager("@prisma/adapter-pg");
195
+ }
196
+ } else if (database === "Mongodb") {
197
+ packageManager("prisma@6.19.0", true);
198
+ packageManager("@prisma/client@6.19.0");
157
199
  }
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
200
  }
162
- const projectDir = process.cwd();
163
201
  const prismaDir = import_path2.default.join(projectDir, "prisma");
164
202
  if (!import_fs2.default.existsSync(prismaDir)) {
165
203
  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(
204
+ runCommand("prisma init");
205
+ const templatePath = import_path2.default.resolve(
206
+ __dirname,
207
+ `./template/prisma/${database}/schema.prisma`
208
+ );
209
+ if (!import_fs2.default.existsSync(prismaDir)) {
210
+ import_fs2.default.mkdirSync(prismaDir, { recursive: true });
211
+ }
212
+ const destinationPath = import_path2.default.join(prismaDir, "schema.prisma");
213
+ import_fs2.default.copyFileSync(templatePath, destinationPath);
214
+ if (database === "Mongodb") {
215
+ const prismaConfigPath = import_path2.default.resolve(
216
+ __dirname,
217
+ `./template/config/prisma.config.ts`
218
+ );
219
+ const prismaConfigDestinationPath = import_path2.default.join("", "prisma.config.ts");
220
+ import_fs2.default.copyFileSync(prismaConfigPath, prismaConfigDestinationPath);
221
+ }
222
+ } else {
223
+ const schemaPath = import_path2.default.join(prismaDir, "schema.prisma");
224
+ const templatePath = import_path2.default.resolve(
181
225
  __dirname,
182
- `./template/config/prisma.config.ts`
226
+ `./template/prisma/${database}/schema.prisma_copy`
183
227
  );
184
- const prismaConfigDestinationPath = import_path2.default.join("", "prisma.config.ts");
185
- import_fs2.default.copyFileSync(prismaConfigPath, prismaConfigDestinationPath);
228
+ import_fs2.default.appendFileSync(schemaPath, "\n");
229
+ import_fs2.default.appendFileSync(schemaPath, import_fs2.default.readFileSync(templatePath));
230
+ }
231
+ if (!packageJson2.dependencies?.["better-auth"]) {
232
+ console.log(import_chalk2.default.yellow("\n\u2699\uFE0F Initializing better-auth...\n"));
233
+ packageManager("better-auth");
186
234
  }
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
235
  const secret = await GenerateSecret();
190
236
  const envPath = import_path2.default.join(projectDir, ".env");
191
- import_fs2.default.appendFileSync(envPath, `
237
+ const envContent = import_fs2.default.readFileSync(envPath, "utf-8");
238
+ if (!envContent.includes("BETTER_AUTH_SECRET")) {
239
+ import_fs2.default.appendFileSync(envPath, `
192
240
 
193
241
  BETTER_AUTH_SECRET=${secret}`);
194
- import_fs2.default.appendFileSync(envPath, `
242
+ }
243
+ if (!envContent.includes("BETTER_AUTH_URL")) {
244
+ import_fs2.default.appendFileSync(envPath, `
195
245
  BETTER_AUTH_URL=http://localhost:3000
196
246
  `);
197
- console.log(import_chalk2.default.yellow("\n create folder...\n"));
247
+ }
198
248
  const srcPath = import_path2.default.join(projectDir, "src");
199
249
  const folder = srcPath ? "" : "src";
200
250
  const libPath = import_path2.default.join(projectDir, folder, "lib");
@@ -262,33 +312,42 @@ BETTER_AUTH_URL=http://localhost:3000
262
312
 
263
313
  // script/drizzleRun.ts
264
314
  var import_chalk3 = __toESM(require("chalk"), 1);
265
- var import_child_process3 = require("child_process");
266
315
  var import_path3 = __toESM(require("path"), 1);
267
316
  var import_url3 = require("url");
268
317
  var import_fs3 = __toESM(require("fs"), 1);
269
318
  var import_meta3 = {};
270
319
  var drizzleRun = async (authUi) => {
271
320
  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" });
321
+ const projectDir = process.cwd();
322
+ const packageJsonPath = import_path3.default.join(projectDir, "package.json");
323
+ const packageJson2 = JSON.parse(import_fs3.default.readFileSync(packageJsonPath, "utf-8"));
324
+ if (!packageJson2.dependencies["better-auth"]) {
325
+ console.log(import_chalk3.default.cyan("\n\u2699\uFE0F Initializing better auth...\n"));
326
+ packageManager("better-auth");
327
+ }
328
+ if (!packageJson2.dependencies["drizzle-orm"] && !packageJson2.dependencies["drizzle-orm"] && !packageJson2.dependencies["drizzle-kit"] && !packageJson2.devDependencies["drizzle-kit"]) {
329
+ console.log(import_chalk3.default.cyan("\n\u2699\uFE0F Initializing drizzle...\n"));
330
+ packageManager("drizzle-orm @neondatabase/serverless dotenv");
331
+ packageManager("drizzle-kit", true);
332
+ }
278
333
  const __filename = (0, import_url3.fileURLToPath)(import_meta3.url);
279
334
  const __dirname = import_path3.default.dirname(__filename);
280
- const projectDir = process.cwd();
281
335
  const envPath = import_path3.default.join(projectDir, ".env");
282
336
  if (!import_fs3.default.existsSync(envPath)) {
283
337
  import_fs3.default.writeFileSync(envPath, "DATABASE_URL=\n");
284
338
  }
285
339
  const secret = await GenerateSecret();
286
- import_fs3.default.appendFileSync(envPath, `
340
+ const envContent = import_fs3.default.readFileSync(envPath, "utf-8");
341
+ if (!envContent.includes("BETTER_AUTH_SECRET")) {
342
+ import_fs3.default.appendFileSync(envPath, `
287
343
 
288
344
  BETTER_AUTH_SECRET=${secret}`);
289
- import_fs3.default.appendFileSync(envPath, `
345
+ }
346
+ if (!envContent.includes("BETTER_AUTH_URL")) {
347
+ import_fs3.default.appendFileSync(envPath, `
290
348
  BETTER_AUTH_URL=http://localhost:3000
291
349
  `);
350
+ }
292
351
  const srcPath = import_path3.default.join(projectDir, "src");
293
352
  const folder = srcPath ? "" : "src";
294
353
  const libPath = import_path3.default.join(projectDir, folder, "lib");
@@ -414,85 +473,122 @@ var import_chalk6 = __toESM(require("chalk"), 1);
414
473
 
415
474
  // script/googleRun.ts
416
475
  var import_chalk4 = __toESM(require("chalk"), 1);
417
- var import_child_process4 = require("child_process");
418
476
  var import_fs4 = __toESM(require("fs"), 1);
419
477
  var import_path4 = __toESM(require("path"), 1);
420
478
  var import_url4 = require("url");
421
479
  var import_meta4 = {};
422
480
  var googleRun = async () => {
423
481
  try {
424
- (0, import_child_process4.execSync)("npm install react-icons --save", { stdio: "inherit" });
425
482
  const __filename = (0, import_url4.fileURLToPath)(import_meta4.url);
426
483
  const __dirname = import_path4.default.dirname(__filename);
427
484
  const projectDir = process.cwd();
428
485
  const srcPath = import_path4.default.join(projectDir, "src");
429
- const folder = srcPath ? "" : "src";
486
+ const folder = import_fs4.default.existsSync(srcPath) ? "src" : "";
430
487
  const authFilePath = import_path4.default.join(projectDir, folder, "lib", "auth.ts");
431
488
  if (!import_fs4.default.existsSync(authFilePath)) {
432
- console.log(import_chalk4.default.red("auth.ts file not found."));
489
+ console.log(import_chalk4.default.red("\u274C auth.ts file not found"));
433
490
  return;
434
491
  }
435
492
  let content = import_fs4.default.readFileSync(authFilePath, "utf8");
436
- const socialProvidersCode = `
437
- socialProviders: {
493
+ if (!content.includes("betterAuth({")) {
494
+ console.log(import_chalk4.default.red("betterAuth({}) block not found"));
495
+ return;
496
+ }
497
+ if (content.includes("socialProviders") && content.includes("google:")) {
498
+ console.log(import_chalk4.default.yellow("Google provider already exists"));
499
+ return;
500
+ }
501
+ const googleProviderEntry = `
438
502
  google: {
439
503
  clientId: process.env.GOOGLE_CLIENT_ID as string,
440
504
  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 });
505
+ },`;
506
+ if (content.includes("socialProviders: {")) {
507
+ const start = content.indexOf("socialProviders: {");
508
+ let braceCount = 0;
509
+ let insertPos = -1;
510
+ for (let i = start; i < content.length; i++) {
511
+ if (content[i] === "{") braceCount++;
512
+ if (content[i] === "}") {
513
+ braceCount--;
514
+ if (braceCount === 0) {
515
+ insertPos = i;
516
+ break;
517
+ }
518
+ }
469
519
  }
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
- );
520
+ if (insertPos === -1) {
521
+ console.log(import_chalk4.default.red("Failed to parse socialProviders block"));
522
+ return;
523
+ }
524
+ content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
478
525
  } else {
479
- console.log(import_chalk4.default.red("Could not find betterAuth({ }) block in auth.ts"));
526
+ const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
527
+ if (!databaseRegex.test(content)) {
528
+ console.log(
529
+ import_chalk4.default.red(
530
+ "Could not find database adapter (prismaAdapter or drizzleAdapter)"
531
+ )
532
+ );
533
+ return;
534
+ }
535
+ const socialProvidersBlock = `
536
+ socialProviders: {
537
+ ${googleProviderEntry}
538
+ },`;
539
+ content = content.replace(
540
+ databaseRegex,
541
+ (match) => `${match}
542
+ ${socialProvidersBlock}`
543
+ );
544
+ }
545
+ import_fs4.default.writeFileSync(authFilePath, content, "utf8");
546
+ const envPath = import_path4.default.join(projectDir, ".env");
547
+ if (import_fs4.default.existsSync(envPath)) {
548
+ const envContent = import_fs4.default.readFileSync(envPath, "utf8");
549
+ if (!envContent.includes("GOOGLE_CLIENT_ID")) {
550
+ import_fs4.default.appendFileSync(
551
+ envPath,
552
+ `
553
+
554
+ # Google OAuth
555
+ GOOGLE_CLIENT_ID=
556
+ GOOGLE_CLIENT_SECRET=
557
+ `
558
+ );
559
+ }
560
+ }
561
+ const componentTemplate = import_path4.default.resolve(
562
+ __dirname,
563
+ "./template/components/GoogleProviders.tsx"
564
+ );
565
+ const componentsDir = import_path4.default.join(
566
+ projectDir,
567
+ folder,
568
+ "components",
569
+ "authverse"
570
+ );
571
+ if (!import_fs4.default.existsSync(componentsDir)) {
572
+ import_fs4.default.mkdirSync(componentsDir, { recursive: true });
480
573
  }
574
+ const componentDest = import_path4.default.join(componentsDir, "GoogleProviders.tsx");
575
+ if (import_fs4.default.existsSync(componentTemplate)) {
576
+ import_fs4.default.copyFileSync(componentTemplate, componentDest);
577
+ }
578
+ console.log(import_chalk4.default.green("Google provider added & merged successfully"));
481
579
  } catch (error) {
482
- console.log(import_chalk4.default.red("Error adding socialProviders:"), error);
580
+ console.log(import_chalk4.default.red("googleRun error:"), error);
483
581
  }
484
582
  };
485
583
 
486
584
  // script/githubRun.ts
487
585
  var import_chalk5 = __toESM(require("chalk"), 1);
488
- var import_child_process5 = require("child_process");
489
586
  var import_fs5 = __toESM(require("fs"), 1);
490
587
  var import_path5 = __toESM(require("path"), 1);
491
588
  var import_url5 = require("url");
492
589
  var import_meta5 = {};
493
590
  var githubRun = async () => {
494
591
  try {
495
- (0, import_child_process5.execSync)("npm install react-icons --save", { stdio: "inherit" });
496
592
  const __filename = (0, import_url5.fileURLToPath)(import_meta5.url);
497
593
  const __dirname = import_path5.default.dirname(__filename);
498
594
  const projectDir = process.cwd();
@@ -500,88 +596,98 @@ var githubRun = async () => {
500
596
  const folder = import_fs5.default.existsSync(srcPath) ? "src" : "";
501
597
  const authFilePath = import_path5.default.join(projectDir, folder, "lib", "auth.ts");
502
598
  if (!import_fs5.default.existsSync(authFilePath)) {
503
- console.log(import_chalk5.default.red("auth.ts file not found."));
599
+ console.log(import_chalk5.default.red("auth.ts file not found"));
504
600
  return;
505
601
  }
506
602
  let content = import_fs5.default.readFileSync(authFilePath, "utf8");
507
- const githubProviderCode = `github: {
603
+ if (!content.includes("betterAuth({")) {
604
+ console.log(import_chalk5.default.red("betterAuth({}) block not found"));
605
+ return;
606
+ }
607
+ if (content.includes("socialProviders") && content.includes("github:")) {
608
+ console.log(import_chalk5.default.yellow("GitHub provider already exists"));
609
+ return;
610
+ }
611
+ const githubProviderEntry = `
612
+ github: {
508
613
  clientId: process.env.GITHUB_CLIENT_ID as string,
509
614
  clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
510
615
  },`;
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
- }
616
+ if (content.includes("socialProviders: {")) {
617
+ const start = content.indexOf("socialProviders: {");
618
+ let braceCount = 0;
619
+ let insertPos = -1;
620
+ for (let i = start; i < content.length; i++) {
621
+ if (content[i] === "{") braceCount++;
622
+ if (content[i] === "}") {
623
+ braceCount--;
624
+ if (braceCount === 0) {
625
+ insertPos = i;
626
+ break;
527
627
  }
528
628
  }
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
629
  }
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=`);
630
+ if (insertPos === -1) {
631
+ console.log(import_chalk5.default.red("Failed to parse socialProviders block"));
632
+ return;
556
633
  }
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 });
634
+ content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
635
+ } else {
636
+ const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
637
+ if (!databaseRegex.test(content)) {
638
+ console.log(
639
+ import_chalk5.default.red(
640
+ "Could not find database adapter (prismaAdapter or drizzleAdapter)"
641
+ )
642
+ );
643
+ return;
569
644
  }
570
- const LoginDestinationPath = import_path5.default.join(
571
- destinationPath,
572
- "GithubProviders.tsx"
645
+ const socialProvidersBlock = `
646
+ socialProviders: {
647
+ ${githubProviderEntry}
648
+ },`;
649
+ content = content.replace(
650
+ databaseRegex,
651
+ (match) => `${match}
652
+ ${socialProvidersBlock}`
573
653
  );
574
- if (import_fs5.default.existsSync(componentPath)) {
575
- import_fs5.default.copyFileSync(componentPath, LoginDestinationPath);
654
+ }
655
+ import_fs5.default.writeFileSync(authFilePath, content, "utf8");
656
+ const envPath = import_path5.default.join(projectDir, ".env");
657
+ if (import_fs5.default.existsSync(envPath)) {
658
+ const envContent = import_fs5.default.readFileSync(envPath, "utf8");
659
+ if (!envContent.includes("GITHUB_CLIENT_ID")) {
660
+ import_fs5.default.appendFileSync(
661
+ envPath,
662
+ `
663
+
664
+ # GitHub OAuth
665
+ GITHUB_CLIENT_ID=
666
+ GITHUB_CLIENT_SECRET=
667
+ `
668
+ );
576
669
  }
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
670
  }
671
+ const componentTemplate = import_path5.default.resolve(
672
+ __dirname,
673
+ "./template/components/GithubProviders.tsx"
674
+ );
675
+ const componentsDir = import_path5.default.join(
676
+ projectDir,
677
+ folder,
678
+ "components",
679
+ "authverse"
680
+ );
681
+ if (!import_fs5.default.existsSync(componentsDir)) {
682
+ import_fs5.default.mkdirSync(componentsDir, { recursive: true });
683
+ }
684
+ const componentDest = import_path5.default.join(componentsDir, "GithubProviders.tsx");
685
+ if (import_fs5.default.existsSync(componentTemplate)) {
686
+ import_fs5.default.copyFileSync(componentTemplate, componentDest);
687
+ }
688
+ console.log(import_chalk5.default.green("GitHub provider added & merged successfully"));
583
689
  } catch (error) {
584
- console.log(import_chalk5.default.red("Error adding socialProviders:"), error);
690
+ console.log(import_chalk5.default.red("githubRun error:"), error);
585
691
  }
586
692
  };
587
693
 
@@ -600,19 +706,25 @@ var providers = async ({ provider }) => {
600
706
 
601
707
  // cli/forget.ts
602
708
  var import_chalk7 = __toESM(require("chalk"), 1);
603
- var import_child_process6 = require("child_process");
604
709
  var import_path6 = __toESM(require("path"), 1);
605
710
  var import_url6 = require("url");
606
711
  var import_fs6 = __toESM(require("fs"), 1);
607
712
  var import_meta6 = {};
608
713
  var forget = async () => {
609
714
  try {
610
- (0, import_child_process6.execSync)("npm install @react-email/components resend", {
611
- stdio: "inherit"
612
- });
715
+ const projectDir = process.cwd();
716
+ const packageJsonPath = import_path6.default.join(projectDir, "package.json");
717
+ const packageJson2 = JSON.parse(import_fs6.default.readFileSync(packageJsonPath, "utf-8"));
718
+ if (!packageJson2.dependencies?.resend) {
719
+ console.log(import_chalk7.default.cyan("\n\u2699\uFE0F Installing Resend...\n"));
720
+ packageManager("resend");
721
+ }
722
+ if (!packageJson2.dependencies?.["@react-email/components"]) {
723
+ console.log(import_chalk7.default.cyan("\n\u2699\uFE0F Installing react email components...\n"));
724
+ packageManager("@react-email/components");
725
+ }
613
726
  const __filename = (0, import_url6.fileURLToPath)(import_meta6.url);
614
727
  const __dirname = import_path6.default.dirname(__filename);
615
- const projectDir = process.cwd();
616
728
  const srcPath = import_path6.default.join(projectDir, "src");
617
729
  const folder = import_fs6.default.existsSync(srcPath) ? "src" : "";
618
730
  const authFilePath = import_path6.default.join(projectDir, folder, "lib", "auth.ts");
@@ -680,7 +792,8 @@ const resend = new Resend(process.env.RESEND_API_KEY as string);
680
792
  import_fs6.default.writeFileSync(authFilePath, content, "utf8");
681
793
  }
682
794
  const envPath = import_path6.default.join(projectDir, ".env");
683
- if (import_fs6.default.existsSync(envPath)) {
795
+ const envContent = import_fs6.default.readFileSync(envPath, "utf8");
796
+ if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
684
797
  import_fs6.default.appendFileSync(envPath, `
685
798
 
686
799
  # Resend API Key for sending emails`);
@@ -778,7 +891,7 @@ EMAIL_SENDER_ADDRESS=`);
778
891
  resetPageDestinationPath
779
892
  );
780
893
  console.log(
781
- import_chalk7.default.green("Added sendResetPassword configuration successfully")
894
+ import_chalk7.default.green("Successfully added forget and reset-password pages")
782
895
  );
783
896
  } else {
784
897
  console.log(