authverse 1.0.6 → 1.0.7-canary.2

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.js CHANGED
@@ -197,12 +197,15 @@ var prismaRun = async ({ authUi, database }) => {
197
197
  }
198
198
  } else {
199
199
  const schemaPath = path2.join(prismaDir, "schema.prisma");
200
- const templatePath = path2.resolve(
201
- __dirname,
202
- `./template/prisma/${database}/schema.prisma_copy`
203
- );
204
- fs2.appendFileSync(schemaPath, "\n");
205
- fs2.appendFileSync(schemaPath, fs2.readFileSync(templatePath));
200
+ const schemaContent = fs2.readFileSync(schemaPath, "utf-8");
201
+ if (!schemaContent.includes("User") && !schemaContent.includes("Session") && !schemaContent.includes("Account") && !schemaContent.includes("Verification")) {
202
+ const templatePath = path2.resolve(
203
+ __dirname,
204
+ `./template/prisma/${database}/schema.prisma_copy`
205
+ );
206
+ fs2.appendFileSync(schemaPath, "\n");
207
+ fs2.appendFileSync(schemaPath, fs2.readFileSync(templatePath));
208
+ }
206
209
  }
207
210
  if (!packageJson2.dependencies?.["better-auth"]) {
208
211
  console.log(chalk2.yellow("\n\u2699\uFE0F Initializing better-auth...\n"));
@@ -406,8 +409,342 @@ BETTER_AUTH_URL=http://localhost:3000
406
409
  }
407
410
  };
408
411
 
412
+ // cli/init.ts
413
+ import path7 from "path";
414
+ import fs7 from "fs";
415
+
416
+ // script/prismaRunTanstackState.ts
417
+ import chalk5 from "chalk";
418
+ import path5 from "path";
419
+ import { fileURLToPath as fileURLToPath5 } from "url";
420
+ import fs5 from "fs";
421
+
422
+ // script/authUiTanstackState.ts
423
+ import chalk4 from "chalk";
424
+ import { fileURLToPath as fileURLToPath4 } from "url";
425
+ import path4 from "path";
426
+ import fs4 from "fs";
427
+ var authUiTanstackState = async () => {
428
+ try {
429
+ console.log(chalk4.yellow("\n Installing shadcn ui Components\n"));
430
+ runCommand("shadcn@latest add button sonner card field input");
431
+ packageManager("@tanstack/react-form");
432
+ const __filename = fileURLToPath4(import.meta.url);
433
+ const __dirname = path4.dirname(__filename);
434
+ const projectDir = process.cwd();
435
+ const srcPath = path4.join(projectDir, "src");
436
+ const componentPath = path4.resolve(
437
+ __dirname,
438
+ "./template/TanstackState/components"
439
+ );
440
+ const authversePathComponents = path4.join(
441
+ srcPath,
442
+ "components",
443
+ "authverse"
444
+ );
445
+ if (!fs4.existsSync(authversePathComponents)) {
446
+ fs4.mkdirSync(authversePathComponents, { recursive: true });
447
+ }
448
+ fs4.copyFileSync(
449
+ `${componentPath}/LoginComponent.tsx`,
450
+ path4.join(authversePathComponents, "LoginComponent.tsx")
451
+ );
452
+ fs4.copyFileSync(
453
+ `${componentPath}/SingUpComponent.tsx`,
454
+ path4.join(authversePathComponents, "SingUpComponent.tsx")
455
+ );
456
+ const pageRoutesPath = path4.join(`${srcPath}/routes`, "auth");
457
+ if (!fs4.existsSync(pageRoutesPath)) {
458
+ fs4.mkdirSync(pageRoutesPath, { recursive: true });
459
+ }
460
+ const templateRoutesPage = path4.resolve(
461
+ __dirname,
462
+ "./template/TanstackState/routes/auth"
463
+ );
464
+ fs4.copyFileSync(
465
+ `${templateRoutesPage}/login.tsx`,
466
+ path4.join(pageRoutesPath, "login.tsx")
467
+ );
468
+ fs4.copyFileSync(
469
+ `${templateRoutesPage}/signup.tsx`,
470
+ path4.join(pageRoutesPath, "signup.tsx")
471
+ );
472
+ const rootPath = path4.join(projectDir, "src/routes", "__root.tsx");
473
+ if (fs4.existsSync(rootPath)) {
474
+ let rootContent = fs4.readFileSync(rootPath, "utf-8");
475
+ if (!rootContent.includes("Toaster")) {
476
+ rootContent = `import { Toaster } from "@/components/ui/sonner";
477
+ ${rootContent}`;
478
+ }
479
+ if (!rootContent.includes("<Toaster")) {
480
+ rootContent = rootContent.replace(
481
+ /<\/body>/,
482
+ " <Toaster />\n </body>"
483
+ );
484
+ }
485
+ fs4.writeFileSync(rootPath, rootContent, "utf-8");
486
+ }
487
+ console.log(chalk4.green("\nSetup completed!\n"));
488
+ } catch (error) {
489
+ console.log(chalk4.red("Auth Ui Tanstack State Error: ", error));
490
+ }
491
+ };
492
+
493
+ // script/prismaRunTanstackState.ts
494
+ var prismaRunTanstackState = async ({
495
+ authUi,
496
+ database
497
+ }) => {
498
+ try {
499
+ const projectDir = process.cwd();
500
+ const __filename = fileURLToPath5(import.meta.url);
501
+ const __dirname = path5.dirname(__filename);
502
+ const packageJsonPath = path5.join(projectDir, "package.json");
503
+ const packageJson2 = JSON.parse(fs5.readFileSync(packageJsonPath, "utf-8"));
504
+ if (!packageJson2.devDependencies?.prisma && !packageJson2.dependencies?.["@prisma/client"]) {
505
+ console.log(chalk5.cyan("\n\u2699\uFE0F Initializing Prisma...\n"));
506
+ if (database !== "Mongodb") {
507
+ packageManager("prisma", true);
508
+ packageManager("@prisma/client");
509
+ if (database === "Mysql") {
510
+ packageManager("@prisma/adapter-mariadb");
511
+ }
512
+ if (database === "Postgresql") {
513
+ packageManager("@prisma/adapter-pg");
514
+ }
515
+ } else if (database === "Mongodb") {
516
+ packageManager("prisma@6.19.0", true);
517
+ packageManager("@prisma/client@6.19.0");
518
+ }
519
+ }
520
+ const prismaDir = path5.join(projectDir, "prisma");
521
+ if (!fs5.existsSync(prismaDir)) {
522
+ console.log(chalk5.yellow("\n\u2699\uFE0F Initializing Prisma...\n"));
523
+ runCommand("prisma init");
524
+ const templatePath = path5.resolve(
525
+ __dirname,
526
+ `./template/prisma/${database}/schema.prisma`
527
+ );
528
+ if (!fs5.existsSync(prismaDir)) {
529
+ fs5.mkdirSync(prismaDir, { recursive: true });
530
+ }
531
+ const destinationPath = path5.join(prismaDir, "schema.prisma");
532
+ fs5.copyFileSync(templatePath, destinationPath);
533
+ if (database === "Mongodb") {
534
+ const prismaConfigPath = path5.resolve(
535
+ __dirname,
536
+ `./template/config/prisma.config.ts`
537
+ );
538
+ const prismaConfigDestinationPath = path5.join("", "prisma.config.ts");
539
+ fs5.copyFileSync(prismaConfigPath, prismaConfigDestinationPath);
540
+ }
541
+ } else {
542
+ const schemaPath = path5.join(prismaDir, "schema.prisma");
543
+ const schemaContent = fs5.readFileSync(schemaPath, "utf-8");
544
+ if (!schemaContent.includes("User") && !schemaContent.includes("Session") && !schemaContent.includes("Account") && !schemaContent.includes("Verification")) {
545
+ const templatePath = path5.resolve(
546
+ __dirname,
547
+ `./template/prisma/${database}/schema.prisma_copy`
548
+ );
549
+ fs5.appendFileSync(schemaPath, "\n");
550
+ fs5.appendFileSync(schemaPath, fs5.readFileSync(templatePath));
551
+ }
552
+ }
553
+ if (!packageJson2.dependencies?.["better-auth"]) {
554
+ console.log(chalk5.yellow("\n\u2699\uFE0F Initializing better-auth...\n"));
555
+ packageManager("better-auth");
556
+ }
557
+ const secret = await GenerateSecret();
558
+ const envPath = path5.join(projectDir, ".env");
559
+ const envContent = fs5.readFileSync(envPath, "utf-8");
560
+ if (!envContent.includes("BETTER_AUTH_SECRET")) {
561
+ fs5.appendFileSync(envPath, `
562
+
563
+ BETTER_AUTH_SECRET=${secret}`);
564
+ }
565
+ if (!envContent.includes("BETTER_AUTH_URL")) {
566
+ fs5.appendFileSync(envPath, `
567
+ BETTER_AUTH_URL=http://localhost:3000
568
+ `);
569
+ }
570
+ const srcPath = path5.join(projectDir, "src");
571
+ const libPath = path5.join(srcPath, "lib");
572
+ if (!fs5.existsSync(libPath)) {
573
+ fs5.mkdirSync(libPath, { recursive: true });
574
+ }
575
+ const authTemplatePath = path5.resolve(
576
+ __dirname,
577
+ `./template/TanstackState/lib/${database}/auth.ts`
578
+ );
579
+ const authDestinationPath = path5.join(libPath, "auth.ts");
580
+ fs5.copyFileSync(authTemplatePath, authDestinationPath);
581
+ const authClientTemplatePath = path5.resolve(
582
+ __dirname,
583
+ "./template/lib/auth-client.ts"
584
+ );
585
+ const authClientDestinationPath = path5.join(libPath, "auth-client.ts");
586
+ fs5.copyFileSync(authClientTemplatePath, authClientDestinationPath);
587
+ const middlewarePath = path5.join(srcPath, "middleware");
588
+ if (!fs5.existsSync(middlewarePath)) {
589
+ fs5.mkdirSync(middlewarePath, { recursive: true });
590
+ }
591
+ const authMiddlewareTemplatePath = path5.resolve(
592
+ __dirname,
593
+ `./template/TanstackState/middleware/auth.ts`
594
+ );
595
+ const authMiddlewareDestinationPath = path5.join(middlewarePath, "auth.ts");
596
+ fs5.copyFileSync(authMiddlewareTemplatePath, authMiddlewareDestinationPath);
597
+ const fileRouteTemplatePath = path5.resolve(
598
+ __dirname,
599
+ `./template/TanstackState/routes/$.ts`
600
+ );
601
+ const fileRouteDestinationPath = path5.join(
602
+ srcPath,
603
+ "routes",
604
+ "api",
605
+ "auth"
606
+ );
607
+ if (!fs5.existsSync(fileRouteDestinationPath)) {
608
+ fs5.mkdirSync(fileRouteDestinationPath, { recursive: true });
609
+ }
610
+ const apiDestinationPath = path5.join(fileRouteDestinationPath, "$.ts");
611
+ fs5.copyFileSync(fileRouteTemplatePath, apiDestinationPath);
612
+ if (authUi) {
613
+ await authUiTanstackState();
614
+ } else {
615
+ console.log(
616
+ chalk5.green(
617
+ "\nPrisma setup completed successfully and better-auth installed\n"
618
+ )
619
+ );
620
+ }
621
+ } catch (err) {
622
+ console.log(chalk5.red("Prisma Run Tanstack State Error: ", err));
623
+ }
624
+ };
625
+
626
+ // script/drizzleRunTanstackState.ts
627
+ import chalk6 from "chalk";
628
+ import path6 from "path";
629
+ import fs6 from "fs";
630
+ import { fileURLToPath as fileURLToPath6 } from "url";
631
+ var drizzleRunTanstackState = async (authUi) => {
632
+ try {
633
+ const projectDir = process.cwd();
634
+ const packageJsonPath = path6.join(projectDir, "package.json");
635
+ const packageJson2 = JSON.parse(fs6.readFileSync(packageJsonPath, "utf-8"));
636
+ if (!packageJson2.dependencies["better-auth"]) {
637
+ console.log(chalk6.cyan("\n\u2699\uFE0F Initializing better auth...\n"));
638
+ packageManager("better-auth");
639
+ }
640
+ if (!packageJson2.dependencies["drizzle-orm"] && !packageJson2.dependencies["drizzle-orm"] && !packageJson2.dependencies["drizzle-kit"] && !packageJson2.devDependencies["drizzle-kit"]) {
641
+ console.log(chalk6.cyan("\n\u2699\uFE0F Initializing drizzle...\n"));
642
+ packageManager("drizzle-orm @neondatabase/serverless dotenv");
643
+ packageManager("drizzle-kit", true);
644
+ }
645
+ const __filename = fileURLToPath6(import.meta.url);
646
+ const __dirname = path6.dirname(__filename);
647
+ const envPath = path6.join(projectDir, ".env");
648
+ if (!fs6.existsSync(envPath)) {
649
+ fs6.writeFileSync(envPath, "DATABASE_URL=\n");
650
+ }
651
+ const secret = await GenerateSecret();
652
+ const envContent = fs6.readFileSync(envPath, "utf-8");
653
+ if (!envContent.includes("BETTER_AUTH_SECRET")) {
654
+ fs6.appendFileSync(envPath, `
655
+
656
+ BETTER_AUTH_SECRET=${secret}`);
657
+ }
658
+ if (!envContent.includes("BETTER_AUTH_URL")) {
659
+ fs6.appendFileSync(envPath, `
660
+ BETTER_AUTH_URL=http://localhost:3000
661
+ `);
662
+ }
663
+ const srcPath = path6.join(projectDir, "src");
664
+ const libPath = path6.join(srcPath, "lib");
665
+ if (!fs6.existsSync(libPath)) {
666
+ fs6.mkdirSync(libPath, { recursive: true });
667
+ }
668
+ const authTemplatePath = path6.resolve(
669
+ __dirname,
670
+ "./template/TanstackState/lib/auth-drizzle.ts"
671
+ );
672
+ const authDestinationPath = path6.join(libPath, "auth.ts");
673
+ fs6.copyFileSync(authTemplatePath, authDestinationPath);
674
+ const authClientTemplatePath = path6.resolve(
675
+ __dirname,
676
+ "./template/lib/auth-client.ts"
677
+ );
678
+ const authClientDestinationPath = path6.join(libPath, "auth-client.ts");
679
+ fs6.copyFileSync(authClientTemplatePath, authClientDestinationPath);
680
+ const dbTemplatePath = path6.resolve(__dirname, "./template/db");
681
+ const dbDir = path6.join(projectDir, "db");
682
+ if (!fs6.existsSync(dbDir)) {
683
+ fs6.mkdirSync(dbDir, { recursive: true });
684
+ }
685
+ const dbDestinationPath = path6.join(dbDir, "drizzle.ts");
686
+ fs6.copyFileSync(`${dbTemplatePath}/drizzle.ts`, dbDestinationPath);
687
+ const schemaDestinationPath = path6.join(dbDir, "schema.ts");
688
+ fs6.copyFileSync(`${dbTemplatePath}/schema.ts`, schemaDestinationPath);
689
+ const drizzleConfigTemplatePath = path6.resolve(
690
+ __dirname,
691
+ "./template/config/drizzle.config.ts"
692
+ );
693
+ const drizzleConfigDestinationPath = path6.join(
694
+ projectDir,
695
+ "drizzle.config.ts"
696
+ );
697
+ fs6.copyFileSync(drizzleConfigTemplatePath, drizzleConfigDestinationPath);
698
+ const middlewarePath = path6.join(srcPath, "middleware");
699
+ if (!fs6.existsSync(middlewarePath)) {
700
+ fs6.mkdirSync(middlewarePath, { recursive: true });
701
+ }
702
+ const authMiddlewareTemplatePath = path6.resolve(
703
+ __dirname,
704
+ `./template/TanstackState/middleware/auth.ts`
705
+ );
706
+ const authMiddlewareDestinationPath = path6.join(middlewarePath, "auth.ts");
707
+ fs6.copyFileSync(authMiddlewareTemplatePath, authMiddlewareDestinationPath);
708
+ const fileRouteTemplatePath = path6.resolve(
709
+ __dirname,
710
+ `./template/TanstackState/routes/$.ts`
711
+ );
712
+ const fileRouteDestinationPath = path6.join(
713
+ srcPath,
714
+ "routes",
715
+ "api",
716
+ "auth"
717
+ );
718
+ if (!fs6.existsSync(fileRouteDestinationPath)) {
719
+ fs6.mkdirSync(fileRouteDestinationPath, { recursive: true });
720
+ }
721
+ const apiDestinationPath = path6.join(fileRouteDestinationPath, "$.ts");
722
+ fs6.copyFileSync(fileRouteTemplatePath, apiDestinationPath);
723
+ if (authUi) {
724
+ await authUiTanstackState();
725
+ } else {
726
+ console.log(
727
+ chalk6.green(
728
+ "\nDrizzle setup completed successfully and better-auth installed\n"
729
+ )
730
+ );
731
+ }
732
+ } catch (err) {
733
+ console.error(chalk6.red("Drizzle setup failed:"), err);
734
+ }
735
+ };
736
+
409
737
  // cli/init.ts
410
738
  var initAnswer = async () => {
739
+ const projectDir = process.cwd();
740
+ const packageJsonPath = path7.join(projectDir, "package.json");
741
+ let framework = "tanstack state";
742
+ if (fs7.existsSync(packageJsonPath)) {
743
+ const packageJson2 = JSON.parse(fs7.readFileSync(packageJsonPath, "utf-8"));
744
+ const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
745
+ framework = hasNext ? "Next js" : "tanstack state";
746
+ }
747
+ console.log(`\u2714 Detected framework: ${framework}`);
411
748
  const answers = await inquirer.prompt([
412
749
  {
413
750
  type: "list",
@@ -429,47 +766,56 @@ var initAnswer = async () => {
429
766
  default: true
430
767
  }
431
768
  ]);
432
- if (answers.orm === "Prisma") {
769
+ if (framework === "Next js" && answers.orm === "Prisma") {
433
770
  await prismaRun({
434
771
  authUi: answers.authUi,
435
772
  database: answers.database
436
773
  });
437
774
  }
438
- if (answers.orm === "Drizzle") {
775
+ if (framework === "Next js" && answers.orm === "Drizzle") {
439
776
  await drizzleRun(answers.authUi);
440
777
  }
778
+ if (framework === "tanstack state" && answers.orm === "Prisma") {
779
+ await prismaRunTanstackState({
780
+ authUi: answers.authUi,
781
+ database: answers.database
782
+ });
783
+ }
784
+ if (framework === "tanstack state" && answers.orm === "Drizzle") {
785
+ await drizzleRunTanstackState(answers.authUi);
786
+ }
441
787
  };
442
788
 
443
789
  // index.ts
444
790
  import { readFileSync as readFileSync2 } from "fs";
445
791
 
446
792
  // cli/provider.ts
447
- import chalk6 from "chalk";
793
+ import chalk11 from "chalk";
448
794
 
449
795
  // script/googleRun.ts
450
- import chalk4 from "chalk";
451
- import fs4 from "fs";
452
- import path4 from "path";
453
- import { fileURLToPath as fileURLToPath4 } from "url";
796
+ import chalk7 from "chalk";
797
+ import fs8 from "fs";
798
+ import path8 from "path";
799
+ import { fileURLToPath as fileURLToPath7 } from "url";
454
800
  var googleRun = async () => {
455
801
  try {
456
- const __filename = fileURLToPath4(import.meta.url);
457
- const __dirname = path4.dirname(__filename);
802
+ const __filename = fileURLToPath7(import.meta.url);
803
+ const __dirname = path8.dirname(__filename);
458
804
  const projectDir = process.cwd();
459
- const srcPath = path4.join(projectDir, "src");
460
- const folder = fs4.existsSync(srcPath) ? "src" : "";
461
- const authFilePath = path4.join(projectDir, folder, "lib", "auth.ts");
462
- if (!fs4.existsSync(authFilePath)) {
463
- console.log(chalk4.red("\u274C auth.ts file not found"));
805
+ const srcPath = path8.join(projectDir, "src");
806
+ const folder = fs8.existsSync(srcPath) ? "src" : "";
807
+ const authFilePath = path8.join(projectDir, folder, "lib", "auth.ts");
808
+ if (!fs8.existsSync(authFilePath)) {
809
+ console.log(chalk7.red("\u274C auth.ts file not found"));
464
810
  return;
465
811
  }
466
- let content = fs4.readFileSync(authFilePath, "utf8");
812
+ let content = fs8.readFileSync(authFilePath, "utf8");
467
813
  if (!content.includes("betterAuth({")) {
468
- console.log(chalk4.red("betterAuth({}) block not found"));
814
+ console.log(chalk7.red("betterAuth({}) block not found"));
469
815
  return;
470
816
  }
471
817
  if (content.includes("socialProviders") && content.includes("google:")) {
472
- console.log(chalk4.yellow("Google provider already exists"));
818
+ console.log(chalk7.yellow("Google provider already exists"));
473
819
  return;
474
820
  }
475
821
  const googleProviderEntry = `
@@ -492,7 +838,7 @@ var googleRun = async () => {
492
838
  }
493
839
  }
494
840
  if (insertPos === -1) {
495
- console.log(chalk4.red("Failed to parse socialProviders block"));
841
+ console.log(chalk7.red("Failed to parse socialProviders block"));
496
842
  return;
497
843
  }
498
844
  content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
@@ -500,7 +846,7 @@ var googleRun = async () => {
500
846
  const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
501
847
  if (!databaseRegex.test(content)) {
502
848
  console.log(
503
- chalk4.red(
849
+ chalk7.red(
504
850
  "Could not find database adapter (prismaAdapter or drizzleAdapter)"
505
851
  )
506
852
  );
@@ -516,12 +862,12 @@ ${googleProviderEntry}
516
862
  ${socialProvidersBlock}`
517
863
  );
518
864
  }
519
- fs4.writeFileSync(authFilePath, content, "utf8");
520
- const envPath = path4.join(projectDir, ".env");
521
- if (fs4.existsSync(envPath)) {
522
- const envContent = fs4.readFileSync(envPath, "utf8");
865
+ fs8.writeFileSync(authFilePath, content, "utf8");
866
+ const envPath = path8.join(projectDir, ".env");
867
+ if (fs8.existsSync(envPath)) {
868
+ const envContent = fs8.readFileSync(envPath, "utf8");
523
869
  if (!envContent.includes("GOOGLE_CLIENT_ID")) {
524
- fs4.appendFileSync(
870
+ fs8.appendFileSync(
525
871
  envPath,
526
872
  `
527
873
 
@@ -532,53 +878,53 @@ GOOGLE_CLIENT_SECRET=
532
878
  );
533
879
  }
534
880
  }
535
- const componentTemplate = path4.resolve(
881
+ const componentTemplate = path8.resolve(
536
882
  __dirname,
537
883
  "./template/components/GoogleProviders.tsx"
538
884
  );
539
- const componentsDir = path4.join(
885
+ const componentsDir = path8.join(
540
886
  projectDir,
541
887
  folder,
542
888
  "components",
543
889
  "authverse"
544
890
  );
545
- if (!fs4.existsSync(componentsDir)) {
546
- fs4.mkdirSync(componentsDir, { recursive: true });
891
+ if (!fs8.existsSync(componentsDir)) {
892
+ fs8.mkdirSync(componentsDir, { recursive: true });
547
893
  }
548
- const componentDest = path4.join(componentsDir, "GoogleProviders.tsx");
549
- if (fs4.existsSync(componentTemplate)) {
550
- fs4.copyFileSync(componentTemplate, componentDest);
894
+ const componentDest = path8.join(componentsDir, "GoogleProviders.tsx");
895
+ if (fs8.existsSync(componentTemplate)) {
896
+ fs8.copyFileSync(componentTemplate, componentDest);
551
897
  }
552
- console.log(chalk4.green("Google provider added & merged successfully"));
898
+ console.log(chalk7.green("Google provider added & merged successfully"));
553
899
  } catch (error) {
554
- console.log(chalk4.red("googleRun error:"), error);
900
+ console.log(chalk7.red("googleRun error:"), error);
555
901
  }
556
902
  };
557
903
 
558
904
  // script/githubRun.ts
559
- import chalk5 from "chalk";
560
- import fs5 from "fs";
561
- import path5 from "path";
562
- import { fileURLToPath as fileURLToPath5 } from "url";
905
+ import chalk8 from "chalk";
906
+ import fs9 from "fs";
907
+ import path9 from "path";
908
+ import { fileURLToPath as fileURLToPath8 } from "url";
563
909
  var githubRun = async () => {
564
910
  try {
565
- const __filename = fileURLToPath5(import.meta.url);
566
- const __dirname = path5.dirname(__filename);
911
+ const __filename = fileURLToPath8(import.meta.url);
912
+ const __dirname = path9.dirname(__filename);
567
913
  const projectDir = process.cwd();
568
- const srcPath = path5.join(projectDir, "src");
569
- const folder = fs5.existsSync(srcPath) ? "src" : "";
570
- const authFilePath = path5.join(projectDir, folder, "lib", "auth.ts");
571
- if (!fs5.existsSync(authFilePath)) {
572
- console.log(chalk5.red("auth.ts file not found"));
914
+ const srcPath = path9.join(projectDir, "src");
915
+ const folder = fs9.existsSync(srcPath) ? "src" : "";
916
+ const authFilePath = path9.join(projectDir, folder, "lib", "auth.ts");
917
+ if (!fs9.existsSync(authFilePath)) {
918
+ console.log(chalk8.red("auth.ts file not found"));
573
919
  return;
574
920
  }
575
- let content = fs5.readFileSync(authFilePath, "utf8");
921
+ let content = fs9.readFileSync(authFilePath, "utf8");
576
922
  if (!content.includes("betterAuth({")) {
577
- console.log(chalk5.red("betterAuth({}) block not found"));
923
+ console.log(chalk8.red("betterAuth({}) block not found"));
578
924
  return;
579
925
  }
580
926
  if (content.includes("socialProviders") && content.includes("github:")) {
581
- console.log(chalk5.yellow("GitHub provider already exists"));
927
+ console.log(chalk8.yellow("GitHub provider already exists"));
582
928
  return;
583
929
  }
584
930
  const githubProviderEntry = `
@@ -601,7 +947,7 @@ var githubRun = async () => {
601
947
  }
602
948
  }
603
949
  if (insertPos === -1) {
604
- console.log(chalk5.red("Failed to parse socialProviders block"));
950
+ console.log(chalk8.red("Failed to parse socialProviders block"));
605
951
  return;
606
952
  }
607
953
  content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
@@ -609,7 +955,7 @@ var githubRun = async () => {
609
955
  const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
610
956
  if (!databaseRegex.test(content)) {
611
957
  console.log(
612
- chalk5.red(
958
+ chalk8.red(
613
959
  "Could not find database adapter (prismaAdapter or drizzleAdapter)"
614
960
  )
615
961
  );
@@ -625,12 +971,12 @@ ${githubProviderEntry}
625
971
  ${socialProvidersBlock}`
626
972
  );
627
973
  }
628
- fs5.writeFileSync(authFilePath, content, "utf8");
629
- const envPath = path5.join(projectDir, ".env");
630
- if (fs5.existsSync(envPath)) {
631
- const envContent = fs5.readFileSync(envPath, "utf8");
974
+ fs9.writeFileSync(authFilePath, content, "utf8");
975
+ const envPath = path9.join(projectDir, ".env");
976
+ if (fs9.existsSync(envPath)) {
977
+ const envContent = fs9.readFileSync(envPath, "utf8");
632
978
  if (!envContent.includes("GITHUB_CLIENT_ID")) {
633
- fs5.appendFileSync(
979
+ fs9.appendFileSync(
634
980
  envPath,
635
981
  `
636
982
 
@@ -641,70 +987,297 @@ GITHUB_CLIENT_SECRET=
641
987
  );
642
988
  }
643
989
  }
644
- const componentTemplate = path5.resolve(
990
+ const componentTemplate = path9.resolve(
645
991
  __dirname,
646
992
  "./template/components/GithubProviders.tsx"
647
993
  );
648
- const componentsDir = path5.join(
994
+ const componentsDir = path9.join(
649
995
  projectDir,
650
996
  folder,
651
997
  "components",
652
998
  "authverse"
653
999
  );
654
- if (!fs5.existsSync(componentsDir)) {
655
- fs5.mkdirSync(componentsDir, { recursive: true });
1000
+ if (!fs9.existsSync(componentsDir)) {
1001
+ fs9.mkdirSync(componentsDir, { recursive: true });
656
1002
  }
657
- const componentDest = path5.join(componentsDir, "GithubProviders.tsx");
658
- if (fs5.existsSync(componentTemplate)) {
659
- fs5.copyFileSync(componentTemplate, componentDest);
1003
+ const componentDest = path9.join(componentsDir, "GithubProviders.tsx");
1004
+ if (fs9.existsSync(componentTemplate)) {
1005
+ fs9.copyFileSync(componentTemplate, componentDest);
660
1006
  }
661
- console.log(chalk5.green("GitHub provider added & merged successfully"));
1007
+ console.log(chalk8.green("GitHub provider added & merged successfully"));
662
1008
  } catch (error) {
663
- console.log(chalk5.red("githubRun error:"), error);
1009
+ console.log(chalk8.red("githubRun error:"), error);
1010
+ }
1011
+ };
1012
+
1013
+ // cli/provider.ts
1014
+ import path12 from "path";
1015
+ import fs12 from "fs";
1016
+
1017
+ // script/googleRunTanstackState.ts
1018
+ import chalk9 from "chalk";
1019
+ import fs10 from "fs";
1020
+ import path10 from "path";
1021
+ import { fileURLToPath as fileURLToPath9 } from "url";
1022
+ var googleRunTanstackState = async () => {
1023
+ try {
1024
+ const __filename = fileURLToPath9(import.meta.url);
1025
+ const __dirname = path10.dirname(__filename);
1026
+ const projectDir = process.cwd();
1027
+ const srcPath = path10.join(projectDir, "src");
1028
+ const authFilePath = path10.join(srcPath, "lib", "auth.ts");
1029
+ if (!fs10.existsSync(authFilePath)) {
1030
+ console.log(chalk9.red("auth.ts file not found"));
1031
+ return;
1032
+ }
1033
+ let content = fs10.readFileSync(authFilePath, "utf8");
1034
+ if (!content.includes("betterAuth({")) {
1035
+ console.log(chalk9.red("betterAuth({}) block not found"));
1036
+ return;
1037
+ }
1038
+ if (content.includes("socialProviders") && content.includes("google:")) {
1039
+ console.log(chalk9.yellow("Google provider already exists"));
1040
+ return;
1041
+ }
1042
+ const googleProviderEntry = `
1043
+ google: {
1044
+ clientId: process.env.GOOGLE_CLIENT_ID as string,
1045
+ clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
1046
+ },`;
1047
+ if (content.includes("socialProviders: {")) {
1048
+ const start = content.indexOf("socialProviders: {");
1049
+ let braceCount = 0;
1050
+ let insertPos = -1;
1051
+ for (let i = start; i < content.length; i++) {
1052
+ if (content[i] === "{") braceCount++;
1053
+ if (content[i] === "}") {
1054
+ braceCount--;
1055
+ if (braceCount === 0) {
1056
+ insertPos = i;
1057
+ break;
1058
+ }
1059
+ }
1060
+ }
1061
+ if (insertPos === -1) {
1062
+ console.log(chalk9.red("Failed to parse socialProviders block"));
1063
+ return;
1064
+ }
1065
+ content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
1066
+ } else {
1067
+ const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
1068
+ if (!databaseRegex.test(content)) {
1069
+ console.log(
1070
+ chalk9.red(
1071
+ "Could not find database adapter (prismaAdapter or drizzleAdapter)"
1072
+ )
1073
+ );
1074
+ return;
1075
+ }
1076
+ const socialProvidersBlock = `
1077
+ socialProviders: {
1078
+ ${googleProviderEntry}
1079
+ },`;
1080
+ content = content.replace(
1081
+ databaseRegex,
1082
+ (match) => `${match}
1083
+ ${socialProvidersBlock}`
1084
+ );
1085
+ }
1086
+ fs10.writeFileSync(authFilePath, content, "utf8");
1087
+ const envPath = path10.join(projectDir, ".env");
1088
+ if (fs10.existsSync(envPath)) {
1089
+ const envContent = fs10.readFileSync(envPath, "utf8");
1090
+ if (!envContent.includes("GOOGLE_CLIENT_ID")) {
1091
+ fs10.appendFileSync(
1092
+ envPath,
1093
+ `
1094
+
1095
+ # Google OAuth
1096
+ GOOGLE_CLIENT_ID=
1097
+ GOOGLE_CLIENT_SECRET=
1098
+ `
1099
+ );
1100
+ }
1101
+ }
1102
+ const componentTemplate = path10.resolve(
1103
+ __dirname,
1104
+ "./template/TanstackState/components/GoogleProviders.tsx"
1105
+ );
1106
+ const componentsDir = path10.join(srcPath, "components", "authverse");
1107
+ if (!fs10.existsSync(componentsDir)) {
1108
+ fs10.mkdirSync(componentsDir, { recursive: true });
1109
+ }
1110
+ const componentDest = path10.join(componentsDir, "GoogleProviders.tsx");
1111
+ if (fs10.existsSync(componentTemplate)) {
1112
+ fs10.copyFileSync(componentTemplate, componentDest);
1113
+ }
1114
+ console.log(chalk9.green("Google provider added & merged successfully"));
1115
+ } catch (error) {
1116
+ console.log(chalk9.red("googleRunTanstackState error:"), error);
1117
+ }
1118
+ };
1119
+
1120
+ // script/githubRunTanstackState.ts
1121
+ import chalk10 from "chalk";
1122
+ import fs11 from "fs";
1123
+ import path11 from "path";
1124
+ import { fileURLToPath as fileURLToPath10 } from "url";
1125
+ var githubRunTanstackState = async () => {
1126
+ try {
1127
+ const __filename = fileURLToPath10(import.meta.url);
1128
+ const __dirname = path11.dirname(__filename);
1129
+ const projectDir = process.cwd();
1130
+ const srcPath = path11.join(projectDir, "src");
1131
+ const authFilePath = path11.join(srcPath, "lib", "auth.ts");
1132
+ if (!fs11.existsSync(authFilePath)) {
1133
+ console.log(chalk10.red("auth.ts file not found"));
1134
+ return;
1135
+ }
1136
+ let content = fs11.readFileSync(authFilePath, "utf8");
1137
+ if (!content.includes("betterAuth({")) {
1138
+ console.log(chalk10.red("betterAuth({}) block not found"));
1139
+ return;
1140
+ }
1141
+ if (content.includes("socialProviders") && content.includes("github:")) {
1142
+ console.log(chalk10.yellow("Github provider already exists"));
1143
+ return;
1144
+ }
1145
+ const githubProviderEntry = `
1146
+ github: {
1147
+ clientId: process.env.GITHUB_CLIENT_ID as string,
1148
+ clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
1149
+ },`;
1150
+ if (content.includes("socialProviders: {")) {
1151
+ const start = content.indexOf("socialProviders: {");
1152
+ let braceCount = 0;
1153
+ let insertPos = -1;
1154
+ for (let i = start; i < content.length; i++) {
1155
+ if (content[i] === "{") braceCount++;
1156
+ if (content[i] === "}") {
1157
+ braceCount--;
1158
+ if (braceCount === 0) {
1159
+ insertPos = i;
1160
+ break;
1161
+ }
1162
+ }
1163
+ }
1164
+ if (insertPos === -1) {
1165
+ console.log(chalk10.red("Failed to parse socialProviders block"));
1166
+ return;
1167
+ }
1168
+ content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
1169
+ } else {
1170
+ const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
1171
+ if (!databaseRegex.test(content)) {
1172
+ console.log(
1173
+ chalk10.red(
1174
+ "Could not find database adapter (prismaAdapter or drizzleAdapter)"
1175
+ )
1176
+ );
1177
+ return;
1178
+ }
1179
+ const socialProvidersBlock = `
1180
+ socialProviders: {
1181
+ ${githubProviderEntry}
1182
+ },`;
1183
+ content = content.replace(
1184
+ databaseRegex,
1185
+ (match) => `${match}
1186
+ ${socialProvidersBlock}`
1187
+ );
1188
+ }
1189
+ fs11.writeFileSync(authFilePath, content, "utf8");
1190
+ const envPath = path11.join(projectDir, ".env");
1191
+ if (fs11.existsSync(envPath)) {
1192
+ const envContent = fs11.readFileSync(envPath, "utf8");
1193
+ if (!envContent.includes("GITHUB_CLIENT_ID")) {
1194
+ fs11.appendFileSync(
1195
+ envPath,
1196
+ `
1197
+
1198
+ # Github OAuth
1199
+ GITHUB_CLIENT_ID=
1200
+ GITHUB_CLIENT_SECRET=
1201
+ `
1202
+ );
1203
+ }
1204
+ }
1205
+ const componentTemplate = path11.resolve(
1206
+ __dirname,
1207
+ "./template/TanstackState/components/GithubProviders.tsx"
1208
+ );
1209
+ const componentsDir = path11.join(srcPath, "components", "authverse");
1210
+ if (!fs11.existsSync(componentsDir)) {
1211
+ fs11.mkdirSync(componentsDir, { recursive: true });
1212
+ }
1213
+ const componentDest = path11.join(componentsDir, "GithubProviders.tsx");
1214
+ if (fs11.existsSync(componentTemplate)) {
1215
+ fs11.copyFileSync(componentTemplate, componentDest);
1216
+ }
1217
+ console.log(chalk10.green("Github provider added & merged successfully"));
1218
+ } catch (error) {
1219
+ console.log(chalk10.red("githubRunTanstackState error:"), error);
664
1220
  }
665
1221
  };
666
1222
 
667
1223
  // cli/provider.ts
668
1224
  var providers = async ({ provider }) => {
669
1225
  try {
670
- if (provider == "google") {
1226
+ const projectDir = process.cwd();
1227
+ const packageJsonPath = path12.join(projectDir, "package.json");
1228
+ let framework = "tanstack state";
1229
+ if (fs12.existsSync(packageJsonPath)) {
1230
+ const packageJson2 = JSON.parse(fs12.readFileSync(packageJsonPath, "utf-8"));
1231
+ const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
1232
+ framework = hasNext ? "Next js" : "tanstack state";
1233
+ }
1234
+ if (framework === "Next js" && provider == "google") {
671
1235
  await googleRun();
672
- } else if (provider == "github") {
1236
+ } else if (framework === "Next js" && provider == "github") {
673
1237
  await githubRun();
674
1238
  }
1239
+ if (framework === "tanstack state" && provider == "google") {
1240
+ await googleRunTanstackState();
1241
+ } else if (framework === "tanstack state" && provider == "github") {
1242
+ await githubRunTanstackState();
1243
+ }
675
1244
  } catch (error) {
676
- console.log(chalk6.red("Error adding provider:"), error);
1245
+ console.log(chalk11.red("Error adding provider:"), error);
677
1246
  }
678
1247
  };
679
1248
 
680
1249
  // cli/forget.ts
681
- import chalk7 from "chalk";
682
- import path6 from "path";
683
- import { fileURLToPath as fileURLToPath6 } from "url";
684
- import fs6 from "fs";
685
- var forget = async () => {
1250
+ import path15 from "path";
1251
+ import fs15 from "fs";
1252
+
1253
+ // script/forgetNext.ts
1254
+ import chalk12 from "chalk";
1255
+ import path13 from "path";
1256
+ import { fileURLToPath as fileURLToPath11 } from "url";
1257
+ import fs13 from "fs";
1258
+ var forgetNext = async () => {
686
1259
  try {
687
1260
  const projectDir = process.cwd();
688
- const packageJsonPath = path6.join(projectDir, "package.json");
689
- const packageJson2 = JSON.parse(fs6.readFileSync(packageJsonPath, "utf-8"));
1261
+ const packageJsonPath = path13.join(projectDir, "package.json");
1262
+ const packageJson2 = JSON.parse(fs13.readFileSync(packageJsonPath, "utf-8"));
690
1263
  if (!packageJson2.dependencies?.resend) {
691
- console.log(chalk7.cyan("\n\u2699\uFE0F Installing Resend...\n"));
1264
+ console.log(chalk12.cyan("\n\u2699\uFE0F Installing Resend...\n"));
692
1265
  packageManager("resend");
693
1266
  }
694
1267
  if (!packageJson2.dependencies?.["@react-email/components"]) {
695
- console.log(chalk7.cyan("\n\u2699\uFE0F Installing react email components...\n"));
1268
+ console.log(chalk12.cyan("\n\u2699\uFE0F Installing react email components...\n"));
696
1269
  packageManager("@react-email/components");
697
1270
  }
698
- const __filename = fileURLToPath6(import.meta.url);
699
- const __dirname = path6.dirname(__filename);
700
- const srcPath = path6.join(projectDir, "src");
701
- const folder = fs6.existsSync(srcPath) ? "src" : "";
702
- const authFilePath = path6.join(projectDir, folder, "lib", "auth.ts");
703
- if (!fs6.existsSync(authFilePath)) {
704
- console.log(chalk7.red("auth.ts file not found."));
1271
+ const __filename = fileURLToPath11(import.meta.url);
1272
+ const __dirname = path13.dirname(__filename);
1273
+ const srcPath = path13.join(projectDir, "src");
1274
+ const folder = fs13.existsSync(srcPath) ? "src" : "";
1275
+ const authFilePath = path13.join(projectDir, folder, "lib", "auth.ts");
1276
+ if (!fs13.existsSync(authFilePath)) {
1277
+ console.log(chalk12.red("auth.ts file not found."));
705
1278
  return;
706
1279
  }
707
- let content = fs6.readFileSync(authFilePath, "utf8");
1280
+ let content = fs13.readFileSync(authFilePath, "utf8");
708
1281
  const codeAdded = `sendResetPassword: async ({ user, url, token }) => {
709
1282
  await resend.emails.send({
710
1283
  from: \`\${process.env.EMAIL_SENDER_NAME} <\${process.env.EMAIL_SENDER_ADDRESS}>\`,
@@ -749,7 +1322,7 @@ var forget = async () => {
749
1322
  content = before + `
750
1323
  ${codeAdded}` + after;
751
1324
  }
752
- fs6.writeFileSync(authFilePath, content, "utf8");
1325
+ fs13.writeFileSync(authFilePath, content, "utf8");
753
1326
  if (!content.includes("import { Resend }") && !content.includes("const resend = new Resend")) {
754
1327
  const lastImportIndex = content.lastIndexOf("import");
755
1328
  const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
@@ -761,117 +1334,315 @@ import ForgotPasswordEmail from "@/components/email/reset-password";
761
1334
  const resend = new Resend(process.env.RESEND_API_KEY as string);
762
1335
  `;
763
1336
  content = beforeImports + newImports + afterImports;
764
- fs6.writeFileSync(authFilePath, content, "utf8");
1337
+ fs13.writeFileSync(authFilePath, content, "utf8");
765
1338
  }
766
- const envPath = path6.join(projectDir, ".env");
767
- const envContent = fs6.readFileSync(envPath, "utf8");
1339
+ const envPath = path13.join(projectDir, ".env");
1340
+ const envContent = fs13.readFileSync(envPath, "utf8");
768
1341
  if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
769
- fs6.appendFileSync(envPath, `
1342
+ fs13.appendFileSync(envPath, `
770
1343
 
771
1344
  # Resend API Key for sending emails`);
772
- fs6.appendFileSync(envPath, `
1345
+ fs13.appendFileSync(envPath, `
773
1346
  RESEND_API_KEY=`);
774
- fs6.appendFileSync(envPath, `
1347
+ fs13.appendFileSync(envPath, `
775
1348
  EMAIL_SENDER_NAME=Your Name`);
776
- fs6.appendFileSync(envPath, `
1349
+ fs13.appendFileSync(envPath, `
777
1350
  EMAIL_SENDER_ADDRESS=`);
778
1351
  }
779
- const componentPath = path6.resolve(
1352
+ const componentPath = path13.resolve(
780
1353
  __dirname,
781
1354
  "./template/email/reset-password.tsx"
782
1355
  );
783
- const destinationPath = path6.join(
1356
+ const destinationPath = path13.join(
784
1357
  projectDir,
785
1358
  folder,
786
1359
  "components",
787
1360
  "email"
788
1361
  );
789
- if (!fs6.existsSync(destinationPath)) {
790
- fs6.mkdirSync(destinationPath, { recursive: true });
1362
+ if (!fs13.existsSync(destinationPath)) {
1363
+ fs13.mkdirSync(destinationPath, { recursive: true });
791
1364
  }
792
- const emailDestinationPath = path6.join(
1365
+ const emailDestinationPath = path13.join(
793
1366
  destinationPath,
794
1367
  "reset-password.tsx"
795
1368
  );
796
- if (fs6.existsSync(componentPath)) {
797
- fs6.copyFileSync(componentPath, emailDestinationPath);
1369
+ if (fs13.existsSync(componentPath)) {
1370
+ fs13.copyFileSync(componentPath, emailDestinationPath);
798
1371
  }
799
- const forgetComponentPath = path6.resolve(
1372
+ const forgetComponentPath = path13.resolve(
800
1373
  __dirname,
801
1374
  "./template/components/ForgetComponent.tsx"
802
1375
  );
803
- const componentsDestinationPath = path6.join(
1376
+ const componentsDestinationPath = path13.join(
804
1377
  projectDir,
805
1378
  folder,
806
1379
  "components",
807
1380
  "authverse"
808
1381
  );
809
- if (!fs6.existsSync(componentsDestinationPath)) {
810
- fs6.mkdirSync(componentsDestinationPath, { recursive: true });
1382
+ if (!fs13.existsSync(componentsDestinationPath)) {
1383
+ fs13.mkdirSync(componentsDestinationPath, { recursive: true });
811
1384
  }
812
- const forgetDestinationPath = path6.join(
1385
+ const forgetDestinationPath = path13.join(
813
1386
  componentsDestinationPath,
814
1387
  "ForgetComponent.tsx"
815
1388
  );
816
- if (fs6.existsSync(forgetComponentPath)) {
817
- fs6.copyFileSync(forgetComponentPath, forgetDestinationPath);
1389
+ if (fs13.existsSync(forgetComponentPath)) {
1390
+ fs13.copyFileSync(forgetComponentPath, forgetDestinationPath);
818
1391
  }
819
- const resetComponentPath = path6.resolve(
1392
+ const resetComponentPath = path13.resolve(
820
1393
  __dirname,
821
1394
  "./template/components/ResetComponent.tsx"
822
1395
  );
823
- const resetDestinationPath = path6.join(
1396
+ const resetDestinationPath = path13.join(
824
1397
  componentsDestinationPath,
825
1398
  "ResetComponent.tsx"
826
1399
  );
827
- if (fs6.existsSync(resetComponentPath)) {
828
- fs6.copyFileSync(resetComponentPath, resetDestinationPath);
1400
+ if (fs13.existsSync(resetComponentPath)) {
1401
+ fs13.copyFileSync(resetComponentPath, resetDestinationPath);
829
1402
  }
830
- const authTemplatePath = path6.resolve(
1403
+ const authTemplatePath = path13.resolve(
831
1404
  __dirname,
832
1405
  "./template/app-auth-uiDesign"
833
1406
  );
834
- const appDestinationPath = path6.join(projectDir, folder, "app", "auth");
835
- if (!fs6.existsSync(appDestinationPath)) {
836
- fs6.mkdirSync(appDestinationPath, { recursive: true });
1407
+ const appDestinationPath = path13.join(projectDir, folder, "app", "auth");
1408
+ if (!fs13.existsSync(appDestinationPath)) {
1409
+ fs13.mkdirSync(appDestinationPath, { recursive: true });
837
1410
  }
838
- const forgetDestinationDir = path6.join(appDestinationPath, "forget");
839
- if (!fs6.existsSync(forgetDestinationDir)) {
840
- fs6.mkdirSync(forgetDestinationDir, { recursive: true });
1411
+ const forgetDestinationDir = path13.join(appDestinationPath, "forget");
1412
+ if (!fs13.existsSync(forgetDestinationDir)) {
1413
+ fs13.mkdirSync(forgetDestinationDir, { recursive: true });
841
1414
  }
842
- const forgetPageDestinationPath = path6.join(
1415
+ const forgetPageDestinationPath = path13.join(
843
1416
  forgetDestinationDir,
844
1417
  "page.tsx"
845
1418
  );
846
- fs6.copyFileSync(
1419
+ fs13.copyFileSync(
847
1420
  `${authTemplatePath}/forget/page.tsx`,
848
1421
  forgetPageDestinationPath
849
1422
  );
850
- const resetDestinationDir = path6.join(
1423
+ const resetDestinationDir = path13.join(
851
1424
  appDestinationPath,
852
1425
  "reset-password"
853
1426
  );
854
- if (!fs6.existsSync(resetDestinationDir)) {
855
- fs6.mkdirSync(resetDestinationDir, { recursive: true });
1427
+ if (!fs13.existsSync(resetDestinationDir)) {
1428
+ fs13.mkdirSync(resetDestinationDir, { recursive: true });
856
1429
  }
857
- const resetPageDestinationPath = path6.join(
1430
+ const resetPageDestinationPath = path13.join(
858
1431
  resetDestinationDir,
859
1432
  "page.tsx"
860
1433
  );
861
- fs6.copyFileSync(
1434
+ fs13.copyFileSync(
862
1435
  `${authTemplatePath}/reset-password/page.tsx`,
863
1436
  resetPageDestinationPath
864
1437
  );
865
1438
  console.log(
866
- chalk7.green("Successfully added forget and reset-password pages")
1439
+ chalk12.green("Successfully added forget and reset-password pages")
1440
+ );
1441
+ } else {
1442
+ console.log(
1443
+ chalk12.red("Could not find emailAndPassword configuration in auth.ts")
1444
+ );
1445
+ }
1446
+ } catch (error) {
1447
+ console.log(chalk12.red("Error adding sendResetPassword:"), error);
1448
+ }
1449
+ };
1450
+
1451
+ // script/forgetTanstack.ts
1452
+ import chalk13 from "chalk";
1453
+ import path14 from "path";
1454
+ import { fileURLToPath as fileURLToPath12 } from "url";
1455
+ import fs14 from "fs";
1456
+ var forgetTanstack = async () => {
1457
+ try {
1458
+ const projectDir = process.cwd();
1459
+ const packageJsonPath = path14.join(projectDir, "package.json");
1460
+ const packageJson2 = JSON.parse(fs14.readFileSync(packageJsonPath, "utf-8"));
1461
+ if (!packageJson2.dependencies?.resend) {
1462
+ console.log(chalk13.cyan("\n\u2699\uFE0F Installing Resend...\n"));
1463
+ packageManager("resend");
1464
+ }
1465
+ if (!packageJson2.dependencies?.["@react-email/components"]) {
1466
+ console.log(chalk13.cyan("\n\u2699\uFE0F Installing react email components...\n"));
1467
+ packageManager("@react-email/components");
1468
+ }
1469
+ const __filename = fileURLToPath12(import.meta.url);
1470
+ const __dirname = path14.dirname(__filename);
1471
+ const srcPath = path14.join(projectDir, "src");
1472
+ const authFilePath = path14.join(srcPath, "lib", "auth.ts");
1473
+ if (!fs14.existsSync(authFilePath)) {
1474
+ console.log(chalk13.red("auth.ts file not found."));
1475
+ return;
1476
+ }
1477
+ let content = fs14.readFileSync(authFilePath, "utf8");
1478
+ const codeAdded = `sendResetPassword: async ({ user, url, token }) => {
1479
+ await resend.emails.send({
1480
+ from: \`\${process.env.EMAIL_SENDER_NAME} <\${process.env.EMAIL_SENDER_ADDRESS}>\`,
1481
+ to: user.email,
1482
+ subject: "Reset your password",
1483
+ react: ForgotPasswordEmail({
1484
+ username: user.name,
1485
+ resetUrl: url,
1486
+ userEmail: user.email,
1487
+ }),
1488
+ });
1489
+ },`;
1490
+ if (content.includes("emailAndPassword: {")) {
1491
+ const emailAndPasswordStart = content.indexOf("emailAndPassword: {");
1492
+ let emailAndPasswordEnd = emailAndPasswordStart;
1493
+ let braceCount = 0;
1494
+ let inEmailAndPassword = false;
1495
+ for (let i = emailAndPasswordStart; i < content.length; i++) {
1496
+ if (content[i] === "{") {
1497
+ braceCount++;
1498
+ inEmailAndPassword = true;
1499
+ } else if (content[i] === "}") {
1500
+ braceCount--;
1501
+ if (inEmailAndPassword && braceCount === 0) {
1502
+ emailAndPasswordEnd = i;
1503
+ break;
1504
+ }
1505
+ }
1506
+ }
1507
+ const emailAndPasswordContent = content.substring(
1508
+ emailAndPasswordStart,
1509
+ emailAndPasswordEnd
1510
+ );
1511
+ if (emailAndPasswordContent.includes("sendResetPassword:")) {
1512
+ content = content.replace(
1513
+ /sendResetPassword:\s*async\s*\([^)]*\)[^{]*\{[^}]*\}[^,]*/,
1514
+ codeAdded
1515
+ );
1516
+ } else {
1517
+ const before = content.substring(0, emailAndPasswordEnd);
1518
+ const after = content.substring(emailAndPasswordEnd);
1519
+ content = before + `
1520
+ ${codeAdded}` + after;
1521
+ }
1522
+ fs14.writeFileSync(authFilePath, content, "utf8");
1523
+ if (!content.includes("import { Resend }") && !content.includes("const resend = new Resend")) {
1524
+ const lastImportIndex = content.lastIndexOf("import");
1525
+ const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
1526
+ const beforeImports = content.substring(0, nextLineAfterLastImport);
1527
+ const afterImports = content.substring(nextLineAfterLastImport);
1528
+ const newImports = `import { Resend } from "resend";
1529
+ import ForgotPasswordEmail from "@/components/email/reset-password";
1530
+
1531
+ const resend = new Resend(process.env.RESEND_API_KEY as string);
1532
+ `;
1533
+ content = beforeImports + newImports + afterImports;
1534
+ fs14.writeFileSync(authFilePath, content, "utf8");
1535
+ }
1536
+ const envPath = path14.join(projectDir, ".env");
1537
+ const envContent = fs14.readFileSync(envPath, "utf8");
1538
+ if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
1539
+ fs14.appendFileSync(envPath, `
1540
+
1541
+ # Resend API Key for sending emails`);
1542
+ fs14.appendFileSync(envPath, `
1543
+ RESEND_API_KEY=`);
1544
+ fs14.appendFileSync(envPath, `
1545
+ EMAIL_SENDER_NAME=Your Name`);
1546
+ fs14.appendFileSync(envPath, `
1547
+ EMAIL_SENDER_ADDRESS=`);
1548
+ }
1549
+ const componentPath = path14.resolve(
1550
+ __dirname,
1551
+ "./template/email/reset-password.tsx"
1552
+ );
1553
+ const destinationPath = path14.join(srcPath, "components", "email");
1554
+ if (!fs14.existsSync(destinationPath)) {
1555
+ fs14.mkdirSync(destinationPath, { recursive: true });
1556
+ }
1557
+ const emailDestinationPath = path14.join(
1558
+ destinationPath,
1559
+ "reset-password.tsx"
1560
+ );
1561
+ if (fs14.existsSync(componentPath)) {
1562
+ fs14.copyFileSync(componentPath, emailDestinationPath);
1563
+ }
1564
+ const forgetComponentPath = path14.resolve(
1565
+ __dirname,
1566
+ "./template/TanstackState/components/ForgetComponent.tsx"
1567
+ );
1568
+ const componentsDestinationPath = path14.join(
1569
+ srcPath,
1570
+ "components",
1571
+ "authverse"
1572
+ );
1573
+ if (!fs14.existsSync(componentsDestinationPath)) {
1574
+ fs14.mkdirSync(componentsDestinationPath, { recursive: true });
1575
+ }
1576
+ const forgetDestinationPath = path14.join(
1577
+ componentsDestinationPath,
1578
+ "ForgetComponent.tsx"
1579
+ );
1580
+ if (fs14.existsSync(forgetComponentPath)) {
1581
+ fs14.copyFileSync(forgetComponentPath, forgetDestinationPath);
1582
+ }
1583
+ const resetComponentPath = path14.resolve(
1584
+ __dirname,
1585
+ "./template/TanstackState/components/ResetComponent.tsx"
1586
+ );
1587
+ const resetDestinationPath = path14.join(
1588
+ componentsDestinationPath,
1589
+ "ResetComponent.tsx"
1590
+ );
1591
+ if (fs14.existsSync(resetComponentPath)) {
1592
+ fs14.copyFileSync(resetComponentPath, resetDestinationPath);
1593
+ }
1594
+ const authTemplatePath = path14.resolve(
1595
+ __dirname,
1596
+ "./template/TanstackState/routes/auth"
1597
+ );
1598
+ const routesDestinationPath = path14.join(srcPath, "routes", "auth");
1599
+ if (!fs14.existsSync(routesDestinationPath)) {
1600
+ fs14.mkdirSync(routesDestinationPath, { recursive: true });
1601
+ }
1602
+ const forgetPageDestinationPath = path14.join(
1603
+ routesDestinationPath,
1604
+ "forget.tsx"
1605
+ );
1606
+ fs14.copyFileSync(
1607
+ `${authTemplatePath}/forget.tsx`,
1608
+ forgetPageDestinationPath
1609
+ );
1610
+ const resetPageDestinationPath = path14.join(
1611
+ routesDestinationPath,
1612
+ "reset-password.tsx"
1613
+ );
1614
+ fs14.copyFileSync(
1615
+ `${authTemplatePath}/reset-password.tsx`,
1616
+ resetPageDestinationPath
1617
+ );
1618
+ console.log(
1619
+ chalk13.green("Successfully added forget and reset-password pages")
867
1620
  );
868
1621
  } else {
869
1622
  console.log(
870
- chalk7.red("Could not find emailAndPassword configuration in auth.ts")
1623
+ chalk13.red("Could not find emailAndPassword configuration in auth.ts")
871
1624
  );
872
1625
  }
873
1626
  } catch (error) {
874
- console.log(chalk7.red("Error adding sendResetPassword:"), error);
1627
+ console.log(chalk13.red("Error adding sendResetPassword:"), error);
1628
+ }
1629
+ };
1630
+
1631
+ // cli/forget.ts
1632
+ var forget = () => {
1633
+ const projectDir = process.cwd();
1634
+ const packageJsonPath = path15.join(projectDir, "package.json");
1635
+ let framework = "tanstack state";
1636
+ if (fs15.existsSync(packageJsonPath)) {
1637
+ const packageJson2 = JSON.parse(fs15.readFileSync(packageJsonPath, "utf-8"));
1638
+ const hasNext = packageJson2?.dependencies?.["next"] || packageJson2?.devDependencies?.["next"];
1639
+ framework = hasNext ? "Next js" : "tanstack state";
1640
+ }
1641
+ if (framework === "Next js") {
1642
+ return forgetNext();
1643
+ }
1644
+ if (framework === "tanstack state") {
1645
+ return forgetTanstack();
875
1646
  }
876
1647
  };
877
1648
 
@@ -892,7 +1663,7 @@ function isNextJsProject() {
892
1663
  }
893
1664
 
894
1665
  // index.ts
895
- import chalk8 from "chalk";
1666
+ import chalk14 from "chalk";
896
1667
  var packageJson = JSON.parse(readFileSync2("./package.json", "utf8"));
897
1668
  var program = new Command();
898
1669
  program.name("authverse").description("CLI tool for creating authverse projects").version(
@@ -902,7 +1673,7 @@ program.name("authverse").description("CLI tool for creating authverse projects"
902
1673
  );
903
1674
  program.command("init").description("Select project template and configuration").action(() => {
904
1675
  if (!isNextJsProject) {
905
- console.log(chalk8.red("Only Next.js projects are supported."));
1676
+ console.log(chalk14.red("Only Next.js projects are supported."));
906
1677
  process.exit(1);
907
1678
  }
908
1679
  initAnswer();