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.js CHANGED
@@ -409,8 +409,342 @@ BETTER_AUTH_URL=http://localhost:3000
409
409
  }
410
410
  };
411
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
+
412
737
  // cli/init.ts
413
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}`);
414
748
  const answers = await inquirer.prompt([
415
749
  {
416
750
  type: "list",
@@ -432,47 +766,56 @@ var initAnswer = async () => {
432
766
  default: true
433
767
  }
434
768
  ]);
435
- if (answers.orm === "Prisma") {
769
+ if (framework === "Next js" && answers.orm === "Prisma") {
436
770
  await prismaRun({
437
771
  authUi: answers.authUi,
438
772
  database: answers.database
439
773
  });
440
774
  }
441
- if (answers.orm === "Drizzle") {
775
+ if (framework === "Next js" && answers.orm === "Drizzle") {
442
776
  await drizzleRun(answers.authUi);
443
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
+ }
444
787
  };
445
788
 
446
789
  // index.ts
447
790
  import { readFileSync as readFileSync2 } from "fs";
448
791
 
449
792
  // cli/provider.ts
450
- import chalk6 from "chalk";
793
+ import chalk11 from "chalk";
451
794
 
452
795
  // script/googleRun.ts
453
- import chalk4 from "chalk";
454
- import fs4 from "fs";
455
- import path4 from "path";
456
- 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";
457
800
  var googleRun = async () => {
458
801
  try {
459
- const __filename = fileURLToPath4(import.meta.url);
460
- const __dirname = path4.dirname(__filename);
802
+ const __filename = fileURLToPath7(import.meta.url);
803
+ const __dirname = path8.dirname(__filename);
461
804
  const projectDir = process.cwd();
462
- const srcPath = path4.join(projectDir, "src");
463
- const folder = fs4.existsSync(srcPath) ? "src" : "";
464
- const authFilePath = path4.join(projectDir, folder, "lib", "auth.ts");
465
- if (!fs4.existsSync(authFilePath)) {
466
- 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"));
467
810
  return;
468
811
  }
469
- let content = fs4.readFileSync(authFilePath, "utf8");
812
+ let content = fs8.readFileSync(authFilePath, "utf8");
470
813
  if (!content.includes("betterAuth({")) {
471
- console.log(chalk4.red("betterAuth({}) block not found"));
814
+ console.log(chalk7.red("betterAuth({}) block not found"));
472
815
  return;
473
816
  }
474
817
  if (content.includes("socialProviders") && content.includes("google:")) {
475
- console.log(chalk4.yellow("Google provider already exists"));
818
+ console.log(chalk7.yellow("Google provider already exists"));
476
819
  return;
477
820
  }
478
821
  const googleProviderEntry = `
@@ -495,7 +838,7 @@ var googleRun = async () => {
495
838
  }
496
839
  }
497
840
  if (insertPos === -1) {
498
- console.log(chalk4.red("Failed to parse socialProviders block"));
841
+ console.log(chalk7.red("Failed to parse socialProviders block"));
499
842
  return;
500
843
  }
501
844
  content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
@@ -503,7 +846,7 @@ var googleRun = async () => {
503
846
  const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
504
847
  if (!databaseRegex.test(content)) {
505
848
  console.log(
506
- chalk4.red(
849
+ chalk7.red(
507
850
  "Could not find database adapter (prismaAdapter or drizzleAdapter)"
508
851
  )
509
852
  );
@@ -519,12 +862,12 @@ ${googleProviderEntry}
519
862
  ${socialProvidersBlock}`
520
863
  );
521
864
  }
522
- fs4.writeFileSync(authFilePath, content, "utf8");
523
- const envPath = path4.join(projectDir, ".env");
524
- if (fs4.existsSync(envPath)) {
525
- 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");
526
869
  if (!envContent.includes("GOOGLE_CLIENT_ID")) {
527
- fs4.appendFileSync(
870
+ fs8.appendFileSync(
528
871
  envPath,
529
872
  `
530
873
 
@@ -535,53 +878,53 @@ GOOGLE_CLIENT_SECRET=
535
878
  );
536
879
  }
537
880
  }
538
- const componentTemplate = path4.resolve(
881
+ const componentTemplate = path8.resolve(
539
882
  __dirname,
540
883
  "./template/components/GoogleProviders.tsx"
541
884
  );
542
- const componentsDir = path4.join(
885
+ const componentsDir = path8.join(
543
886
  projectDir,
544
887
  folder,
545
888
  "components",
546
889
  "authverse"
547
890
  );
548
- if (!fs4.existsSync(componentsDir)) {
549
- fs4.mkdirSync(componentsDir, { recursive: true });
891
+ if (!fs8.existsSync(componentsDir)) {
892
+ fs8.mkdirSync(componentsDir, { recursive: true });
550
893
  }
551
- const componentDest = path4.join(componentsDir, "GoogleProviders.tsx");
552
- if (fs4.existsSync(componentTemplate)) {
553
- fs4.copyFileSync(componentTemplate, componentDest);
894
+ const componentDest = path8.join(componentsDir, "GoogleProviders.tsx");
895
+ if (fs8.existsSync(componentTemplate)) {
896
+ fs8.copyFileSync(componentTemplate, componentDest);
554
897
  }
555
- console.log(chalk4.green("Google provider added & merged successfully"));
898
+ console.log(chalk7.green("Google provider added & merged successfully"));
556
899
  } catch (error) {
557
- console.log(chalk4.red("googleRun error:"), error);
900
+ console.log(chalk7.red("googleRun error:"), error);
558
901
  }
559
902
  };
560
903
 
561
904
  // script/githubRun.ts
562
- import chalk5 from "chalk";
563
- import fs5 from "fs";
564
- import path5 from "path";
565
- 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";
566
909
  var githubRun = async () => {
567
910
  try {
568
- const __filename = fileURLToPath5(import.meta.url);
569
- const __dirname = path5.dirname(__filename);
911
+ const __filename = fileURLToPath8(import.meta.url);
912
+ const __dirname = path9.dirname(__filename);
570
913
  const projectDir = process.cwd();
571
- const srcPath = path5.join(projectDir, "src");
572
- const folder = fs5.existsSync(srcPath) ? "src" : "";
573
- const authFilePath = path5.join(projectDir, folder, "lib", "auth.ts");
574
- if (!fs5.existsSync(authFilePath)) {
575
- 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"));
576
919
  return;
577
920
  }
578
- let content = fs5.readFileSync(authFilePath, "utf8");
921
+ let content = fs9.readFileSync(authFilePath, "utf8");
579
922
  if (!content.includes("betterAuth({")) {
580
- console.log(chalk5.red("betterAuth({}) block not found"));
923
+ console.log(chalk8.red("betterAuth({}) block not found"));
581
924
  return;
582
925
  }
583
926
  if (content.includes("socialProviders") && content.includes("github:")) {
584
- console.log(chalk5.yellow("GitHub provider already exists"));
927
+ console.log(chalk8.yellow("GitHub provider already exists"));
585
928
  return;
586
929
  }
587
930
  const githubProviderEntry = `
@@ -604,7 +947,7 @@ var githubRun = async () => {
604
947
  }
605
948
  }
606
949
  if (insertPos === -1) {
607
- console.log(chalk5.red("Failed to parse socialProviders block"));
950
+ console.log(chalk8.red("Failed to parse socialProviders block"));
608
951
  return;
609
952
  }
610
953
  content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
@@ -612,7 +955,7 @@ var githubRun = async () => {
612
955
  const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
613
956
  if (!databaseRegex.test(content)) {
614
957
  console.log(
615
- chalk5.red(
958
+ chalk8.red(
616
959
  "Could not find database adapter (prismaAdapter or drizzleAdapter)"
617
960
  )
618
961
  );
@@ -628,12 +971,12 @@ ${githubProviderEntry}
628
971
  ${socialProvidersBlock}`
629
972
  );
630
973
  }
631
- fs5.writeFileSync(authFilePath, content, "utf8");
632
- const envPath = path5.join(projectDir, ".env");
633
- if (fs5.existsSync(envPath)) {
634
- 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");
635
978
  if (!envContent.includes("GITHUB_CLIENT_ID")) {
636
- fs5.appendFileSync(
979
+ fs9.appendFileSync(
637
980
  envPath,
638
981
  `
639
982
 
@@ -644,70 +987,297 @@ GITHUB_CLIENT_SECRET=
644
987
  );
645
988
  }
646
989
  }
647
- const componentTemplate = path5.resolve(
990
+ const componentTemplate = path9.resolve(
648
991
  __dirname,
649
992
  "./template/components/GithubProviders.tsx"
650
993
  );
651
- const componentsDir = path5.join(
994
+ const componentsDir = path9.join(
652
995
  projectDir,
653
996
  folder,
654
997
  "components",
655
998
  "authverse"
656
999
  );
657
- if (!fs5.existsSync(componentsDir)) {
658
- fs5.mkdirSync(componentsDir, { recursive: true });
1000
+ if (!fs9.existsSync(componentsDir)) {
1001
+ fs9.mkdirSync(componentsDir, { recursive: true });
659
1002
  }
660
- const componentDest = path5.join(componentsDir, "GithubProviders.tsx");
661
- if (fs5.existsSync(componentTemplate)) {
662
- fs5.copyFileSync(componentTemplate, componentDest);
1003
+ const componentDest = path9.join(componentsDir, "GithubProviders.tsx");
1004
+ if (fs9.existsSync(componentTemplate)) {
1005
+ fs9.copyFileSync(componentTemplate, componentDest);
663
1006
  }
664
- console.log(chalk5.green("GitHub provider added & merged successfully"));
1007
+ console.log(chalk8.green("GitHub provider added & merged successfully"));
665
1008
  } catch (error) {
666
- 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);
667
1220
  }
668
1221
  };
669
1222
 
670
1223
  // cli/provider.ts
671
1224
  var providers = async ({ provider }) => {
672
1225
  try {
673
- 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") {
674
1235
  await googleRun();
675
- } else if (provider == "github") {
1236
+ } else if (framework === "Next js" && provider == "github") {
676
1237
  await githubRun();
677
1238
  }
1239
+ if (framework === "tanstack state" && provider == "google") {
1240
+ await googleRunTanstackState();
1241
+ } else if (framework === "tanstack state" && provider == "github") {
1242
+ await githubRunTanstackState();
1243
+ }
678
1244
  } catch (error) {
679
- console.log(chalk6.red("Error adding provider:"), error);
1245
+ console.log(chalk11.red("Error adding provider:"), error);
680
1246
  }
681
1247
  };
682
1248
 
683
1249
  // cli/forget.ts
684
- import chalk7 from "chalk";
685
- import path6 from "path";
686
- import { fileURLToPath as fileURLToPath6 } from "url";
687
- import fs6 from "fs";
688
- 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 () => {
689
1259
  try {
690
1260
  const projectDir = process.cwd();
691
- const packageJsonPath = path6.join(projectDir, "package.json");
692
- 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"));
693
1263
  if (!packageJson2.dependencies?.resend) {
694
- console.log(chalk7.cyan("\n\u2699\uFE0F Installing Resend...\n"));
1264
+ console.log(chalk12.cyan("\n\u2699\uFE0F Installing Resend...\n"));
695
1265
  packageManager("resend");
696
1266
  }
697
1267
  if (!packageJson2.dependencies?.["@react-email/components"]) {
698
- 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"));
699
1269
  packageManager("@react-email/components");
700
1270
  }
701
- const __filename = fileURLToPath6(import.meta.url);
702
- const __dirname = path6.dirname(__filename);
703
- const srcPath = path6.join(projectDir, "src");
704
- const folder = fs6.existsSync(srcPath) ? "src" : "";
705
- const authFilePath = path6.join(projectDir, folder, "lib", "auth.ts");
706
- if (!fs6.existsSync(authFilePath)) {
707
- 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."));
708
1278
  return;
709
1279
  }
710
- let content = fs6.readFileSync(authFilePath, "utf8");
1280
+ let content = fs13.readFileSync(authFilePath, "utf8");
711
1281
  const codeAdded = `sendResetPassword: async ({ user, url, token }) => {
712
1282
  await resend.emails.send({
713
1283
  from: \`\${process.env.EMAIL_SENDER_NAME} <\${process.env.EMAIL_SENDER_ADDRESS}>\`,
@@ -752,7 +1322,7 @@ var forget = async () => {
752
1322
  content = before + `
753
1323
  ${codeAdded}` + after;
754
1324
  }
755
- fs6.writeFileSync(authFilePath, content, "utf8");
1325
+ fs13.writeFileSync(authFilePath, content, "utf8");
756
1326
  if (!content.includes("import { Resend }") && !content.includes("const resend = new Resend")) {
757
1327
  const lastImportIndex = content.lastIndexOf("import");
758
1328
  const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
@@ -764,117 +1334,315 @@ import ForgotPasswordEmail from "@/components/email/reset-password";
764
1334
  const resend = new Resend(process.env.RESEND_API_KEY as string);
765
1335
  `;
766
1336
  content = beforeImports + newImports + afterImports;
767
- fs6.writeFileSync(authFilePath, content, "utf8");
1337
+ fs13.writeFileSync(authFilePath, content, "utf8");
768
1338
  }
769
- const envPath = path6.join(projectDir, ".env");
770
- const envContent = fs6.readFileSync(envPath, "utf8");
1339
+ const envPath = path13.join(projectDir, ".env");
1340
+ const envContent = fs13.readFileSync(envPath, "utf8");
771
1341
  if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
772
- fs6.appendFileSync(envPath, `
1342
+ fs13.appendFileSync(envPath, `
773
1343
 
774
1344
  # Resend API Key for sending emails`);
775
- fs6.appendFileSync(envPath, `
1345
+ fs13.appendFileSync(envPath, `
776
1346
  RESEND_API_KEY=`);
777
- fs6.appendFileSync(envPath, `
1347
+ fs13.appendFileSync(envPath, `
778
1348
  EMAIL_SENDER_NAME=Your Name`);
779
- fs6.appendFileSync(envPath, `
1349
+ fs13.appendFileSync(envPath, `
780
1350
  EMAIL_SENDER_ADDRESS=`);
781
1351
  }
782
- const componentPath = path6.resolve(
1352
+ const componentPath = path13.resolve(
783
1353
  __dirname,
784
1354
  "./template/email/reset-password.tsx"
785
1355
  );
786
- const destinationPath = path6.join(
1356
+ const destinationPath = path13.join(
787
1357
  projectDir,
788
1358
  folder,
789
1359
  "components",
790
1360
  "email"
791
1361
  );
792
- if (!fs6.existsSync(destinationPath)) {
793
- fs6.mkdirSync(destinationPath, { recursive: true });
1362
+ if (!fs13.existsSync(destinationPath)) {
1363
+ fs13.mkdirSync(destinationPath, { recursive: true });
794
1364
  }
795
- const emailDestinationPath = path6.join(
1365
+ const emailDestinationPath = path13.join(
796
1366
  destinationPath,
797
1367
  "reset-password.tsx"
798
1368
  );
799
- if (fs6.existsSync(componentPath)) {
800
- fs6.copyFileSync(componentPath, emailDestinationPath);
1369
+ if (fs13.existsSync(componentPath)) {
1370
+ fs13.copyFileSync(componentPath, emailDestinationPath);
801
1371
  }
802
- const forgetComponentPath = path6.resolve(
1372
+ const forgetComponentPath = path13.resolve(
803
1373
  __dirname,
804
1374
  "./template/components/ForgetComponent.tsx"
805
1375
  );
806
- const componentsDestinationPath = path6.join(
1376
+ const componentsDestinationPath = path13.join(
807
1377
  projectDir,
808
1378
  folder,
809
1379
  "components",
810
1380
  "authverse"
811
1381
  );
812
- if (!fs6.existsSync(componentsDestinationPath)) {
813
- fs6.mkdirSync(componentsDestinationPath, { recursive: true });
1382
+ if (!fs13.existsSync(componentsDestinationPath)) {
1383
+ fs13.mkdirSync(componentsDestinationPath, { recursive: true });
814
1384
  }
815
- const forgetDestinationPath = path6.join(
1385
+ const forgetDestinationPath = path13.join(
816
1386
  componentsDestinationPath,
817
1387
  "ForgetComponent.tsx"
818
1388
  );
819
- if (fs6.existsSync(forgetComponentPath)) {
820
- fs6.copyFileSync(forgetComponentPath, forgetDestinationPath);
1389
+ if (fs13.existsSync(forgetComponentPath)) {
1390
+ fs13.copyFileSync(forgetComponentPath, forgetDestinationPath);
821
1391
  }
822
- const resetComponentPath = path6.resolve(
1392
+ const resetComponentPath = path13.resolve(
823
1393
  __dirname,
824
1394
  "./template/components/ResetComponent.tsx"
825
1395
  );
826
- const resetDestinationPath = path6.join(
1396
+ const resetDestinationPath = path13.join(
827
1397
  componentsDestinationPath,
828
1398
  "ResetComponent.tsx"
829
1399
  );
830
- if (fs6.existsSync(resetComponentPath)) {
831
- fs6.copyFileSync(resetComponentPath, resetDestinationPath);
1400
+ if (fs13.existsSync(resetComponentPath)) {
1401
+ fs13.copyFileSync(resetComponentPath, resetDestinationPath);
832
1402
  }
833
- const authTemplatePath = path6.resolve(
1403
+ const authTemplatePath = path13.resolve(
834
1404
  __dirname,
835
1405
  "./template/app-auth-uiDesign"
836
1406
  );
837
- const appDestinationPath = path6.join(projectDir, folder, "app", "auth");
838
- if (!fs6.existsSync(appDestinationPath)) {
839
- 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 });
840
1410
  }
841
- const forgetDestinationDir = path6.join(appDestinationPath, "forget");
842
- if (!fs6.existsSync(forgetDestinationDir)) {
843
- fs6.mkdirSync(forgetDestinationDir, { recursive: true });
1411
+ const forgetDestinationDir = path13.join(appDestinationPath, "forget");
1412
+ if (!fs13.existsSync(forgetDestinationDir)) {
1413
+ fs13.mkdirSync(forgetDestinationDir, { recursive: true });
844
1414
  }
845
- const forgetPageDestinationPath = path6.join(
1415
+ const forgetPageDestinationPath = path13.join(
846
1416
  forgetDestinationDir,
847
1417
  "page.tsx"
848
1418
  );
849
- fs6.copyFileSync(
1419
+ fs13.copyFileSync(
850
1420
  `${authTemplatePath}/forget/page.tsx`,
851
1421
  forgetPageDestinationPath
852
1422
  );
853
- const resetDestinationDir = path6.join(
1423
+ const resetDestinationDir = path13.join(
854
1424
  appDestinationPath,
855
1425
  "reset-password"
856
1426
  );
857
- if (!fs6.existsSync(resetDestinationDir)) {
858
- fs6.mkdirSync(resetDestinationDir, { recursive: true });
1427
+ if (!fs13.existsSync(resetDestinationDir)) {
1428
+ fs13.mkdirSync(resetDestinationDir, { recursive: true });
859
1429
  }
860
- const resetPageDestinationPath = path6.join(
1430
+ const resetPageDestinationPath = path13.join(
861
1431
  resetDestinationDir,
862
1432
  "page.tsx"
863
1433
  );
864
- fs6.copyFileSync(
1434
+ fs13.copyFileSync(
865
1435
  `${authTemplatePath}/reset-password/page.tsx`,
866
1436
  resetPageDestinationPath
867
1437
  );
868
1438
  console.log(
869
- 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")
870
1620
  );
871
1621
  } else {
872
1622
  console.log(
873
- chalk7.red("Could not find emailAndPassword configuration in auth.ts")
1623
+ chalk13.red("Could not find emailAndPassword configuration in auth.ts")
874
1624
  );
875
1625
  }
876
1626
  } catch (error) {
877
- 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();
878
1646
  }
879
1647
  };
880
1648
 
@@ -895,7 +1663,7 @@ function isNextJsProject() {
895
1663
  }
896
1664
 
897
1665
  // index.ts
898
- import chalk8 from "chalk";
1666
+ import chalk14 from "chalk";
899
1667
  var packageJson = JSON.parse(readFileSync2("./package.json", "utf8"));
900
1668
  var program = new Command();
901
1669
  program.name("authverse").description("CLI tool for creating authverse projects").version(
@@ -905,7 +1673,7 @@ program.name("authverse").description("CLI tool for creating authverse projects"
905
1673
  );
906
1674
  program.command("init").description("Select project template and configuration").action(() => {
907
1675
  if (!isNextJsProject) {
908
- console.log(chalk8.red("Only Next.js projects are supported."));
1676
+ console.log(chalk14.red("Only Next.js projects are supported."));
909
1677
  process.exit(1);
910
1678
  }
911
1679
  initAnswer();