authverse 1.0.6 → 1.0.7-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.cjs +919 -142
- package/dist/index.js +905 -134
- package/dist/template/TanstackState/components/ForgetComponent.tsx +128 -0
- package/dist/template/TanstackState/components/GithubProviders.tsx +34 -0
- package/dist/template/TanstackState/components/GoogleProviders.tsx +46 -0
- package/dist/template/TanstackState/components/LoginComponent.tsx +159 -0
- package/dist/template/TanstackState/components/ResetComponent.tsx +163 -0
- package/dist/template/TanstackState/components/SingUpComponent.tsx +189 -0
- package/dist/template/TanstackState/lib/Mongodb/auth.ts +25 -0
- package/dist/template/TanstackState/lib/Mysql/auth.ts +30 -0
- package/dist/template/TanstackState/lib/Postgresql/auth.ts +23 -0
- package/dist/template/TanstackState/lib/auth-drizzle.ts +16 -0
- package/dist/template/TanstackState/middleware/auth.ts +15 -0
- package/dist/template/TanstackState/routes/$.ts +15 -0
- package/dist/template/TanstackState/routes/auth/forget.tsx +14 -0
- package/dist/template/TanstackState/routes/auth/login.tsx +14 -0
- package/dist/template/TanstackState/routes/auth/reset-password.tsx +18 -0
- package/dist/template/TanstackState/routes/auth/signup.tsx +14 -0
- package/dist/template/prisma/postgresql/schema.prisma +1 -1
- package/package.json +2 -1
- /package/dist/template/prisma/mysql/{schema copy.prisma → schema.prisma} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -221,12 +221,15 @@ var prismaRun = async ({ authUi, database }) => {
|
|
|
221
221
|
}
|
|
222
222
|
} else {
|
|
223
223
|
const schemaPath = import_path2.default.join(prismaDir, "schema.prisma");
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
224
|
+
const schemaContent = import_fs2.default.readFileSync(schemaPath, "utf-8");
|
|
225
|
+
if (!schemaContent.includes("User") && !schemaContent.includes("Session") && !schemaContent.includes("Account") && !schemaContent.includes("Verification")) {
|
|
226
|
+
const templatePath = import_path2.default.resolve(
|
|
227
|
+
__dirname,
|
|
228
|
+
`./template/prisma/${database}/schema.prisma_copy`
|
|
229
|
+
);
|
|
230
|
+
import_fs2.default.appendFileSync(schemaPath, "\n");
|
|
231
|
+
import_fs2.default.appendFileSync(schemaPath, import_fs2.default.readFileSync(templatePath));
|
|
232
|
+
}
|
|
230
233
|
}
|
|
231
234
|
if (!packageJson2.dependencies?.["better-auth"]) {
|
|
232
235
|
console.log(import_chalk2.default.yellow("\n\u2699\uFE0F Initializing better-auth...\n"));
|
|
@@ -431,8 +434,345 @@ BETTER_AUTH_URL=http://localhost:3000
|
|
|
431
434
|
}
|
|
432
435
|
};
|
|
433
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
|
+
|
|
434
765
|
// cli/init.ts
|
|
435
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}`);
|
|
436
776
|
const answers = await import_inquirer.default.prompt([
|
|
437
777
|
{
|
|
438
778
|
type: "list",
|
|
@@ -454,48 +794,57 @@ var initAnswer = async () => {
|
|
|
454
794
|
default: true
|
|
455
795
|
}
|
|
456
796
|
]);
|
|
457
|
-
if (answers.orm === "Prisma") {
|
|
797
|
+
if (framework === "Next js" && answers.orm === "Prisma") {
|
|
458
798
|
await prismaRun({
|
|
459
799
|
authUi: answers.authUi,
|
|
460
800
|
database: answers.database
|
|
461
801
|
});
|
|
462
802
|
}
|
|
463
|
-
if (answers.orm === "Drizzle") {
|
|
803
|
+
if (framework === "Next js" && answers.orm === "Drizzle") {
|
|
464
804
|
await drizzleRun(answers.authUi);
|
|
465
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
|
+
}
|
|
466
815
|
};
|
|
467
816
|
|
|
468
817
|
// index.ts
|
|
469
|
-
var
|
|
818
|
+
var import_fs17 = require("fs");
|
|
470
819
|
|
|
471
820
|
// cli/provider.ts
|
|
472
|
-
var
|
|
821
|
+
var import_chalk11 = __toESM(require("chalk"), 1);
|
|
473
822
|
|
|
474
823
|
// script/googleRun.ts
|
|
475
|
-
var
|
|
476
|
-
var
|
|
477
|
-
var
|
|
478
|
-
var
|
|
479
|
-
var
|
|
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 = {};
|
|
480
829
|
var googleRun = async () => {
|
|
481
830
|
try {
|
|
482
|
-
const __filename = (0,
|
|
483
|
-
const __dirname =
|
|
831
|
+
const __filename = (0, import_url7.fileURLToPath)(import_meta7.url);
|
|
832
|
+
const __dirname = import_path8.default.dirname(__filename);
|
|
484
833
|
const projectDir = process.cwd();
|
|
485
|
-
const srcPath =
|
|
486
|
-
const folder =
|
|
487
|
-
const authFilePath =
|
|
488
|
-
if (!
|
|
489
|
-
console.log(
|
|
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"));
|
|
490
839
|
return;
|
|
491
840
|
}
|
|
492
|
-
let content =
|
|
841
|
+
let content = import_fs8.default.readFileSync(authFilePath, "utf8");
|
|
493
842
|
if (!content.includes("betterAuth({")) {
|
|
494
|
-
console.log(
|
|
843
|
+
console.log(import_chalk7.default.red("betterAuth({}) block not found"));
|
|
495
844
|
return;
|
|
496
845
|
}
|
|
497
846
|
if (content.includes("socialProviders") && content.includes("google:")) {
|
|
498
|
-
console.log(
|
|
847
|
+
console.log(import_chalk7.default.yellow("Google provider already exists"));
|
|
499
848
|
return;
|
|
500
849
|
}
|
|
501
850
|
const googleProviderEntry = `
|
|
@@ -518,7 +867,7 @@ var googleRun = async () => {
|
|
|
518
867
|
}
|
|
519
868
|
}
|
|
520
869
|
if (insertPos === -1) {
|
|
521
|
-
console.log(
|
|
870
|
+
console.log(import_chalk7.default.red("Failed to parse socialProviders block"));
|
|
522
871
|
return;
|
|
523
872
|
}
|
|
524
873
|
content = content.slice(0, insertPos) + googleProviderEntry + "\n " + content.slice(insertPos);
|
|
@@ -526,7 +875,7 @@ var googleRun = async () => {
|
|
|
526
875
|
const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
|
|
527
876
|
if (!databaseRegex.test(content)) {
|
|
528
877
|
console.log(
|
|
529
|
-
|
|
878
|
+
import_chalk7.default.red(
|
|
530
879
|
"Could not find database adapter (prismaAdapter or drizzleAdapter)"
|
|
531
880
|
)
|
|
532
881
|
);
|
|
@@ -542,12 +891,12 @@ ${googleProviderEntry}
|
|
|
542
891
|
${socialProvidersBlock}`
|
|
543
892
|
);
|
|
544
893
|
}
|
|
545
|
-
|
|
546
|
-
const envPath =
|
|
547
|
-
if (
|
|
548
|
-
const envContent =
|
|
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");
|
|
549
898
|
if (!envContent.includes("GOOGLE_CLIENT_ID")) {
|
|
550
|
-
|
|
899
|
+
import_fs8.default.appendFileSync(
|
|
551
900
|
envPath,
|
|
552
901
|
`
|
|
553
902
|
|
|
@@ -558,54 +907,54 @@ GOOGLE_CLIENT_SECRET=
|
|
|
558
907
|
);
|
|
559
908
|
}
|
|
560
909
|
}
|
|
561
|
-
const componentTemplate =
|
|
910
|
+
const componentTemplate = import_path8.default.resolve(
|
|
562
911
|
__dirname,
|
|
563
912
|
"./template/components/GoogleProviders.tsx"
|
|
564
913
|
);
|
|
565
|
-
const componentsDir =
|
|
914
|
+
const componentsDir = import_path8.default.join(
|
|
566
915
|
projectDir,
|
|
567
916
|
folder,
|
|
568
917
|
"components",
|
|
569
918
|
"authverse"
|
|
570
919
|
);
|
|
571
|
-
if (!
|
|
572
|
-
|
|
920
|
+
if (!import_fs8.default.existsSync(componentsDir)) {
|
|
921
|
+
import_fs8.default.mkdirSync(componentsDir, { recursive: true });
|
|
573
922
|
}
|
|
574
|
-
const componentDest =
|
|
575
|
-
if (
|
|
576
|
-
|
|
923
|
+
const componentDest = import_path8.default.join(componentsDir, "GoogleProviders.tsx");
|
|
924
|
+
if (import_fs8.default.existsSync(componentTemplate)) {
|
|
925
|
+
import_fs8.default.copyFileSync(componentTemplate, componentDest);
|
|
577
926
|
}
|
|
578
|
-
console.log(
|
|
927
|
+
console.log(import_chalk7.default.green("Google provider added & merged successfully"));
|
|
579
928
|
} catch (error) {
|
|
580
|
-
console.log(
|
|
929
|
+
console.log(import_chalk7.default.red("googleRun error:"), error);
|
|
581
930
|
}
|
|
582
931
|
};
|
|
583
932
|
|
|
584
933
|
// script/githubRun.ts
|
|
585
|
-
var
|
|
586
|
-
var
|
|
587
|
-
var
|
|
588
|
-
var
|
|
589
|
-
var
|
|
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 = {};
|
|
590
939
|
var githubRun = async () => {
|
|
591
940
|
try {
|
|
592
|
-
const __filename = (0,
|
|
593
|
-
const __dirname =
|
|
941
|
+
const __filename = (0, import_url8.fileURLToPath)(import_meta8.url);
|
|
942
|
+
const __dirname = import_path9.default.dirname(__filename);
|
|
594
943
|
const projectDir = process.cwd();
|
|
595
|
-
const srcPath =
|
|
596
|
-
const folder =
|
|
597
|
-
const authFilePath =
|
|
598
|
-
if (!
|
|
599
|
-
console.log(
|
|
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"));
|
|
600
949
|
return;
|
|
601
950
|
}
|
|
602
|
-
let content =
|
|
951
|
+
let content = import_fs9.default.readFileSync(authFilePath, "utf8");
|
|
603
952
|
if (!content.includes("betterAuth({")) {
|
|
604
|
-
console.log(
|
|
953
|
+
console.log(import_chalk8.default.red("betterAuth({}) block not found"));
|
|
605
954
|
return;
|
|
606
955
|
}
|
|
607
956
|
if (content.includes("socialProviders") && content.includes("github:")) {
|
|
608
|
-
console.log(
|
|
957
|
+
console.log(import_chalk8.default.yellow("GitHub provider already exists"));
|
|
609
958
|
return;
|
|
610
959
|
}
|
|
611
960
|
const githubProviderEntry = `
|
|
@@ -628,7 +977,7 @@ var githubRun = async () => {
|
|
|
628
977
|
}
|
|
629
978
|
}
|
|
630
979
|
if (insertPos === -1) {
|
|
631
|
-
console.log(
|
|
980
|
+
console.log(import_chalk8.default.red("Failed to parse socialProviders block"));
|
|
632
981
|
return;
|
|
633
982
|
}
|
|
634
983
|
content = content.slice(0, insertPos) + githubProviderEntry + "\n " + content.slice(insertPos);
|
|
@@ -636,7 +985,7 @@ var githubRun = async () => {
|
|
|
636
985
|
const databaseRegex = /database:\s*(prismaAdapter|drizzleAdapter)\([\s\S]*?\),/;
|
|
637
986
|
if (!databaseRegex.test(content)) {
|
|
638
987
|
console.log(
|
|
639
|
-
|
|
988
|
+
import_chalk8.default.red(
|
|
640
989
|
"Could not find database adapter (prismaAdapter or drizzleAdapter)"
|
|
641
990
|
)
|
|
642
991
|
);
|
|
@@ -652,12 +1001,12 @@ ${githubProviderEntry}
|
|
|
652
1001
|
${socialProvidersBlock}`
|
|
653
1002
|
);
|
|
654
1003
|
}
|
|
655
|
-
|
|
656
|
-
const envPath =
|
|
657
|
-
if (
|
|
658
|
-
const envContent =
|
|
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");
|
|
659
1008
|
if (!envContent.includes("GITHUB_CLIENT_ID")) {
|
|
660
|
-
|
|
1009
|
+
import_fs9.default.appendFileSync(
|
|
661
1010
|
envPath,
|
|
662
1011
|
`
|
|
663
1012
|
|
|
@@ -668,71 +1017,300 @@ GITHUB_CLIENT_SECRET=
|
|
|
668
1017
|
);
|
|
669
1018
|
}
|
|
670
1019
|
}
|
|
671
|
-
const componentTemplate =
|
|
1020
|
+
const componentTemplate = import_path9.default.resolve(
|
|
672
1021
|
__dirname,
|
|
673
1022
|
"./template/components/GithubProviders.tsx"
|
|
674
1023
|
);
|
|
675
|
-
const componentsDir =
|
|
1024
|
+
const componentsDir = import_path9.default.join(
|
|
676
1025
|
projectDir,
|
|
677
1026
|
folder,
|
|
678
1027
|
"components",
|
|
679
1028
|
"authverse"
|
|
680
1029
|
);
|
|
681
|
-
if (!
|
|
682
|
-
|
|
1030
|
+
if (!import_fs9.default.existsSync(componentsDir)) {
|
|
1031
|
+
import_fs9.default.mkdirSync(componentsDir, { recursive: true });
|
|
683
1032
|
}
|
|
684
|
-
const componentDest =
|
|
685
|
-
if (
|
|
686
|
-
|
|
1033
|
+
const componentDest = import_path9.default.join(componentsDir, "GithubProviders.tsx");
|
|
1034
|
+
if (import_fs9.default.existsSync(componentTemplate)) {
|
|
1035
|
+
import_fs9.default.copyFileSync(componentTemplate, componentDest);
|
|
687
1036
|
}
|
|
688
|
-
console.log(
|
|
1037
|
+
console.log(import_chalk8.default.green("GitHub provider added & merged successfully"));
|
|
689
1038
|
} catch (error) {
|
|
690
|
-
console.log(
|
|
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);
|
|
691
1252
|
}
|
|
692
1253
|
};
|
|
693
1254
|
|
|
694
1255
|
// cli/provider.ts
|
|
695
1256
|
var providers = async ({ provider }) => {
|
|
696
1257
|
try {
|
|
697
|
-
|
|
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") {
|
|
698
1267
|
await googleRun();
|
|
699
|
-
} else if (provider == "github") {
|
|
1268
|
+
} else if (framework === "Next js" && provider == "github") {
|
|
700
1269
|
await githubRun();
|
|
701
1270
|
}
|
|
1271
|
+
if (framework === "tanstack state" && provider == "google") {
|
|
1272
|
+
await googleRunTanstackState();
|
|
1273
|
+
} else if (framework === "tanstack state" && provider == "github") {
|
|
1274
|
+
await githubRunTanstackState();
|
|
1275
|
+
}
|
|
702
1276
|
} catch (error) {
|
|
703
|
-
console.log(
|
|
1277
|
+
console.log(import_chalk11.default.red("Error adding provider:"), error);
|
|
704
1278
|
}
|
|
705
1279
|
};
|
|
706
1280
|
|
|
707
1281
|
// cli/forget.ts
|
|
708
|
-
var
|
|
709
|
-
var
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
var
|
|
713
|
-
var
|
|
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 () => {
|
|
714
1292
|
try {
|
|
715
1293
|
const projectDir = process.cwd();
|
|
716
|
-
const packageJsonPath =
|
|
717
|
-
const packageJson2 = JSON.parse(
|
|
1294
|
+
const packageJsonPath = import_path13.default.join(projectDir, "package.json");
|
|
1295
|
+
const packageJson2 = JSON.parse(import_fs13.default.readFileSync(packageJsonPath, "utf-8"));
|
|
718
1296
|
if (!packageJson2.dependencies?.resend) {
|
|
719
|
-
console.log(
|
|
1297
|
+
console.log(import_chalk12.default.cyan("\n\u2699\uFE0F Installing Resend...\n"));
|
|
720
1298
|
packageManager("resend");
|
|
721
1299
|
}
|
|
722
1300
|
if (!packageJson2.dependencies?.["@react-email/components"]) {
|
|
723
|
-
console.log(
|
|
1301
|
+
console.log(import_chalk12.default.cyan("\n\u2699\uFE0F Installing react email components...\n"));
|
|
724
1302
|
packageManager("@react-email/components");
|
|
725
1303
|
}
|
|
726
|
-
const __filename = (0,
|
|
727
|
-
const __dirname =
|
|
728
|
-
const srcPath =
|
|
729
|
-
const folder =
|
|
730
|
-
const authFilePath =
|
|
731
|
-
if (!
|
|
732
|
-
console.log(
|
|
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."));
|
|
733
1311
|
return;
|
|
734
1312
|
}
|
|
735
|
-
let content =
|
|
1313
|
+
let content = import_fs13.default.readFileSync(authFilePath, "utf8");
|
|
736
1314
|
const codeAdded = `sendResetPassword: async ({ user, url, token }) => {
|
|
737
1315
|
await resend.emails.send({
|
|
738
1316
|
from: \`\${process.env.EMAIL_SENDER_NAME} <\${process.env.EMAIL_SENDER_ADDRESS}>\`,
|
|
@@ -777,7 +1355,7 @@ var forget = async () => {
|
|
|
777
1355
|
content = before + `
|
|
778
1356
|
${codeAdded}` + after;
|
|
779
1357
|
}
|
|
780
|
-
|
|
1358
|
+
import_fs13.default.writeFileSync(authFilePath, content, "utf8");
|
|
781
1359
|
if (!content.includes("import { Resend }") && !content.includes("const resend = new Resend")) {
|
|
782
1360
|
const lastImportIndex = content.lastIndexOf("import");
|
|
783
1361
|
const nextLineAfterLastImport = content.indexOf("\n", lastImportIndex) + 1;
|
|
@@ -789,126 +1367,325 @@ import ForgotPasswordEmail from "@/components/email/reset-password";
|
|
|
789
1367
|
const resend = new Resend(process.env.RESEND_API_KEY as string);
|
|
790
1368
|
`;
|
|
791
1369
|
content = beforeImports + newImports + afterImports;
|
|
792
|
-
|
|
1370
|
+
import_fs13.default.writeFileSync(authFilePath, content, "utf8");
|
|
793
1371
|
}
|
|
794
|
-
const envPath =
|
|
795
|
-
const envContent =
|
|
1372
|
+
const envPath = import_path13.default.join(projectDir, ".env");
|
|
1373
|
+
const envContent = import_fs13.default.readFileSync(envPath, "utf8");
|
|
796
1374
|
if (!envContent.includes("RESEND_API_KEY") && !envContent.includes("EMAIL_SENDER_NAME") && !envContent.includes("EMAIL_SENDER_ADDRESS")) {
|
|
797
|
-
|
|
1375
|
+
import_fs13.default.appendFileSync(envPath, `
|
|
798
1376
|
|
|
799
1377
|
# Resend API Key for sending emails`);
|
|
800
|
-
|
|
1378
|
+
import_fs13.default.appendFileSync(envPath, `
|
|
801
1379
|
RESEND_API_KEY=`);
|
|
802
|
-
|
|
1380
|
+
import_fs13.default.appendFileSync(envPath, `
|
|
803
1381
|
EMAIL_SENDER_NAME=Your Name`);
|
|
804
|
-
|
|
1382
|
+
import_fs13.default.appendFileSync(envPath, `
|
|
805
1383
|
EMAIL_SENDER_ADDRESS=`);
|
|
806
1384
|
}
|
|
807
|
-
const componentPath =
|
|
1385
|
+
const componentPath = import_path13.default.resolve(
|
|
808
1386
|
__dirname,
|
|
809
1387
|
"./template/email/reset-password.tsx"
|
|
810
1388
|
);
|
|
811
|
-
const destinationPath =
|
|
1389
|
+
const destinationPath = import_path13.default.join(
|
|
812
1390
|
projectDir,
|
|
813
1391
|
folder,
|
|
814
1392
|
"components",
|
|
815
1393
|
"email"
|
|
816
1394
|
);
|
|
817
|
-
if (!
|
|
818
|
-
|
|
1395
|
+
if (!import_fs13.default.existsSync(destinationPath)) {
|
|
1396
|
+
import_fs13.default.mkdirSync(destinationPath, { recursive: true });
|
|
819
1397
|
}
|
|
820
|
-
const emailDestinationPath =
|
|
1398
|
+
const emailDestinationPath = import_path13.default.join(
|
|
821
1399
|
destinationPath,
|
|
822
1400
|
"reset-password.tsx"
|
|
823
1401
|
);
|
|
824
|
-
if (
|
|
825
|
-
|
|
1402
|
+
if (import_fs13.default.existsSync(componentPath)) {
|
|
1403
|
+
import_fs13.default.copyFileSync(componentPath, emailDestinationPath);
|
|
826
1404
|
}
|
|
827
|
-
const forgetComponentPath =
|
|
1405
|
+
const forgetComponentPath = import_path13.default.resolve(
|
|
828
1406
|
__dirname,
|
|
829
1407
|
"./template/components/ForgetComponent.tsx"
|
|
830
1408
|
);
|
|
831
|
-
const componentsDestinationPath =
|
|
1409
|
+
const componentsDestinationPath = import_path13.default.join(
|
|
832
1410
|
projectDir,
|
|
833
1411
|
folder,
|
|
834
1412
|
"components",
|
|
835
1413
|
"authverse"
|
|
836
1414
|
);
|
|
837
|
-
if (!
|
|
838
|
-
|
|
1415
|
+
if (!import_fs13.default.existsSync(componentsDestinationPath)) {
|
|
1416
|
+
import_fs13.default.mkdirSync(componentsDestinationPath, { recursive: true });
|
|
839
1417
|
}
|
|
840
|
-
const forgetDestinationPath =
|
|
1418
|
+
const forgetDestinationPath = import_path13.default.join(
|
|
841
1419
|
componentsDestinationPath,
|
|
842
1420
|
"ForgetComponent.tsx"
|
|
843
1421
|
);
|
|
844
|
-
if (
|
|
845
|
-
|
|
1422
|
+
if (import_fs13.default.existsSync(forgetComponentPath)) {
|
|
1423
|
+
import_fs13.default.copyFileSync(forgetComponentPath, forgetDestinationPath);
|
|
846
1424
|
}
|
|
847
|
-
const resetComponentPath =
|
|
1425
|
+
const resetComponentPath = import_path13.default.resolve(
|
|
848
1426
|
__dirname,
|
|
849
1427
|
"./template/components/ResetComponent.tsx"
|
|
850
1428
|
);
|
|
851
|
-
const resetDestinationPath =
|
|
1429
|
+
const resetDestinationPath = import_path13.default.join(
|
|
852
1430
|
componentsDestinationPath,
|
|
853
1431
|
"ResetComponent.tsx"
|
|
854
1432
|
);
|
|
855
|
-
if (
|
|
856
|
-
|
|
1433
|
+
if (import_fs13.default.existsSync(resetComponentPath)) {
|
|
1434
|
+
import_fs13.default.copyFileSync(resetComponentPath, resetDestinationPath);
|
|
857
1435
|
}
|
|
858
|
-
const authTemplatePath =
|
|
1436
|
+
const authTemplatePath = import_path13.default.resolve(
|
|
859
1437
|
__dirname,
|
|
860
1438
|
"./template/app-auth-uiDesign"
|
|
861
1439
|
);
|
|
862
|
-
const appDestinationPath =
|
|
863
|
-
if (!
|
|
864
|
-
|
|
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 });
|
|
865
1443
|
}
|
|
866
|
-
const forgetDestinationDir =
|
|
867
|
-
if (!
|
|
868
|
-
|
|
1444
|
+
const forgetDestinationDir = import_path13.default.join(appDestinationPath, "forget");
|
|
1445
|
+
if (!import_fs13.default.existsSync(forgetDestinationDir)) {
|
|
1446
|
+
import_fs13.default.mkdirSync(forgetDestinationDir, { recursive: true });
|
|
869
1447
|
}
|
|
870
|
-
const forgetPageDestinationPath =
|
|
1448
|
+
const forgetPageDestinationPath = import_path13.default.join(
|
|
871
1449
|
forgetDestinationDir,
|
|
872
1450
|
"page.tsx"
|
|
873
1451
|
);
|
|
874
|
-
|
|
1452
|
+
import_fs13.default.copyFileSync(
|
|
875
1453
|
`${authTemplatePath}/forget/page.tsx`,
|
|
876
1454
|
forgetPageDestinationPath
|
|
877
1455
|
);
|
|
878
|
-
const resetDestinationDir =
|
|
1456
|
+
const resetDestinationDir = import_path13.default.join(
|
|
879
1457
|
appDestinationPath,
|
|
880
1458
|
"reset-password"
|
|
881
1459
|
);
|
|
882
|
-
if (!
|
|
883
|
-
|
|
1460
|
+
if (!import_fs13.default.existsSync(resetDestinationDir)) {
|
|
1461
|
+
import_fs13.default.mkdirSync(resetDestinationDir, { recursive: true });
|
|
884
1462
|
}
|
|
885
|
-
const resetPageDestinationPath =
|
|
1463
|
+
const resetPageDestinationPath = import_path13.default.join(
|
|
886
1464
|
resetDestinationDir,
|
|
887
1465
|
"page.tsx"
|
|
888
1466
|
);
|
|
889
|
-
|
|
1467
|
+
import_fs13.default.copyFileSync(
|
|
890
1468
|
`${authTemplatePath}/reset-password/page.tsx`,
|
|
891
1469
|
resetPageDestinationPath
|
|
892
1470
|
);
|
|
893
1471
|
console.log(
|
|
894
|
-
|
|
1472
|
+
import_chalk12.default.green("Successfully added forget and reset-password pages")
|
|
895
1473
|
);
|
|
896
1474
|
} else {
|
|
897
1475
|
console.log(
|
|
898
|
-
|
|
1476
|
+
import_chalk12.default.red("Could not find emailAndPassword configuration in auth.ts")
|
|
899
1477
|
);
|
|
900
1478
|
}
|
|
901
1479
|
} catch (error) {
|
|
902
|
-
console.log(
|
|
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();
|
|
903
1680
|
}
|
|
904
1681
|
};
|
|
905
1682
|
|
|
906
1683
|
// script/detect-nextjs.ts
|
|
907
|
-
var
|
|
1684
|
+
var import_fs16 = require("fs");
|
|
908
1685
|
function isNextJsProject() {
|
|
909
|
-
if (!(0,
|
|
1686
|
+
if (!(0, import_fs16.existsSync)("./package.json")) return false;
|
|
910
1687
|
try {
|
|
911
|
-
const pkg = JSON.parse((0,
|
|
1688
|
+
const pkg = JSON.parse((0, import_fs16.readFileSync)("./package.json", "utf8"));
|
|
912
1689
|
const deps = {
|
|
913
1690
|
...pkg.dependencies,
|
|
914
1691
|
...pkg.devDependencies
|
|
@@ -920,8 +1697,8 @@ function isNextJsProject() {
|
|
|
920
1697
|
}
|
|
921
1698
|
|
|
922
1699
|
// index.ts
|
|
923
|
-
var
|
|
924
|
-
var packageJson = JSON.parse((0,
|
|
1700
|
+
var import_chalk14 = __toESM(require("chalk"), 1);
|
|
1701
|
+
var packageJson = JSON.parse((0, import_fs17.readFileSync)("./package.json", "utf8"));
|
|
925
1702
|
var program = new import_commander.Command();
|
|
926
1703
|
program.name("authverse").description("CLI tool for creating authverse projects").version(
|
|
927
1704
|
packageJson.version || "1.0.0",
|
|
@@ -930,7 +1707,7 @@ program.name("authverse").description("CLI tool for creating authverse projects"
|
|
|
930
1707
|
);
|
|
931
1708
|
program.command("init").description("Select project template and configuration").action(() => {
|
|
932
1709
|
if (!isNextJsProject) {
|
|
933
|
-
console.log(
|
|
1710
|
+
console.log(import_chalk14.default.red("Only Next.js projects are supported."));
|
|
934
1711
|
process.exit(1);
|
|
935
1712
|
}
|
|
936
1713
|
initAnswer();
|