authverse 1.0.7-canary.1 → 1.0.7

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