create-kyro 0.1.4 → 0.1.6
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 +16 -67
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -496,18 +496,15 @@ Visit [https://kyro.cms](https://kyro.cms) for full documentation.
|
|
|
496
496
|
|
|
497
497
|
${answers.database === "sqlite" ? "# SQLite (local) - no additional config needed" : answers.database === "postgres" || answers.database === "mysql" ? "# Database connection (PostgreSQL/MySQL)\nDATABASE_URL=postgresql://user:password@localhost:5432/kyro_cms\nDATABASE_SSL=false" : "# MongoDB connection\nMONGODB_URI=mongodb://localhost:27017/kyro_cms"}
|
|
498
498
|
|
|
499
|
-
${answers.auth ? `# Authentication (
|
|
499
|
+
${answers.auth ? `# Authentication (uses SQLite at ./data/auth.db - no Redis needed)
|
|
500
500
|
JWT_SECRET=change-this-to-a-random-32-character-string
|
|
501
501
|
JWT_EXPIRES_IN=24h
|
|
502
502
|
|
|
503
|
-
#
|
|
504
|
-
|
|
505
|
-
KYRO_ADMIN_PASSWORD=SecurePass123!
|
|
506
|
-
KYRO_ADMIN_ROLE=super_admin
|
|
503
|
+
# Registration control (set to false to disable public registration after first user)
|
|
504
|
+
KYRO_ALLOW_REGISTRATION=true
|
|
507
505
|
|
|
508
|
-
# Optional:
|
|
509
|
-
#
|
|
510
|
-
# REDIS_TLS=false
|
|
506
|
+
# Optional: Custom auth database path (default: ./data/auth.db)
|
|
507
|
+
# KYRO_AUTH_DB_PATH=./data/auth.db
|
|
511
508
|
|
|
512
509
|
# Optional: SMTP for emails
|
|
513
510
|
# SMTP_HOST=smtp.example.com
|
|
@@ -628,20 +625,15 @@ import config from '../../../kyro.config';
|
|
|
628
625
|
}
|
|
629
626
|
}
|
|
630
627
|
function generateLoginEndpoint(database) {
|
|
631
|
-
const adapterImport = database === "sqlite" ? `import { SQLiteAuthAdapter } from "@kyro-cms/core";` : `import { RedisAuthAdapter } from "@kyro-cms/core";`;
|
|
632
|
-
const adapterInit = database === "sqlite" ? ` return new SQLiteAuthAdapter({ path: "./data.db" });` : ` return new RedisAuthAdapter({
|
|
633
|
-
url: process.env.REDIS_URL || "redis://localhost:6379",
|
|
634
|
-
tls: process.env.REDIS_TLS === "true",
|
|
635
|
-
});`;
|
|
636
628
|
return `import type { APIRoute } from "astro";
|
|
637
|
-
|
|
629
|
+
import { SQLiteAuthAdapter } from "@kyro-cms/core";
|
|
638
630
|
import jwt from "jsonwebtoken";
|
|
639
631
|
|
|
640
632
|
const JWT_SECRET = process.env.JWT_SECRET || "change-me-in-production";
|
|
641
633
|
const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || "24h";
|
|
642
634
|
|
|
643
635
|
async function getAuthApi() {
|
|
644
|
-
|
|
636
|
+
return new SQLiteAuthAdapter({ path: "./data/auth.db" });
|
|
645
637
|
}
|
|
646
638
|
|
|
647
639
|
export const POST: APIRoute = async ({ request }) => {
|
|
@@ -723,28 +715,8 @@ export const POST: APIRoute = async ({ request }) => {
|
|
|
723
715
|
`;
|
|
724
716
|
}
|
|
725
717
|
function generateRegisterEndpoint(database) {
|
|
726
|
-
const adapterImport = database === "sqlite" ? `import { SQLiteAuthAdapter } from "@kyro-cms/core";` : `import { RedisAuthAdapter } from "@kyro-cms/core";`;
|
|
727
|
-
const adapterInit = database === "sqlite" ? ` return new SQLiteAuthAdapter({ path: "./data.db" });` : ` return new RedisAuthAdapter({
|
|
728
|
-
url: process.env.REDIS_URL || "redis://localhost:6379",
|
|
729
|
-
tls: process.env.REDIS_TLS === "true",
|
|
730
|
-
});`;
|
|
731
|
-
const isFirstUserCheck = database === "sqlite" ? ` const isFirstUser = !(await adapter.hasAnyUsers());` : ` const isFirstUser = await checkIsFirstUser(adapter);`;
|
|
732
|
-
const isFirstUserFn = database === "sqlite" ? "" : `
|
|
733
|
-
|
|
734
|
-
async function checkIsFirstUser(adapter: RedisAuthAdapter): Promise<boolean> {
|
|
735
|
-
try {
|
|
736
|
-
const redis = (adapter as any).redis;
|
|
737
|
-
if (!redis) return true;
|
|
738
|
-
const pattern = "kyro:auth:users:email:*";
|
|
739
|
-
const result = await redis.scan("0", "MATCH", pattern, "COUNT", "1");
|
|
740
|
-
const keys = result[1];
|
|
741
|
-
return keys.length === 0;
|
|
742
|
-
} catch {
|
|
743
|
-
return true;
|
|
744
|
-
}
|
|
745
|
-
}`;
|
|
746
718
|
return `import type { APIRoute } from "astro";
|
|
747
|
-
|
|
719
|
+
import { SQLiteAuthAdapter } from "@kyro-cms/core";
|
|
748
720
|
import jwt from "jsonwebtoken";
|
|
749
721
|
|
|
750
722
|
const JWT_SECRET = process.env.JWT_SECRET || "change-me-in-production";
|
|
@@ -752,7 +724,7 @@ const JWT_EXPIRES_IN = process.env.JWT_EXPIRES_IN || "24h";
|
|
|
752
724
|
const ALLOW_REGISTRATION = process.env.KYRO_ALLOW_REGISTRATION !== "false";
|
|
753
725
|
|
|
754
726
|
async function getAuthApi() {
|
|
755
|
-
|
|
727
|
+
return new SQLiteAuthAdapter({ path: "./data/auth.db" });
|
|
756
728
|
}
|
|
757
729
|
|
|
758
730
|
export const POST: APIRoute = async ({ request }) => {
|
|
@@ -804,7 +776,7 @@ export const POST: APIRoute = async ({ request }) => {
|
|
|
804
776
|
);
|
|
805
777
|
}
|
|
806
778
|
|
|
807
|
-
|
|
779
|
+
const isFirstUser = !(await adapter.hasAnyUsers());
|
|
808
780
|
|
|
809
781
|
if (!isFirstUser && !ALLOW_REGISTRATION) {
|
|
810
782
|
await adapter.disconnect();
|
|
@@ -865,20 +837,15 @@ ${isFirstUserCheck}
|
|
|
865
837
|
headers: { "Content-Type": "application/json" },
|
|
866
838
|
});
|
|
867
839
|
}
|
|
868
|
-
}
|
|
840
|
+
};
|
|
869
841
|
`;
|
|
870
842
|
}
|
|
871
843
|
function generateLogoutEndpoint(database) {
|
|
872
|
-
const adapterImport = database === "sqlite" ? `import { SQLiteAuthAdapter } from "@kyro-cms/core";` : `import { RedisAuthAdapter } from "@kyro-cms/core";`;
|
|
873
|
-
const adapterInit = database === "sqlite" ? ` return new SQLiteAuthAdapter({ path: "./data.db" });` : ` return new RedisAuthAdapter({
|
|
874
|
-
url: process.env.REDIS_URL || "redis://localhost:6379",
|
|
875
|
-
tls: process.env.REDIS_TLS === "true",
|
|
876
|
-
});`;
|
|
877
844
|
return `import type { APIRoute } from "astro";
|
|
878
|
-
|
|
845
|
+
import { SQLiteAuthAdapter } from "@kyro-cms/core";
|
|
879
846
|
|
|
880
847
|
async function getAuthApi() {
|
|
881
|
-
|
|
848
|
+
return new SQLiteAuthAdapter({ path: "./data/auth.db" });
|
|
882
849
|
}
|
|
883
850
|
|
|
884
851
|
export const POST: APIRoute = async ({ request }) => {
|
|
@@ -947,29 +914,11 @@ export const GET: APIRoute = async ({ request }) => {
|
|
|
947
914
|
`;
|
|
948
915
|
}
|
|
949
916
|
function generateUsersEndpoint(database) {
|
|
950
|
-
const adapterImport = database === "sqlite" ? `import { SQLiteAuthAdapter } from "@kyro-cms/core";` : `import { RedisAuthAdapter } from "@kyro-cms/core";`;
|
|
951
|
-
const adapterInit = database === "sqlite" ? ` return new SQLiteAuthAdapter({ path: "./data.db" });` : ` return new RedisAuthAdapter({
|
|
952
|
-
url: process.env.REDIS_URL || "redis://localhost:6379",
|
|
953
|
-
tls: process.env.REDIS_TLS === "true",
|
|
954
|
-
});`;
|
|
955
|
-
const hasUsersCheck = database === "sqlite" ? ` const hasUsers = await adapter.hasAnyUsers();` : ` const redis = (adapter as any).redis;
|
|
956
|
-
if (!redis) {
|
|
957
|
-
await adapter.disconnect();
|
|
958
|
-
return new Response(JSON.stringify({ hasUsers: false }), {
|
|
959
|
-
status: 200,
|
|
960
|
-
headers: { "Content-Type": "application/json" },
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
const pattern = "kyro:auth:users:email:*";
|
|
965
|
-
const result = await redis.scan("0", "MATCH", pattern, "COUNT", "1");
|
|
966
|
-
const keys = result[1];
|
|
967
|
-
const hasUsers = keys.length > 0;`;
|
|
968
917
|
return `import type { APIRoute } from "astro";
|
|
969
|
-
|
|
918
|
+
import { SQLiteAuthAdapter } from "@kyro-cms/core";
|
|
970
919
|
|
|
971
920
|
async function getAuthApi() {
|
|
972
|
-
|
|
921
|
+
return new SQLiteAuthAdapter({ path: "./data/auth.db" });
|
|
973
922
|
}
|
|
974
923
|
|
|
975
924
|
export const GET: APIRoute = async () => {
|
|
@@ -977,7 +926,7 @@ export const GET: APIRoute = async () => {
|
|
|
977
926
|
const adapter = await getAuthApi();
|
|
978
927
|
await adapter.connect();
|
|
979
928
|
|
|
980
|
-
|
|
929
|
+
const hasUsers = await adapter.hasAnyUsers();
|
|
981
930
|
|
|
982
931
|
await adapter.disconnect();
|
|
983
932
|
|