@mesob/auth-hono 0.1.0 → 0.2.0
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-CScADcDn.d.ts → index-DCxsFKQ2.d.ts} +7 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +545 -381
- package/dist/index.js.map +1 -1
- package/dist/lib/cookie.d.ts +1 -1
- package/dist/lib/error-handler.d.ts +5 -0
- package/dist/lib/error-handler.js +99 -0
- package/dist/lib/error-handler.js.map +1 -0
- package/dist/lib/normalize-user.d.ts +1 -1
- package/dist/lib/openapi-config.d.ts +1 -1
- package/dist/lib/openapi-config.js +6 -1
- package/dist/lib/openapi-config.js.map +1 -1
- package/dist/lib/phone-validation.d.ts +15 -0
- package/dist/lib/phone-validation.js +15 -0
- package/dist/lib/phone-validation.js.map +1 -0
- package/dist/lib/session.d.ts +1 -1
- package/dist/lib/tenant.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -430,7 +430,7 @@ var createDatabase = (connectionString) => {
|
|
|
430
430
|
};
|
|
431
431
|
|
|
432
432
|
// src/handler.ts
|
|
433
|
-
import { OpenAPIHono as
|
|
433
|
+
import { OpenAPIHono as OpenAPIHono17 } from "@hono/zod-openapi";
|
|
434
434
|
import { getCookie as getCookie3 } from "hono/cookie";
|
|
435
435
|
|
|
436
436
|
// src/db/orm/session.ts
|
|
@@ -691,8 +691,104 @@ var hashToken = async (token, secret) => {
|
|
|
691
691
|
};
|
|
692
692
|
var generateToken = (bytes = 48) => randomHex(bytes);
|
|
693
693
|
|
|
694
|
+
// src/lib/error-handler.ts
|
|
695
|
+
import { logger } from "@mesob/common";
|
|
696
|
+
import { HTTPException } from "hono/http-exception";
|
|
697
|
+
var isDatabaseError = (error) => {
|
|
698
|
+
if (typeof error !== "object" || error === null) {
|
|
699
|
+
return false;
|
|
700
|
+
}
|
|
701
|
+
if ("code" in error || "query" in error || "detail" in error) {
|
|
702
|
+
return true;
|
|
703
|
+
}
|
|
704
|
+
if (error instanceof Error) {
|
|
705
|
+
const message = error.message.toLowerCase();
|
|
706
|
+
return message.includes("failed query") || message.includes("relation") || message.includes("column") || message.includes("syntax error") || message.includes("duplicate key") || message.includes("foreign key") || message.includes("null value");
|
|
707
|
+
}
|
|
708
|
+
return false;
|
|
709
|
+
};
|
|
710
|
+
var sanitizeDatabaseError = (error) => {
|
|
711
|
+
const code = error.code;
|
|
712
|
+
if (code === "23505") {
|
|
713
|
+
return "Resource already exists";
|
|
714
|
+
}
|
|
715
|
+
if (code === "23503") {
|
|
716
|
+
return "Referenced resource not found";
|
|
717
|
+
}
|
|
718
|
+
if (code === "23502") {
|
|
719
|
+
return "Required field is missing";
|
|
720
|
+
}
|
|
721
|
+
if (code === "42P01") {
|
|
722
|
+
return "Resource not found";
|
|
723
|
+
}
|
|
724
|
+
if (code === "42703") {
|
|
725
|
+
return "Invalid request";
|
|
726
|
+
}
|
|
727
|
+
if (code === "23514") {
|
|
728
|
+
return "Validation failed";
|
|
729
|
+
}
|
|
730
|
+
return "An error occurred while processing your request";
|
|
731
|
+
};
|
|
732
|
+
var isDatabaseErrorMessage = (message) => {
|
|
733
|
+
const lowerMessage = message.toLowerCase();
|
|
734
|
+
return lowerMessage.includes("failed query") || lowerMessage.includes("select") || lowerMessage.includes("insert") || lowerMessage.includes("update") || lowerMessage.includes("delete") || lowerMessage.includes("from") || lowerMessage.includes("where") || lowerMessage.includes("limit") || lowerMessage.includes("params:") || lowerMessage.includes("query") || message.includes('"iam".') || message.includes('"tenants"') || message.includes('"users"') || message.includes('"sessions"') || message.includes('"accounts"') || lowerMessage.includes("relation") || lowerMessage.includes("column") || lowerMessage.includes("syntax error") || lowerMessage.includes("database") || lowerMessage.includes("postgres") || lowerMessage.includes("sql");
|
|
735
|
+
};
|
|
736
|
+
var handleError = (error, c) => {
|
|
737
|
+
logger.error("API Error:", {
|
|
738
|
+
error,
|
|
739
|
+
path: c.req.path,
|
|
740
|
+
method: c.req.method,
|
|
741
|
+
url: c.req.url
|
|
742
|
+
});
|
|
743
|
+
if (error instanceof HTTPException) {
|
|
744
|
+
const message = isDatabaseErrorMessage(error.message) ? "An error occurred while processing your request" : error.message;
|
|
745
|
+
return c.json({ error: message }, error.status);
|
|
746
|
+
}
|
|
747
|
+
if (isDatabaseError(error)) {
|
|
748
|
+
const userMessage = sanitizeDatabaseError(error);
|
|
749
|
+
logger.error("Database error details:", {
|
|
750
|
+
code: error.code,
|
|
751
|
+
message: error.message,
|
|
752
|
+
detail: error.detail,
|
|
753
|
+
query: error.query,
|
|
754
|
+
parameters: error.parameters
|
|
755
|
+
});
|
|
756
|
+
return c.json({ error: userMessage }, 500);
|
|
757
|
+
}
|
|
758
|
+
if (error instanceof Error) {
|
|
759
|
+
const message = error.message;
|
|
760
|
+
const lowerMessage = message.toLowerCase();
|
|
761
|
+
const isDatabaseError2 = lowerMessage.includes("failed query") || lowerMessage.includes("select") || lowerMessage.includes("insert") || lowerMessage.includes("update") || lowerMessage.includes("delete") || lowerMessage.includes("from") || lowerMessage.includes("where") || lowerMessage.includes("limit") || lowerMessage.includes("params:") || lowerMessage.includes("query") || message.includes('"iam".') || message.includes('"tenants"') || message.includes('"users"') || message.includes('"sessions"') || message.includes('"accounts"') || lowerMessage.includes("relation") || lowerMessage.includes("column") || lowerMessage.includes("syntax error") || lowerMessage.includes("duplicate key") || lowerMessage.includes("foreign key") || lowerMessage.includes("null value") || lowerMessage.includes("database") || lowerMessage.includes("postgres") || lowerMessage.includes("sql");
|
|
762
|
+
if (isDatabaseError2) {
|
|
763
|
+
logger.error("SQL/database error detected:", {
|
|
764
|
+
message: error.message,
|
|
765
|
+
stack: error.stack,
|
|
766
|
+
name: error.name
|
|
767
|
+
});
|
|
768
|
+
return c.json(
|
|
769
|
+
{ error: "An error occurred while processing your request" },
|
|
770
|
+
500
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
logger.error("Error details:", {
|
|
774
|
+
message: error.message,
|
|
775
|
+
stack: error.stack,
|
|
776
|
+
name: error.name
|
|
777
|
+
});
|
|
778
|
+
return c.json(
|
|
779
|
+
{ error: "An error occurred while processing your request" },
|
|
780
|
+
500
|
|
781
|
+
);
|
|
782
|
+
}
|
|
783
|
+
logger.error("Unknown error:", error);
|
|
784
|
+
return c.json(
|
|
785
|
+
{ error: "An error occurred while processing your request" },
|
|
786
|
+
500
|
|
787
|
+
);
|
|
788
|
+
};
|
|
789
|
+
|
|
694
790
|
// src/routes/index.ts
|
|
695
|
-
import { OpenAPIHono as
|
|
791
|
+
import { OpenAPIHono as OpenAPIHono16 } from "@hono/zod-openapi";
|
|
696
792
|
|
|
697
793
|
// src/routes/auth/auth.route.ts
|
|
698
794
|
import { createRoute, OpenAPIHono } from "@hono/zod-openapi";
|
|
@@ -804,11 +900,12 @@ var verifyPasswordSchema = z.object({
|
|
|
804
900
|
var messageWithVerificationIdSchema = messageSchema.extend({
|
|
805
901
|
verificationId: z.string().uuid().optional()
|
|
806
902
|
});
|
|
807
|
-
var
|
|
808
|
-
|
|
903
|
+
var checkAccountSchema = z.object({
|
|
904
|
+
username: z.string()
|
|
809
905
|
});
|
|
810
|
-
var
|
|
811
|
-
exists: z.boolean()
|
|
906
|
+
var checkAccountResponseSchema = z.object({
|
|
907
|
+
exists: z.boolean(),
|
|
908
|
+
verified: z.boolean()
|
|
812
909
|
});
|
|
813
910
|
var updateProfileSchema = z.object({
|
|
814
911
|
fullName: z.string().min(1).max(255).optional().describe("User full name")
|
|
@@ -833,131 +930,55 @@ var pendingAccountChangeResponseSchema = z.object({
|
|
|
833
930
|
verificationId: z.string().uuid().nullable()
|
|
834
931
|
});
|
|
835
932
|
|
|
836
|
-
// src/routes/auth/handler/check-
|
|
933
|
+
// src/routes/auth/handler/check-account.ts
|
|
837
934
|
import { and as and4, eq as eq4, sql as sql4 } from "drizzle-orm";
|
|
838
935
|
|
|
839
936
|
// src/lib/tenant.ts
|
|
840
|
-
import { HTTPException } from "hono/http-exception";
|
|
937
|
+
import { HTTPException as HTTPException2 } from "hono/http-exception";
|
|
841
938
|
var ensureTenantId = (config, tenantId) => {
|
|
842
939
|
const enableTenant = config.tenant?.enabled ?? true;
|
|
843
940
|
if (enableTenant) {
|
|
844
941
|
if (!tenantId) {
|
|
845
|
-
throw new
|
|
942
|
+
throw new HTTPException2(400, {
|
|
846
943
|
message: "Missing tenantId. Tenant isolation is enabled."
|
|
847
944
|
});
|
|
848
945
|
}
|
|
849
946
|
return tenantId;
|
|
850
947
|
}
|
|
851
948
|
if (!config.tenant?.tenantId) {
|
|
852
|
-
throw new
|
|
949
|
+
throw new HTTPException2(500, {
|
|
853
950
|
message: "tenantId must be provided in config.tenant when tenant.enabled is false."
|
|
854
951
|
});
|
|
855
952
|
}
|
|
856
953
|
return config.tenant.tenantId;
|
|
857
954
|
};
|
|
858
955
|
|
|
859
|
-
// src/routes/auth/handler/check-
|
|
860
|
-
var
|
|
956
|
+
// src/routes/auth/handler/check-account.ts
|
|
957
|
+
var checkAccountHandler = async (c) => {
|
|
861
958
|
const body = c.req.valid("json");
|
|
862
959
|
const config = c.get("config");
|
|
863
960
|
const database = c.get("database");
|
|
864
961
|
const tenantId = c.get("tenantId");
|
|
865
962
|
const resolvedTenantId = ensureTenantId(config, tenantId);
|
|
866
|
-
const {
|
|
867
|
-
const isEmail =
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
'id', ${userRolesInIam.id},
|
|
886
|
-
'roleId', ${rolesInIam.id},
|
|
887
|
-
'code', ${rolesInIam.code},
|
|
888
|
-
'name', ${rolesInIam.name},
|
|
889
|
-
'description', ${rolesInIam.description}
|
|
890
|
-
)
|
|
891
|
-
) FILTER (WHERE ${userRolesInIam.id} IS NOT NULL),
|
|
892
|
-
'[]'::json
|
|
893
|
-
)
|
|
894
|
-
`
|
|
895
|
-
}).from(usersInIam).leftJoin(
|
|
896
|
-
userRolesInIam,
|
|
897
|
-
and4(
|
|
898
|
-
eq4(userRolesInIam.userId, usersInIam.id),
|
|
899
|
-
eq4(userRolesInIam.tenantId, resolvedTenantId)
|
|
900
|
-
)
|
|
901
|
-
).leftJoin(
|
|
902
|
-
rolesInIam,
|
|
903
|
-
and4(
|
|
904
|
-
eq4(userRolesInIam.roleId, rolesInIam.id),
|
|
905
|
-
eq4(rolesInIam.tenantId, resolvedTenantId)
|
|
906
|
-
)
|
|
907
|
-
).where(
|
|
908
|
-
and4(
|
|
909
|
-
eq4(usersInIam.tenantId, resolvedTenantId),
|
|
910
|
-
sql4`lower(${usersInIam.email}) = lower(${identifier})`
|
|
911
|
-
)
|
|
912
|
-
).groupBy(usersInIam.id).limit(1);
|
|
913
|
-
user = result || null;
|
|
914
|
-
} else {
|
|
915
|
-
const [result] = await database.select({
|
|
916
|
-
id: usersInIam.id,
|
|
917
|
-
tenantId: usersInIam.tenantId,
|
|
918
|
-
fullName: usersInIam.fullName,
|
|
919
|
-
email: usersInIam.email,
|
|
920
|
-
phone: usersInIam.phone,
|
|
921
|
-
handle: usersInIam.handle,
|
|
922
|
-
image: usersInIam.image,
|
|
923
|
-
emailVerified: usersInIam.emailVerified,
|
|
924
|
-
phoneVerified: usersInIam.phoneVerified,
|
|
925
|
-
lastSignInAt: usersInIam.lastSignInAt,
|
|
926
|
-
userRoles: sql4`
|
|
927
|
-
COALESCE(
|
|
928
|
-
json_agg(
|
|
929
|
-
json_build_object(
|
|
930
|
-
'id', ${userRolesInIam.id},
|
|
931
|
-
'roleId', ${rolesInIam.id},
|
|
932
|
-
'code', ${rolesInIam.code},
|
|
933
|
-
'name', ${rolesInIam.name},
|
|
934
|
-
'description', ${rolesInIam.description}
|
|
935
|
-
)
|
|
936
|
-
) FILTER (WHERE ${userRolesInIam.id} IS NOT NULL),
|
|
937
|
-
'[]'::json
|
|
938
|
-
)
|
|
939
|
-
`
|
|
940
|
-
}).from(usersInIam).leftJoin(
|
|
941
|
-
userRolesInIam,
|
|
942
|
-
and4(
|
|
943
|
-
eq4(userRolesInIam.userId, usersInIam.id),
|
|
944
|
-
eq4(userRolesInIam.tenantId, resolvedTenantId)
|
|
945
|
-
)
|
|
946
|
-
).leftJoin(
|
|
947
|
-
rolesInIam,
|
|
948
|
-
and4(
|
|
949
|
-
eq4(userRolesInIam.roleId, rolesInIam.id),
|
|
950
|
-
eq4(rolesInIam.tenantId, resolvedTenantId)
|
|
951
|
-
)
|
|
952
|
-
).where(
|
|
953
|
-
and4(
|
|
954
|
-
eq4(usersInIam.tenantId, resolvedTenantId),
|
|
955
|
-
eq4(usersInIam.phone, identifier)
|
|
956
|
-
)
|
|
957
|
-
).groupBy(usersInIam.id).limit(1);
|
|
958
|
-
user = result || null;
|
|
959
|
-
}
|
|
960
|
-
return c.json({ exists: !!user }, 200);
|
|
963
|
+
const { username } = body;
|
|
964
|
+
const isEmail = username.includes("@");
|
|
965
|
+
const whereClause = isEmail ? and4(
|
|
966
|
+
eq4(usersInIam.tenantId, resolvedTenantId),
|
|
967
|
+
sql4`lower(${usersInIam.email}) = lower(${username})`
|
|
968
|
+
) : and4(
|
|
969
|
+
eq4(usersInIam.tenantId, resolvedTenantId),
|
|
970
|
+
eq4(usersInIam.phone, username)
|
|
971
|
+
);
|
|
972
|
+
const [result] = await database.select({
|
|
973
|
+
verified: isEmail ? usersInIam.emailVerified : usersInIam.phoneVerified
|
|
974
|
+
}).from(usersInIam).where(whereClause).limit(1);
|
|
975
|
+
return c.json(
|
|
976
|
+
{
|
|
977
|
+
exists: !!result,
|
|
978
|
+
verified: result?.verified ?? false
|
|
979
|
+
},
|
|
980
|
+
200
|
|
981
|
+
);
|
|
961
982
|
};
|
|
962
983
|
|
|
963
984
|
// src/routes/auth/handler/sign-in.ts
|
|
@@ -1067,7 +1088,7 @@ var getRefreshedExpiresAt = ({
|
|
|
1067
1088
|
};
|
|
1068
1089
|
|
|
1069
1090
|
// src/routes/auth/helper/session.ts
|
|
1070
|
-
import { and as and5, asc, eq as eq5, gt as gt2, sql as sql5 } from "drizzle-orm";
|
|
1091
|
+
import { and as and5, asc, eq as eq5, gt as gt2, inArray, sql as sql5 } from "drizzle-orm";
|
|
1071
1092
|
var createSessionRecord = async ({
|
|
1072
1093
|
tx,
|
|
1073
1094
|
tenantId,
|
|
@@ -1160,7 +1181,10 @@ var cleanupOldSessions = async ({
|
|
|
1160
1181
|
and5(
|
|
1161
1182
|
eq5(sessionsInIam.tenantId, tenantId),
|
|
1162
1183
|
eq5(sessionsInIam.userId, userId),
|
|
1163
|
-
|
|
1184
|
+
inArray(
|
|
1185
|
+
sessionsInIam.id,
|
|
1186
|
+
idsToDelete.map((s) => s.id)
|
|
1187
|
+
)
|
|
1164
1188
|
)
|
|
1165
1189
|
);
|
|
1166
1190
|
};
|
|
@@ -1685,6 +1709,18 @@ function withTransaction(database, callback) {
|
|
|
1685
1709
|
return database.transaction(async (tx) => callback(tx));
|
|
1686
1710
|
}
|
|
1687
1711
|
|
|
1712
|
+
// src/lib/phone-validation.ts
|
|
1713
|
+
var createPhoneField = (config) => {
|
|
1714
|
+
const phoneRegex = config.phone.phoneRegex || /^(\+2519|\+2517|2519|2517|09|07)\d{8}$/;
|
|
1715
|
+
const regex = typeof phoneRegex === "string" ? new RegExp(phoneRegex) : phoneRegex;
|
|
1716
|
+
return {
|
|
1717
|
+
validate: (phone) => {
|
|
1718
|
+
return regex.test(phone.trim());
|
|
1719
|
+
},
|
|
1720
|
+
regex
|
|
1721
|
+
};
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1688
1724
|
// src/routes/auth/handler/sign-up.ts
|
|
1689
1725
|
var SignUpError = class extends Error {
|
|
1690
1726
|
constructor(message, status) {
|
|
@@ -1704,6 +1740,12 @@ var signUpHandler = async (c) => {
|
|
|
1704
1740
|
return c.json({ error: "Either email or phone is required" }, 409);
|
|
1705
1741
|
}
|
|
1706
1742
|
const isEmail = identifier.includes("@");
|
|
1743
|
+
if (phone) {
|
|
1744
|
+
const phoneValidator = createPhoneField(config);
|
|
1745
|
+
if (!phoneValidator.validate(phone)) {
|
|
1746
|
+
return c.json({ error: "Invalid phone number format" }, 400);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1707
1749
|
if (isEmail && !config.email.enabled) {
|
|
1708
1750
|
return c.json({ error: "Email authentication is disabled" }, 403);
|
|
1709
1751
|
}
|
|
@@ -1868,6 +1910,14 @@ var signUpRoute = createRoute({
|
|
|
1868
1910
|
},
|
|
1869
1911
|
description: "Account created"
|
|
1870
1912
|
},
|
|
1913
|
+
400: {
|
|
1914
|
+
content: {
|
|
1915
|
+
"application/json": {
|
|
1916
|
+
schema: errorResponseSchema
|
|
1917
|
+
}
|
|
1918
|
+
},
|
|
1919
|
+
description: "Invalid request"
|
|
1920
|
+
},
|
|
1871
1921
|
403: {
|
|
1872
1922
|
content: {
|
|
1873
1923
|
"application/json": {
|
|
@@ -1919,16 +1969,16 @@ var signInRoute = createRoute({
|
|
|
1919
1969
|
}
|
|
1920
1970
|
}
|
|
1921
1971
|
});
|
|
1922
|
-
var
|
|
1972
|
+
var checkAccountRoute = createRoute({
|
|
1923
1973
|
method: "post",
|
|
1924
|
-
path: "/check-
|
|
1974
|
+
path: "/check-account",
|
|
1925
1975
|
tags: ["Auth"],
|
|
1926
|
-
summary: "Check if
|
|
1976
|
+
summary: "Check if account exists",
|
|
1927
1977
|
request: {
|
|
1928
1978
|
body: {
|
|
1929
1979
|
content: {
|
|
1930
1980
|
"application/json": {
|
|
1931
|
-
schema:
|
|
1981
|
+
schema: checkAccountSchema
|
|
1932
1982
|
}
|
|
1933
1983
|
}
|
|
1934
1984
|
}
|
|
@@ -1937,10 +1987,10 @@ var checkUserRoute = createRoute({
|
|
|
1937
1987
|
200: {
|
|
1938
1988
|
content: {
|
|
1939
1989
|
"application/json": {
|
|
1940
|
-
schema:
|
|
1990
|
+
schema: checkAccountResponseSchema
|
|
1941
1991
|
}
|
|
1942
1992
|
},
|
|
1943
|
-
description: "
|
|
1993
|
+
description: "Account check result"
|
|
1944
1994
|
}
|
|
1945
1995
|
}
|
|
1946
1996
|
});
|
|
@@ -1956,7 +2006,7 @@ var signOutRoute = createRoute({
|
|
|
1956
2006
|
}
|
|
1957
2007
|
}
|
|
1958
2008
|
});
|
|
1959
|
-
var authRoutes = new OpenAPIHono().openapi(signUpRoute, signUpHandler).openapi(signInRoute, signInHandler).openapi(
|
|
2009
|
+
var authRoutes = new OpenAPIHono().openapi(signUpRoute, signUpHandler).openapi(signInRoute, signInHandler).openapi(checkAccountRoute, checkAccountHandler).openapi(signOutRoute, signOutHandler);
|
|
1960
2010
|
var auth_route_default = authRoutes;
|
|
1961
2011
|
|
|
1962
2012
|
// src/routes/domains/domains.route.ts
|
|
@@ -3385,6 +3435,10 @@ var phoneVerificationRequestHandler = async (c) => {
|
|
|
3385
3435
|
if (!phone) {
|
|
3386
3436
|
return c.json({ error: "Phone required" }, 400);
|
|
3387
3437
|
}
|
|
3438
|
+
const phoneValidator = createPhoneField(config);
|
|
3439
|
+
if (!phoneValidator.validate(phone)) {
|
|
3440
|
+
return c.json({ error: "Invalid phone number format" }, 400);
|
|
3441
|
+
}
|
|
3388
3442
|
const genericResponse = {
|
|
3389
3443
|
message: "If the account exists, a verification code was sent."
|
|
3390
3444
|
};
|
|
@@ -3662,19 +3716,38 @@ var meHandler = (c) => {
|
|
|
3662
3716
|
var sessionHandler = (c) => {
|
|
3663
3717
|
const user = c.get("user");
|
|
3664
3718
|
const session = c.get("session");
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3719
|
+
const status = c.get("sessionStatus");
|
|
3720
|
+
if (status === "no_cookie") {
|
|
3721
|
+
return c.json({ user: null, session: null }, 200);
|
|
3722
|
+
}
|
|
3723
|
+
if (status === "invalid_session") {
|
|
3724
|
+
return c.json({ error: "Invalid session", code: "INVALID_SESSION" }, 401);
|
|
3725
|
+
}
|
|
3726
|
+
if (status === "user_not_found") {
|
|
3727
|
+
return c.json({ error: "User not found", code: "USER_NOT_FOUND" }, 401);
|
|
3728
|
+
}
|
|
3729
|
+
if (status === "error") {
|
|
3730
|
+
return c.json(
|
|
3731
|
+
{ error: "Session check error", code: "SESSION_CHECK_ERROR" },
|
|
3732
|
+
500
|
|
3733
|
+
);
|
|
3734
|
+
}
|
|
3735
|
+
if (user && session) {
|
|
3736
|
+
return c.json(
|
|
3737
|
+
{
|
|
3738
|
+
user: normalizeUser(user),
|
|
3739
|
+
session: {
|
|
3740
|
+
id: session.id,
|
|
3741
|
+
expiresAt: session.expiresAt,
|
|
3742
|
+
createdAt: session.createdAt,
|
|
3743
|
+
userAgent: session.userAgent,
|
|
3744
|
+
ip: session.ip
|
|
3745
|
+
}
|
|
3746
|
+
},
|
|
3747
|
+
200
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
return c.json({ user: null, session: null }, 200);
|
|
3678
3751
|
};
|
|
3679
3752
|
|
|
3680
3753
|
// src/routes/profile/handler/update.ts
|
|
@@ -3802,6 +3875,10 @@ var updatePhoneHandler = async (c) => {
|
|
|
3802
3875
|
return c.json({ error: AUTH_ERRORS.UNAUTHORIZED }, 401);
|
|
3803
3876
|
}
|
|
3804
3877
|
const resolvedTenantId = ensureTenantId(config, tenantId);
|
|
3878
|
+
const phoneValidator = createPhoneField(config);
|
|
3879
|
+
if (!phoneValidator.validate(body.phone)) {
|
|
3880
|
+
return c.json({ error: "Invalid phone number format" }, 400);
|
|
3881
|
+
}
|
|
3805
3882
|
if (user.phone && session?.id) {
|
|
3806
3883
|
await database.delete(sessionsInIam).where(
|
|
3807
3884
|
and27(
|
|
@@ -3896,7 +3973,23 @@ var sessionRoute = createRoute7({
|
|
|
3896
3973
|
})
|
|
3897
3974
|
}
|
|
3898
3975
|
},
|
|
3899
|
-
description: "
|
|
3976
|
+
description: "Session info (null if no cookie sent)"
|
|
3977
|
+
},
|
|
3978
|
+
401: {
|
|
3979
|
+
content: {
|
|
3980
|
+
"application/json": {
|
|
3981
|
+
schema: errorResponseSchema
|
|
3982
|
+
}
|
|
3983
|
+
},
|
|
3984
|
+
description: "Invalid session (cookie sent but invalid/expired)"
|
|
3985
|
+
},
|
|
3986
|
+
500: {
|
|
3987
|
+
content: {
|
|
3988
|
+
"application/json": {
|
|
3989
|
+
schema: errorResponseSchema
|
|
3990
|
+
}
|
|
3991
|
+
},
|
|
3992
|
+
description: "Server error checking session"
|
|
3900
3993
|
}
|
|
3901
3994
|
}
|
|
3902
3995
|
});
|
|
@@ -4005,6 +4098,14 @@ var updatePhoneRoute = createRoute7({
|
|
|
4005
4098
|
},
|
|
4006
4099
|
description: "Phone updated"
|
|
4007
4100
|
},
|
|
4101
|
+
400: {
|
|
4102
|
+
content: {
|
|
4103
|
+
"application/json": {
|
|
4104
|
+
schema: errorResponseSchema
|
|
4105
|
+
}
|
|
4106
|
+
},
|
|
4107
|
+
description: "Invalid request"
|
|
4108
|
+
},
|
|
4008
4109
|
401: {
|
|
4009
4110
|
content: {
|
|
4010
4111
|
"application/json": {
|
|
@@ -4713,8 +4814,69 @@ var revokeAllSessionsRoute = createRoute10({
|
|
|
4713
4814
|
var sessionRoutes = new OpenAPIHono10().openapi(listSessionsRoute, listSessionsHandler).openapi(getSessionRoute, getSessionHandler).openapi(revokeSessionRoute, revokeSessionHandler).openapi(revokeAllSessionsRoute, revokeAllSessionsHandler);
|
|
4714
4815
|
var sessions_route_default = sessionRoutes;
|
|
4715
4816
|
|
|
4716
|
-
// src/routes/
|
|
4817
|
+
// src/routes/system/system.route.ts
|
|
4717
4818
|
import { createRoute as createRoute11, OpenAPIHono as OpenAPIHono11 } from "@hono/zod-openapi";
|
|
4819
|
+
import { z as z8 } from "zod";
|
|
4820
|
+
|
|
4821
|
+
// src/routes/system/handler/tenant.ts
|
|
4822
|
+
var tenantHandler = (c) => {
|
|
4823
|
+
const tenantId = c.get("tenantId");
|
|
4824
|
+
const tenant = c.get("tenant");
|
|
4825
|
+
const host = c.get("host");
|
|
4826
|
+
return c.json(
|
|
4827
|
+
{
|
|
4828
|
+
host: host || null,
|
|
4829
|
+
tenantId: tenantId || null,
|
|
4830
|
+
tenant: tenant || null,
|
|
4831
|
+
status: "ok"
|
|
4832
|
+
},
|
|
4833
|
+
200
|
|
4834
|
+
);
|
|
4835
|
+
};
|
|
4836
|
+
|
|
4837
|
+
// src/routes/system/system.route.ts
|
|
4838
|
+
var tenantRoute = createRoute11({
|
|
4839
|
+
method: "get",
|
|
4840
|
+
path: "/init",
|
|
4841
|
+
tags: ["System"],
|
|
4842
|
+
summary: "Get tenant info",
|
|
4843
|
+
responses: {
|
|
4844
|
+
200: {
|
|
4845
|
+
content: {
|
|
4846
|
+
"application/json": {
|
|
4847
|
+
schema: z8.object({
|
|
4848
|
+
host: z8.string().nullable(),
|
|
4849
|
+
tenantId: z8.string().nullable(),
|
|
4850
|
+
tenant: z8.object({
|
|
4851
|
+
id: z8.string(),
|
|
4852
|
+
name: z8.unknown(),
|
|
4853
|
+
description: z8.unknown(),
|
|
4854
|
+
isActive: z8.boolean()
|
|
4855
|
+
}).nullable(),
|
|
4856
|
+
status: z8.literal("ok")
|
|
4857
|
+
})
|
|
4858
|
+
}
|
|
4859
|
+
},
|
|
4860
|
+
description: "Tenant info"
|
|
4861
|
+
},
|
|
4862
|
+
500: {
|
|
4863
|
+
content: {
|
|
4864
|
+
"application/json": {
|
|
4865
|
+
schema: errorResponseSchema
|
|
4866
|
+
}
|
|
4867
|
+
},
|
|
4868
|
+
description: "Server error"
|
|
4869
|
+
}
|
|
4870
|
+
}
|
|
4871
|
+
});
|
|
4872
|
+
var tenantRoutes = new OpenAPIHono11().openapi(
|
|
4873
|
+
tenantRoute,
|
|
4874
|
+
tenantHandler
|
|
4875
|
+
);
|
|
4876
|
+
var system_route_default = tenantRoutes;
|
|
4877
|
+
|
|
4878
|
+
// src/routes/tenants/tenants.route.ts
|
|
4879
|
+
import { createRoute as createRoute12, OpenAPIHono as OpenAPIHono12 } from "@hono/zod-openapi";
|
|
4718
4880
|
|
|
4719
4881
|
// src/routes/tenants/handler/create-tenant.ts
|
|
4720
4882
|
import { eq as eq38 } from "drizzle-orm";
|
|
@@ -4846,79 +5008,79 @@ var updateTenantHandler = async (c) => {
|
|
|
4846
5008
|
};
|
|
4847
5009
|
|
|
4848
5010
|
// src/routes/tenants/tenants.schema.ts
|
|
4849
|
-
import { z as
|
|
4850
|
-
var listTenantsQuerySchema =
|
|
4851
|
-
page:
|
|
4852
|
-
limit:
|
|
4853
|
-
isActive:
|
|
4854
|
-
});
|
|
4855
|
-
var tenantIdParamSchema =
|
|
4856
|
-
id:
|
|
4857
|
-
});
|
|
4858
|
-
var createTenantSchema =
|
|
4859
|
-
id:
|
|
4860
|
-
name:
|
|
4861
|
-
description:
|
|
4862
|
-
theme:
|
|
4863
|
-
supportedLanguages:
|
|
4864
|
-
defaultLanguage:
|
|
4865
|
-
supportedCurrency:
|
|
4866
|
-
defaultCurrency:
|
|
4867
|
-
timezone:
|
|
4868
|
-
isActive:
|
|
4869
|
-
locale:
|
|
4870
|
-
settings:
|
|
4871
|
-
seo:
|
|
4872
|
-
});
|
|
4873
|
-
var updateTenantSchema =
|
|
4874
|
-
name:
|
|
4875
|
-
description:
|
|
4876
|
-
theme:
|
|
4877
|
-
supportedLanguages:
|
|
4878
|
-
defaultLanguage:
|
|
4879
|
-
supportedCurrency:
|
|
4880
|
-
defaultCurrency:
|
|
4881
|
-
timezone:
|
|
4882
|
-
isActive:
|
|
4883
|
-
locale:
|
|
4884
|
-
settings:
|
|
4885
|
-
seo:
|
|
4886
|
-
});
|
|
4887
|
-
var tenantSchema =
|
|
4888
|
-
id:
|
|
4889
|
-
createdAt:
|
|
4890
|
-
updatedAt:
|
|
4891
|
-
name:
|
|
4892
|
-
description:
|
|
4893
|
-
theme:
|
|
4894
|
-
supportedLanguages:
|
|
4895
|
-
defaultLanguage:
|
|
4896
|
-
supportedCurrency:
|
|
4897
|
-
defaultCurrency:
|
|
4898
|
-
timezone:
|
|
4899
|
-
isActive:
|
|
4900
|
-
locale:
|
|
4901
|
-
settings:
|
|
4902
|
-
seo:
|
|
4903
|
-
});
|
|
4904
|
-
var listTenantsResponseSchema =
|
|
4905
|
-
tenants:
|
|
4906
|
-
total:
|
|
4907
|
-
page:
|
|
4908
|
-
limit:
|
|
4909
|
-
});
|
|
4910
|
-
var tenantResponseSchema =
|
|
5011
|
+
import { z as z9 } from "zod";
|
|
5012
|
+
var listTenantsQuerySchema = z9.object({
|
|
5013
|
+
page: z9.coerce.number().min(1).default(1).optional(),
|
|
5014
|
+
limit: z9.coerce.number().min(1).max(100).default(20).optional(),
|
|
5015
|
+
isActive: z9.coerce.boolean().optional()
|
|
5016
|
+
});
|
|
5017
|
+
var tenantIdParamSchema = z9.object({
|
|
5018
|
+
id: z9.string()
|
|
5019
|
+
});
|
|
5020
|
+
var createTenantSchema = z9.object({
|
|
5021
|
+
id: z9.string().max(30),
|
|
5022
|
+
name: z9.unknown(),
|
|
5023
|
+
description: z9.unknown().optional(),
|
|
5024
|
+
theme: z9.unknown().optional(),
|
|
5025
|
+
supportedLanguages: z9.unknown().optional(),
|
|
5026
|
+
defaultLanguage: z9.string().optional(),
|
|
5027
|
+
supportedCurrency: z9.unknown().optional(),
|
|
5028
|
+
defaultCurrency: z9.string().optional(),
|
|
5029
|
+
timezone: z9.string().optional(),
|
|
5030
|
+
isActive: z9.boolean().default(true).optional(),
|
|
5031
|
+
locale: z9.unknown().optional(),
|
|
5032
|
+
settings: z9.unknown().optional(),
|
|
5033
|
+
seo: z9.unknown().optional()
|
|
5034
|
+
});
|
|
5035
|
+
var updateTenantSchema = z9.object({
|
|
5036
|
+
name: z9.unknown().optional(),
|
|
5037
|
+
description: z9.unknown().nullable().optional(),
|
|
5038
|
+
theme: z9.unknown().nullable().optional(),
|
|
5039
|
+
supportedLanguages: z9.unknown().nullable().optional(),
|
|
5040
|
+
defaultLanguage: z9.string().nullable().optional(),
|
|
5041
|
+
supportedCurrency: z9.unknown().nullable().optional(),
|
|
5042
|
+
defaultCurrency: z9.string().nullable().optional(),
|
|
5043
|
+
timezone: z9.string().nullable().optional(),
|
|
5044
|
+
isActive: z9.boolean().optional(),
|
|
5045
|
+
locale: z9.unknown().nullable().optional(),
|
|
5046
|
+
settings: z9.unknown().nullable().optional(),
|
|
5047
|
+
seo: z9.unknown().nullable().optional()
|
|
5048
|
+
});
|
|
5049
|
+
var tenantSchema = z9.object({
|
|
5050
|
+
id: z9.string(),
|
|
5051
|
+
createdAt: z9.string(),
|
|
5052
|
+
updatedAt: z9.string(),
|
|
5053
|
+
name: z9.unknown(),
|
|
5054
|
+
description: z9.unknown().nullable(),
|
|
5055
|
+
theme: z9.unknown().nullable(),
|
|
5056
|
+
supportedLanguages: z9.unknown().nullable(),
|
|
5057
|
+
defaultLanguage: z9.string().nullable(),
|
|
5058
|
+
supportedCurrency: z9.unknown().nullable(),
|
|
5059
|
+
defaultCurrency: z9.string().nullable(),
|
|
5060
|
+
timezone: z9.string().nullable(),
|
|
5061
|
+
isActive: z9.boolean(),
|
|
5062
|
+
locale: z9.unknown().nullable(),
|
|
5063
|
+
settings: z9.unknown().nullable(),
|
|
5064
|
+
seo: z9.unknown().nullable()
|
|
5065
|
+
});
|
|
5066
|
+
var listTenantsResponseSchema = z9.object({
|
|
5067
|
+
tenants: z9.array(tenantSchema),
|
|
5068
|
+
total: z9.number(),
|
|
5069
|
+
page: z9.number(),
|
|
5070
|
+
limit: z9.number()
|
|
5071
|
+
});
|
|
5072
|
+
var tenantResponseSchema = z9.object({
|
|
4911
5073
|
tenant: tenantSchema
|
|
4912
5074
|
});
|
|
4913
|
-
var deleteTenantResponseSchema =
|
|
4914
|
-
message:
|
|
5075
|
+
var deleteTenantResponseSchema = z9.object({
|
|
5076
|
+
message: z9.string()
|
|
4915
5077
|
});
|
|
4916
|
-
var errorResponseSchema7 =
|
|
4917
|
-
error:
|
|
5078
|
+
var errorResponseSchema7 = z9.object({
|
|
5079
|
+
error: z9.string()
|
|
4918
5080
|
});
|
|
4919
5081
|
|
|
4920
5082
|
// src/routes/tenants/tenants.route.ts
|
|
4921
|
-
var listTenantsRoute =
|
|
5083
|
+
var listTenantsRoute = createRoute12({
|
|
4922
5084
|
method: "get",
|
|
4923
5085
|
path: "/",
|
|
4924
5086
|
tags: ["Tenants"],
|
|
@@ -4937,7 +5099,7 @@ var listTenantsRoute = createRoute11({
|
|
|
4937
5099
|
}
|
|
4938
5100
|
}
|
|
4939
5101
|
});
|
|
4940
|
-
var getTenantRoute =
|
|
5102
|
+
var getTenantRoute = createRoute12({
|
|
4941
5103
|
method: "get",
|
|
4942
5104
|
path: "/{id}",
|
|
4943
5105
|
tags: ["Tenants"],
|
|
@@ -4964,7 +5126,7 @@ var getTenantRoute = createRoute11({
|
|
|
4964
5126
|
}
|
|
4965
5127
|
}
|
|
4966
5128
|
});
|
|
4967
|
-
var createTenantRoute =
|
|
5129
|
+
var createTenantRoute = createRoute12({
|
|
4968
5130
|
method: "post",
|
|
4969
5131
|
path: "/",
|
|
4970
5132
|
tags: ["Tenants"],
|
|
@@ -4997,7 +5159,7 @@ var createTenantRoute = createRoute11({
|
|
|
4997
5159
|
}
|
|
4998
5160
|
}
|
|
4999
5161
|
});
|
|
5000
|
-
var updateTenantRoute =
|
|
5162
|
+
var updateTenantRoute = createRoute12({
|
|
5001
5163
|
method: "put",
|
|
5002
5164
|
path: "/{id}",
|
|
5003
5165
|
tags: ["Tenants"],
|
|
@@ -5031,7 +5193,7 @@ var updateTenantRoute = createRoute11({
|
|
|
5031
5193
|
}
|
|
5032
5194
|
}
|
|
5033
5195
|
});
|
|
5034
|
-
var deleteTenantRoute =
|
|
5196
|
+
var deleteTenantRoute = createRoute12({
|
|
5035
5197
|
method: "delete",
|
|
5036
5198
|
path: "/{id}",
|
|
5037
5199
|
tags: ["Tenants"],
|
|
@@ -5058,11 +5220,11 @@ var deleteTenantRoute = createRoute11({
|
|
|
5058
5220
|
}
|
|
5059
5221
|
}
|
|
5060
5222
|
});
|
|
5061
|
-
var
|
|
5062
|
-
var tenants_route_default =
|
|
5223
|
+
var tenantRoutes2 = new OpenAPIHono12().openapi(listTenantsRoute, listTenantsHandler).openapi(getTenantRoute, getTenantHandler).openapi(createTenantRoute, createTenantHandler).openapi(updateTenantRoute, updateTenantHandler).openapi(deleteTenantRoute, deleteTenantHandler);
|
|
5224
|
+
var tenants_route_default = tenantRoutes2;
|
|
5063
5225
|
|
|
5064
5226
|
// src/routes/user-roles/user-roles.route.ts
|
|
5065
|
-
import { createRoute as
|
|
5227
|
+
import { createRoute as createRoute13, OpenAPIHono as OpenAPIHono13 } from "@hono/zod-openapi";
|
|
5066
5228
|
|
|
5067
5229
|
// src/routes/user-roles/handler/assign-user-role.ts
|
|
5068
5230
|
var assignUserRoleHandler = async (c) => {
|
|
@@ -5122,39 +5284,39 @@ var revokeUserRoleHandler = async (c) => {
|
|
|
5122
5284
|
};
|
|
5123
5285
|
|
|
5124
5286
|
// src/routes/user-roles/user-roles.schema.ts
|
|
5125
|
-
import { z as
|
|
5126
|
-
var listUserRolesQuerySchema =
|
|
5127
|
-
userId:
|
|
5128
|
-
roleId:
|
|
5287
|
+
import { z as z10 } from "zod";
|
|
5288
|
+
var listUserRolesQuerySchema = z10.object({
|
|
5289
|
+
userId: z10.uuid().optional(),
|
|
5290
|
+
roleId: z10.uuid().optional()
|
|
5129
5291
|
});
|
|
5130
|
-
var userRoleIdParamSchema =
|
|
5131
|
-
id:
|
|
5292
|
+
var userRoleIdParamSchema = z10.object({
|
|
5293
|
+
id: z10.uuid()
|
|
5132
5294
|
});
|
|
5133
|
-
var assignUserRoleSchema =
|
|
5134
|
-
userId:
|
|
5135
|
-
roleId:
|
|
5295
|
+
var assignUserRoleSchema = z10.object({
|
|
5296
|
+
userId: z10.uuid(),
|
|
5297
|
+
roleId: z10.uuid()
|
|
5136
5298
|
});
|
|
5137
|
-
var userRoleSchema2 =
|
|
5138
|
-
id:
|
|
5139
|
-
tenantId:
|
|
5140
|
-
userId:
|
|
5141
|
-
roleId:
|
|
5299
|
+
var userRoleSchema2 = z10.object({
|
|
5300
|
+
id: z10.uuid(),
|
|
5301
|
+
tenantId: z10.string(),
|
|
5302
|
+
userId: z10.uuid(),
|
|
5303
|
+
roleId: z10.uuid()
|
|
5142
5304
|
});
|
|
5143
|
-
var listUserRolesResponseSchema =
|
|
5144
|
-
userRoles:
|
|
5305
|
+
var listUserRolesResponseSchema = z10.object({
|
|
5306
|
+
userRoles: z10.array(userRoleSchema2)
|
|
5145
5307
|
});
|
|
5146
|
-
var userRoleResponseSchema =
|
|
5308
|
+
var userRoleResponseSchema = z10.object({
|
|
5147
5309
|
userRole: userRoleSchema2
|
|
5148
5310
|
});
|
|
5149
|
-
var revokeUserRoleResponseSchema =
|
|
5150
|
-
message:
|
|
5311
|
+
var revokeUserRoleResponseSchema = z10.object({
|
|
5312
|
+
message: z10.string()
|
|
5151
5313
|
});
|
|
5152
|
-
var errorResponseSchema8 =
|
|
5153
|
-
error:
|
|
5314
|
+
var errorResponseSchema8 = z10.object({
|
|
5315
|
+
error: z10.string()
|
|
5154
5316
|
});
|
|
5155
5317
|
|
|
5156
5318
|
// src/routes/user-roles/user-roles.route.ts
|
|
5157
|
-
var listUserRolesRoute =
|
|
5319
|
+
var listUserRolesRoute = createRoute13({
|
|
5158
5320
|
method: "get",
|
|
5159
5321
|
path: "/",
|
|
5160
5322
|
tags: ["User Roles"],
|
|
@@ -5173,7 +5335,7 @@ var listUserRolesRoute = createRoute12({
|
|
|
5173
5335
|
}
|
|
5174
5336
|
}
|
|
5175
5337
|
});
|
|
5176
|
-
var assignUserRoleRoute =
|
|
5338
|
+
var assignUserRoleRoute = createRoute13({
|
|
5177
5339
|
method: "post",
|
|
5178
5340
|
path: "/",
|
|
5179
5341
|
tags: ["User Roles"],
|
|
@@ -5206,7 +5368,7 @@ var assignUserRoleRoute = createRoute12({
|
|
|
5206
5368
|
}
|
|
5207
5369
|
}
|
|
5208
5370
|
});
|
|
5209
|
-
var revokeUserRoleRoute =
|
|
5371
|
+
var revokeUserRoleRoute = createRoute13({
|
|
5210
5372
|
method: "delete",
|
|
5211
5373
|
path: "/{id}",
|
|
5212
5374
|
tags: ["User Roles"],
|
|
@@ -5233,11 +5395,11 @@ var revokeUserRoleRoute = createRoute12({
|
|
|
5233
5395
|
}
|
|
5234
5396
|
}
|
|
5235
5397
|
});
|
|
5236
|
-
var userRoleRoutes = new
|
|
5398
|
+
var userRoleRoutes = new OpenAPIHono13().openapi(listUserRolesRoute, listUserRolesHandler).openapi(assignUserRoleRoute, assignUserRoleHandler).openapi(revokeUserRoleRoute, revokeUserRoleHandler);
|
|
5237
5399
|
var user_roles_route_default = userRoleRoutes;
|
|
5238
5400
|
|
|
5239
5401
|
// src/routes/users/users.route.ts
|
|
5240
|
-
import { createRoute as
|
|
5402
|
+
import { createRoute as createRoute14, OpenAPIHono as OpenAPIHono14 } from "@hono/zod-openapi";
|
|
5241
5403
|
|
|
5242
5404
|
// src/routes/users/handler/ban-user.ts
|
|
5243
5405
|
import { and as and41, eq as eq45, sql as sql22 } from "drizzle-orm";
|
|
@@ -5528,72 +5690,72 @@ var updateUserHandler = async (c) => {
|
|
|
5528
5690
|
};
|
|
5529
5691
|
|
|
5530
5692
|
// src/routes/users/users.schema.ts
|
|
5531
|
-
import { z as
|
|
5532
|
-
var listUsersQuerySchema =
|
|
5533
|
-
page:
|
|
5534
|
-
limit:
|
|
5535
|
-
tenantId:
|
|
5536
|
-
email:
|
|
5537
|
-
phone:
|
|
5538
|
-
handle:
|
|
5539
|
-
});
|
|
5540
|
-
var userIdParamSchema2 =
|
|
5541
|
-
id:
|
|
5693
|
+
import { z as z11 } from "zod";
|
|
5694
|
+
var listUsersQuerySchema = z11.object({
|
|
5695
|
+
page: z11.coerce.number().min(1).default(1).optional(),
|
|
5696
|
+
limit: z11.coerce.number().min(1).max(100).default(20).optional(),
|
|
5697
|
+
tenantId: z11.string().optional(),
|
|
5698
|
+
email: z11.string().optional(),
|
|
5699
|
+
phone: z11.string().optional(),
|
|
5700
|
+
handle: z11.string().optional()
|
|
5701
|
+
});
|
|
5702
|
+
var userIdParamSchema2 = z11.object({
|
|
5703
|
+
id: z11.uuid()
|
|
5542
5704
|
});
|
|
5543
|
-
var createUserSchema =
|
|
5544
|
-
email:
|
|
5545
|
-
phone:
|
|
5546
|
-
fullName:
|
|
5547
|
-
handle:
|
|
5548
|
-
image:
|
|
5549
|
-
emailVerified:
|
|
5550
|
-
phoneVerified:
|
|
5551
|
-
});
|
|
5552
|
-
var updateUserSchema =
|
|
5553
|
-
fullName:
|
|
5554
|
-
email:
|
|
5555
|
-
phone:
|
|
5556
|
-
handle:
|
|
5557
|
-
image:
|
|
5558
|
-
emailVerified:
|
|
5559
|
-
phoneVerified:
|
|
5560
|
-
});
|
|
5561
|
-
var banUserSchema =
|
|
5562
|
-
bannedUntil:
|
|
5563
|
-
});
|
|
5564
|
-
var listUsersResponseSchema =
|
|
5565
|
-
users:
|
|
5566
|
-
total:
|
|
5567
|
-
page:
|
|
5568
|
-
limit:
|
|
5569
|
-
});
|
|
5570
|
-
var userResponseSchema =
|
|
5705
|
+
var createUserSchema = z11.object({
|
|
5706
|
+
email: z11.string().email().optional(),
|
|
5707
|
+
phone: z11.string().optional(),
|
|
5708
|
+
fullName: z11.string().min(1),
|
|
5709
|
+
handle: z11.string().optional(),
|
|
5710
|
+
image: z11.string().url().optional(),
|
|
5711
|
+
emailVerified: z11.boolean().default(false).optional(),
|
|
5712
|
+
phoneVerified: z11.boolean().default(false).optional()
|
|
5713
|
+
});
|
|
5714
|
+
var updateUserSchema = z11.object({
|
|
5715
|
+
fullName: z11.string().min(1).optional(),
|
|
5716
|
+
email: z11.string().email().nullable().optional(),
|
|
5717
|
+
phone: z11.string().nullable().optional(),
|
|
5718
|
+
handle: z11.string().optional(),
|
|
5719
|
+
image: z11.string().url().nullable().optional(),
|
|
5720
|
+
emailVerified: z11.boolean().optional(),
|
|
5721
|
+
phoneVerified: z11.boolean().optional()
|
|
5722
|
+
});
|
|
5723
|
+
var banUserSchema = z11.object({
|
|
5724
|
+
bannedUntil: z11.string().datetime().nullable().optional()
|
|
5725
|
+
});
|
|
5726
|
+
var listUsersResponseSchema = z11.object({
|
|
5727
|
+
users: z11.array(userSchema),
|
|
5728
|
+
total: z11.number(),
|
|
5729
|
+
page: z11.number(),
|
|
5730
|
+
limit: z11.number()
|
|
5731
|
+
});
|
|
5732
|
+
var userResponseSchema = z11.object({
|
|
5571
5733
|
user: userSchema
|
|
5572
5734
|
});
|
|
5573
|
-
var deleteUserResponseSchema =
|
|
5574
|
-
message:
|
|
5735
|
+
var deleteUserResponseSchema = z11.object({
|
|
5736
|
+
message: z11.string()
|
|
5575
5737
|
});
|
|
5576
|
-
var errorResponseSchema9 =
|
|
5577
|
-
error:
|
|
5738
|
+
var errorResponseSchema9 = z11.object({
|
|
5739
|
+
error: z11.string()
|
|
5578
5740
|
});
|
|
5579
|
-
var searchUsersQuerySchema =
|
|
5580
|
-
search:
|
|
5581
|
-
limit:
|
|
5741
|
+
var searchUsersQuerySchema = z11.object({
|
|
5742
|
+
search: z11.string().optional().describe("Search term"),
|
|
5743
|
+
limit: z11.coerce.number().int().positive().optional().default(20).describe("Limit")
|
|
5582
5744
|
});
|
|
5583
|
-
var userSearchResultSchema =
|
|
5584
|
-
id:
|
|
5585
|
-
fullName:
|
|
5586
|
-
email:
|
|
5587
|
-
phone:
|
|
5588
|
-
handle:
|
|
5589
|
-
image:
|
|
5745
|
+
var userSearchResultSchema = z11.object({
|
|
5746
|
+
id: z11.string().uuid().describe("User ID"),
|
|
5747
|
+
fullName: z11.string().describe("Full name"),
|
|
5748
|
+
email: z11.string().nullable().describe("Email"),
|
|
5749
|
+
phone: z11.string().nullable().describe("Phone"),
|
|
5750
|
+
handle: z11.string().describe("Handle"),
|
|
5751
|
+
image: z11.string().nullable().describe("Image URL")
|
|
5590
5752
|
});
|
|
5591
|
-
var searchUsersResponseSchema =
|
|
5592
|
-
users:
|
|
5753
|
+
var searchUsersResponseSchema = z11.object({
|
|
5754
|
+
users: z11.array(userSearchResultSchema).describe("Users")
|
|
5593
5755
|
});
|
|
5594
5756
|
|
|
5595
5757
|
// src/routes/users/users.route.ts
|
|
5596
|
-
var listUsersRoute =
|
|
5758
|
+
var listUsersRoute = createRoute14({
|
|
5597
5759
|
method: "get",
|
|
5598
5760
|
path: "/",
|
|
5599
5761
|
tags: ["Users"],
|
|
@@ -5612,7 +5774,7 @@ var listUsersRoute = createRoute13({
|
|
|
5612
5774
|
}
|
|
5613
5775
|
}
|
|
5614
5776
|
});
|
|
5615
|
-
var getUserRoute =
|
|
5777
|
+
var getUserRoute = createRoute14({
|
|
5616
5778
|
method: "get",
|
|
5617
5779
|
path: "/{id}",
|
|
5618
5780
|
tags: ["Users"],
|
|
@@ -5639,7 +5801,7 @@ var getUserRoute = createRoute13({
|
|
|
5639
5801
|
}
|
|
5640
5802
|
}
|
|
5641
5803
|
});
|
|
5642
|
-
var createUserRoute =
|
|
5804
|
+
var createUserRoute = createRoute14({
|
|
5643
5805
|
method: "post",
|
|
5644
5806
|
path: "/",
|
|
5645
5807
|
tags: ["Users"],
|
|
@@ -5672,7 +5834,7 @@ var createUserRoute = createRoute13({
|
|
|
5672
5834
|
}
|
|
5673
5835
|
}
|
|
5674
5836
|
});
|
|
5675
|
-
var updateUserRoute =
|
|
5837
|
+
var updateUserRoute = createRoute14({
|
|
5676
5838
|
method: "put",
|
|
5677
5839
|
path: "/{id}",
|
|
5678
5840
|
tags: ["Users"],
|
|
@@ -5714,7 +5876,7 @@ var updateUserRoute = createRoute13({
|
|
|
5714
5876
|
}
|
|
5715
5877
|
}
|
|
5716
5878
|
});
|
|
5717
|
-
var deleteUserRoute =
|
|
5879
|
+
var deleteUserRoute = createRoute14({
|
|
5718
5880
|
method: "delete",
|
|
5719
5881
|
path: "/{id}",
|
|
5720
5882
|
tags: ["Users"],
|
|
@@ -5741,7 +5903,7 @@ var deleteUserRoute = createRoute13({
|
|
|
5741
5903
|
}
|
|
5742
5904
|
}
|
|
5743
5905
|
});
|
|
5744
|
-
var banUserRoute =
|
|
5906
|
+
var banUserRoute = createRoute14({
|
|
5745
5907
|
method: "post",
|
|
5746
5908
|
path: "/{id}/ban",
|
|
5747
5909
|
tags: ["Users"],
|
|
@@ -5775,7 +5937,7 @@ var banUserRoute = createRoute13({
|
|
|
5775
5937
|
}
|
|
5776
5938
|
}
|
|
5777
5939
|
});
|
|
5778
|
-
var searchUsersRoute =
|
|
5940
|
+
var searchUsersRoute = createRoute14({
|
|
5779
5941
|
method: "get",
|
|
5780
5942
|
path: "/search",
|
|
5781
5943
|
tags: ["Users"],
|
|
@@ -5794,11 +5956,11 @@ var searchUsersRoute = createRoute13({
|
|
|
5794
5956
|
}
|
|
5795
5957
|
}
|
|
5796
5958
|
});
|
|
5797
|
-
var userRoutes = new
|
|
5959
|
+
var userRoutes = new OpenAPIHono14().openapi(listUsersRoute, listUsersHandler).openapi(getUserRoute, getUserHandler).openapi(createUserRoute, createUserHandler).openapi(updateUserRoute, updateUserHandler).openapi(deleteUserRoute, deleteUserHandler).openapi(banUserRoute, banUserHandler).openapi(searchUsersRoute, searchUsersHandler);
|
|
5798
5960
|
var users_route_default = userRoutes;
|
|
5799
5961
|
|
|
5800
5962
|
// src/routes/verifications/verifications.route.ts
|
|
5801
|
-
import { createRoute as
|
|
5963
|
+
import { createRoute as createRoute15, OpenAPIHono as OpenAPIHono15 } from "@hono/zod-openapi";
|
|
5802
5964
|
|
|
5803
5965
|
// src/routes/verifications/handler/invalidate-verification.ts
|
|
5804
5966
|
import { and as and47, eq as eq51 } from "drizzle-orm";
|
|
@@ -5860,44 +6022,44 @@ var listVerificationsHandler = async (c) => {
|
|
|
5860
6022
|
};
|
|
5861
6023
|
|
|
5862
6024
|
// src/routes/verifications/verifications.schema.ts
|
|
5863
|
-
import { z as
|
|
5864
|
-
var listVerificationsQuerySchema =
|
|
5865
|
-
page:
|
|
5866
|
-
limit:
|
|
5867
|
-
userId:
|
|
5868
|
-
type:
|
|
5869
|
-
status:
|
|
5870
|
-
});
|
|
5871
|
-
var verificationIdParamSchema =
|
|
5872
|
-
id:
|
|
5873
|
-
});
|
|
5874
|
-
var verificationSchema =
|
|
5875
|
-
id:
|
|
5876
|
-
tenantId:
|
|
5877
|
-
userId:
|
|
5878
|
-
code:
|
|
5879
|
-
expiresAt:
|
|
5880
|
-
type:
|
|
5881
|
-
attempt:
|
|
5882
|
-
to:
|
|
5883
|
-
createdAt:
|
|
5884
|
-
updatedAt:
|
|
5885
|
-
});
|
|
5886
|
-
var listVerificationsResponseSchema =
|
|
5887
|
-
verifications:
|
|
5888
|
-
total:
|
|
5889
|
-
page:
|
|
5890
|
-
limit:
|
|
5891
|
-
});
|
|
5892
|
-
var invalidateVerificationResponseSchema =
|
|
5893
|
-
message:
|
|
5894
|
-
});
|
|
5895
|
-
var errorResponseSchema10 =
|
|
5896
|
-
error:
|
|
6025
|
+
import { z as z12 } from "zod";
|
|
6026
|
+
var listVerificationsQuerySchema = z12.object({
|
|
6027
|
+
page: z12.coerce.number().min(1).default(1).optional(),
|
|
6028
|
+
limit: z12.coerce.number().min(1).max(100).default(20).optional(),
|
|
6029
|
+
userId: z12.uuid().optional(),
|
|
6030
|
+
type: z12.string().optional(),
|
|
6031
|
+
status: z12.enum(["active", "expired", "consumed"]).optional()
|
|
6032
|
+
});
|
|
6033
|
+
var verificationIdParamSchema = z12.object({
|
|
6034
|
+
id: z12.uuid()
|
|
6035
|
+
});
|
|
6036
|
+
var verificationSchema = z12.object({
|
|
6037
|
+
id: z12.uuid(),
|
|
6038
|
+
tenantId: z12.string(),
|
|
6039
|
+
userId: z12.uuid(),
|
|
6040
|
+
code: z12.string(),
|
|
6041
|
+
expiresAt: z12.string(),
|
|
6042
|
+
type: z12.string().nullable(),
|
|
6043
|
+
attempt: z12.number().nullable(),
|
|
6044
|
+
to: z12.string().nullable(),
|
|
6045
|
+
createdAt: z12.string(),
|
|
6046
|
+
updatedAt: z12.string()
|
|
6047
|
+
});
|
|
6048
|
+
var listVerificationsResponseSchema = z12.object({
|
|
6049
|
+
verifications: z12.array(verificationSchema),
|
|
6050
|
+
total: z12.number(),
|
|
6051
|
+
page: z12.number(),
|
|
6052
|
+
limit: z12.number()
|
|
6053
|
+
});
|
|
6054
|
+
var invalidateVerificationResponseSchema = z12.object({
|
|
6055
|
+
message: z12.string()
|
|
6056
|
+
});
|
|
6057
|
+
var errorResponseSchema10 = z12.object({
|
|
6058
|
+
error: z12.string()
|
|
5897
6059
|
});
|
|
5898
6060
|
|
|
5899
6061
|
// src/routes/verifications/verifications.route.ts
|
|
5900
|
-
var listVerificationsRoute =
|
|
6062
|
+
var listVerificationsRoute = createRoute15({
|
|
5901
6063
|
method: "get",
|
|
5902
6064
|
path: "/",
|
|
5903
6065
|
tags: ["Verifications"],
|
|
@@ -5916,7 +6078,7 @@ var listVerificationsRoute = createRoute14({
|
|
|
5916
6078
|
}
|
|
5917
6079
|
}
|
|
5918
6080
|
});
|
|
5919
|
-
var invalidateVerificationRoute =
|
|
6081
|
+
var invalidateVerificationRoute = createRoute15({
|
|
5920
6082
|
method: "delete",
|
|
5921
6083
|
path: "/{id}",
|
|
5922
6084
|
tags: ["Verifications"],
|
|
@@ -5943,11 +6105,11 @@ var invalidateVerificationRoute = createRoute14({
|
|
|
5943
6105
|
}
|
|
5944
6106
|
}
|
|
5945
6107
|
});
|
|
5946
|
-
var verificationRoutes = new
|
|
6108
|
+
var verificationRoutes = new OpenAPIHono15().openapi(listVerificationsRoute, listVerificationsHandler).openapi(invalidateVerificationRoute, invalidateVerificationHandler);
|
|
5947
6109
|
var verifications_route_default = verificationRoutes;
|
|
5948
6110
|
|
|
5949
6111
|
// src/routes/index.ts
|
|
5950
|
-
var routes = new
|
|
6112
|
+
var routes = new OpenAPIHono16().route("/", auth_route_default).route("/", profile_route_default).route("/password", password_route_default).route("/email", email_route_default).route("/phone", phone_route_default).route("/users", users_route_default).route("/system", system_route_default).route("/tenants", tenants_route_default).route("/domains", domains_route_default).route("/roles", roles_route_default).route("/permissions", permissions_route_default).route("/role-permissions", role_permissions_route_default).route("/user-roles", user_roles_route_default).route("/sessions", sessions_route_default).route("/verifications", verifications_route_default);
|
|
5951
6113
|
var routes_default = routes;
|
|
5952
6114
|
|
|
5953
6115
|
// src/utility/set-auth-context.ts
|
|
@@ -6028,7 +6190,10 @@ var createAuthRoutes = ({
|
|
|
6028
6190
|
config,
|
|
6029
6191
|
database
|
|
6030
6192
|
}) => {
|
|
6031
|
-
const app = new
|
|
6193
|
+
const app = new OpenAPIHono17();
|
|
6194
|
+
app.onError((error, c) => {
|
|
6195
|
+
return handleError(error, c);
|
|
6196
|
+
});
|
|
6032
6197
|
app.use(
|
|
6033
6198
|
"*",
|
|
6034
6199
|
createAuthMiddleware({
|
|
@@ -6089,13 +6254,18 @@ var createOpenApiConfig = (config) => {
|
|
|
6089
6254
|
},
|
|
6090
6255
|
{ name: "User Roles", description: "User-role assignment (IAM)" },
|
|
6091
6256
|
{ name: "Sessions", description: "Session management (IAM)" },
|
|
6092
|
-
{ name: "Verifications", description: "Verification management (IAM)" }
|
|
6257
|
+
{ name: "Verifications", description: "Verification management (IAM)" },
|
|
6258
|
+
{ name: "System", description: "System initialization" }
|
|
6093
6259
|
],
|
|
6094
6260
|
"x-tagGroups": [
|
|
6095
6261
|
{
|
|
6096
6262
|
name: "Authentication",
|
|
6097
6263
|
tags: ["Auth", "Profile", "Password", "Email", "Phone"]
|
|
6098
6264
|
},
|
|
6265
|
+
{
|
|
6266
|
+
name: "System",
|
|
6267
|
+
tags: ["System"]
|
|
6268
|
+
},
|
|
6099
6269
|
{
|
|
6100
6270
|
name: "IAM Management",
|
|
6101
6271
|
tags: [
|
|
@@ -6123,10 +6293,12 @@ var createSessionMiddleware = () => {
|
|
|
6123
6293
|
c.set("user", null);
|
|
6124
6294
|
c.set("session", null);
|
|
6125
6295
|
c.set("userId", null);
|
|
6296
|
+
c.set("sessionStatus", "error");
|
|
6126
6297
|
return await next();
|
|
6127
6298
|
}
|
|
6128
6299
|
const sessionData = await authInstance.getSession(c);
|
|
6129
|
-
const { session, user } = sessionData;
|
|
6300
|
+
const { session, user, status } = sessionData;
|
|
6301
|
+
c.set("sessionStatus", status);
|
|
6130
6302
|
if (!(session && user)) {
|
|
6131
6303
|
c.set("user", null);
|
|
6132
6304
|
c.set("session", null);
|
|
@@ -6142,16 +6314,9 @@ var createSessionMiddleware = () => {
|
|
|
6142
6314
|
};
|
|
6143
6315
|
|
|
6144
6316
|
// src/middlewares/tenant-middleware.ts
|
|
6145
|
-
import { logger } from "@mesob/common";
|
|
6317
|
+
import { logger as logger2 } from "@mesob/common";
|
|
6146
6318
|
import { createMiddleware as createMiddleware2 } from "hono/factory";
|
|
6147
|
-
import { HTTPException as
|
|
6148
|
-
var TENANT_TEST_PATH = "/api/health/tenant-test";
|
|
6149
|
-
var AUTH_DOCS_PATHS = [
|
|
6150
|
-
"/api/auth/docs",
|
|
6151
|
-
"/api/auth/openapi.json",
|
|
6152
|
-
"/api/docs",
|
|
6153
|
-
"/api/openapi.json"
|
|
6154
|
-
];
|
|
6319
|
+
import { HTTPException as HTTPException3 } from "hono/http-exception";
|
|
6155
6320
|
function resolveHost(hostHeader, forwardedHost) {
|
|
6156
6321
|
const hostHeaderStr = hostHeader || "";
|
|
6157
6322
|
const forwardedHostStr = forwardedHost || "";
|
|
@@ -6191,7 +6356,7 @@ async function resolveTenant(database, config, host) {
|
|
|
6191
6356
|
}
|
|
6192
6357
|
return { tenantId, tenant };
|
|
6193
6358
|
} catch (err) {
|
|
6194
|
-
|
|
6359
|
+
logger2.error("Tenant resolution error:", err);
|
|
6195
6360
|
throw err;
|
|
6196
6361
|
}
|
|
6197
6362
|
}
|
|
@@ -6209,19 +6374,13 @@ function validateTenant(tenantId, tenant) {
|
|
|
6209
6374
|
}
|
|
6210
6375
|
var createTenantMiddleware = (database, config) => {
|
|
6211
6376
|
return createMiddleware2(async (c, next) => {
|
|
6212
|
-
const pathname = new URL(c.req.url).pathname;
|
|
6213
|
-
const isTenantTest = pathname === TENANT_TEST_PATH;
|
|
6214
|
-
const isAuthDocs = AUTH_DOCS_PATHS.includes(pathname);
|
|
6215
6377
|
const host = resolveHost(
|
|
6216
6378
|
c.req.header("host"),
|
|
6217
6379
|
c.req.header("x-forwarded-host")
|
|
6218
6380
|
);
|
|
6219
6381
|
c.set("host", host);
|
|
6220
6382
|
if (!host) {
|
|
6221
|
-
|
|
6222
|
-
return await next();
|
|
6223
|
-
}
|
|
6224
|
-
throw new HTTPException2(400, { message: "Missing Host header" });
|
|
6383
|
+
throw new HTTPException3(400, { message: "Missing Host header" });
|
|
6225
6384
|
}
|
|
6226
6385
|
let tenantId = null;
|
|
6227
6386
|
let tenant = null;
|
|
@@ -6230,15 +6389,13 @@ var createTenantMiddleware = (database, config) => {
|
|
|
6230
6389
|
tenantId = result.tenantId;
|
|
6231
6390
|
tenant = result.tenant;
|
|
6232
6391
|
} catch {
|
|
6233
|
-
|
|
6234
|
-
throw new HTTPException2(500, { message: "Tenant resolution failed" });
|
|
6235
|
-
}
|
|
6392
|
+
throw new HTTPException3(500, { message: "Tenant resolution failed" });
|
|
6236
6393
|
}
|
|
6237
6394
|
c.set("tenantId", tenantId);
|
|
6238
6395
|
c.set("tenant", tenant);
|
|
6239
6396
|
const error = validateTenant(tenantId, tenant);
|
|
6240
|
-
if (error
|
|
6241
|
-
throw new
|
|
6397
|
+
if (error) {
|
|
6398
|
+
throw new HTTPException3(404, { message: error });
|
|
6242
6399
|
}
|
|
6243
6400
|
return await next();
|
|
6244
6401
|
});
|
|
@@ -6250,7 +6407,12 @@ var createGetSession = (database, config) => {
|
|
|
6250
6407
|
return async (c) => {
|
|
6251
6408
|
const sessionToken = getCookie4(c, getSessionCookieName(config));
|
|
6252
6409
|
if (!sessionToken) {
|
|
6253
|
-
return {
|
|
6410
|
+
return {
|
|
6411
|
+
session: null,
|
|
6412
|
+
user: null,
|
|
6413
|
+
sessionToken: null,
|
|
6414
|
+
status: "no_cookie"
|
|
6415
|
+
};
|
|
6254
6416
|
}
|
|
6255
6417
|
try {
|
|
6256
6418
|
const hashedToken = await hashToken(sessionToken, config.secret);
|
|
@@ -6261,7 +6423,12 @@ var createGetSession = (database, config) => {
|
|
|
6261
6423
|
});
|
|
6262
6424
|
if (!session) {
|
|
6263
6425
|
deleteSessionCookie(c, config);
|
|
6264
|
-
return {
|
|
6426
|
+
return {
|
|
6427
|
+
session: null,
|
|
6428
|
+
user: null,
|
|
6429
|
+
sessionToken: null,
|
|
6430
|
+
status: "invalid_session"
|
|
6431
|
+
};
|
|
6265
6432
|
}
|
|
6266
6433
|
const user = await fetchUserWithRoles({
|
|
6267
6434
|
database,
|
|
@@ -6275,7 +6442,12 @@ var createGetSession = (database, config) => {
|
|
|
6275
6442
|
tenantId: session.tenantId
|
|
6276
6443
|
});
|
|
6277
6444
|
deleteSessionCookie(c, config);
|
|
6278
|
-
return {
|
|
6445
|
+
return {
|
|
6446
|
+
session: null,
|
|
6447
|
+
user: null,
|
|
6448
|
+
sessionToken: null,
|
|
6449
|
+
status: "user_not_found"
|
|
6450
|
+
};
|
|
6279
6451
|
}
|
|
6280
6452
|
const rememberMe = session.meta?.rememberMe !== false;
|
|
6281
6453
|
const updateAge = getSessionUpdateAge({
|
|
@@ -6299,21 +6471,22 @@ var createGetSession = (database, config) => {
|
|
|
6299
6471
|
return {
|
|
6300
6472
|
session: { ...session, expiresAt: newExpiresAt },
|
|
6301
6473
|
user,
|
|
6302
|
-
sessionToken
|
|
6474
|
+
sessionToken,
|
|
6475
|
+
status: "valid"
|
|
6303
6476
|
};
|
|
6304
6477
|
}
|
|
6305
|
-
return { session, user, sessionToken };
|
|
6478
|
+
return { session, user, sessionToken, status: "valid" };
|
|
6306
6479
|
} catch {
|
|
6307
|
-
return { session: null, user: null, sessionToken: null };
|
|
6480
|
+
return { session: null, user: null, sessionToken: null, status: "error" };
|
|
6308
6481
|
}
|
|
6309
6482
|
};
|
|
6310
6483
|
};
|
|
6311
6484
|
|
|
6312
6485
|
// src/types/index.ts
|
|
6313
|
-
import { logger as
|
|
6486
|
+
import { logger as logger3 } from "@mesob/common";
|
|
6314
6487
|
var createDefaultSendVerificationOTP = (expiresIn) => {
|
|
6315
6488
|
return (params) => {
|
|
6316
|
-
|
|
6489
|
+
logger3.log(
|
|
6317
6490
|
`[Verification OTP] Code: ${params.code}, Hash: ${params.hash}, ExpiresIn: ${expiresIn}, Type: ${params.type}`
|
|
6318
6491
|
);
|
|
6319
6492
|
};
|
|
@@ -6327,6 +6500,7 @@ var defaultConfig = {
|
|
|
6327
6500
|
resendInterval: "30s",
|
|
6328
6501
|
sendVerificationOTP: createDefaultSendVerificationOTP("15m")
|
|
6329
6502
|
};
|
|
6503
|
+
var defaultPhoneRegex = /^(\+2519|\+2517|2519|2517|09|07)\d{8}$/;
|
|
6330
6504
|
var defaultAuthConfig = {
|
|
6331
6505
|
tenant: {
|
|
6332
6506
|
enabled: true,
|
|
@@ -6347,7 +6521,10 @@ var defaultAuthConfig = {
|
|
|
6347
6521
|
maxPerUser: 5
|
|
6348
6522
|
},
|
|
6349
6523
|
email: defaultConfig,
|
|
6350
|
-
phone:
|
|
6524
|
+
phone: {
|
|
6525
|
+
...defaultConfig,
|
|
6526
|
+
phoneRegex: defaultPhoneRegex
|
|
6527
|
+
},
|
|
6351
6528
|
security: {
|
|
6352
6529
|
maxLoginAttempts: 5,
|
|
6353
6530
|
lockoutDuration: "15m"
|
|
@@ -6403,20 +6580,7 @@ var createMesobAuth = (authConfig) => {
|
|
|
6403
6580
|
const getSession = createGetSession(database, config);
|
|
6404
6581
|
const tenantMiddleware = createTenantMiddleware(database, config);
|
|
6405
6582
|
const sessionMiddleware = createSessionMiddleware();
|
|
6406
|
-
const routes2 =
|
|
6407
|
-
...routesApp,
|
|
6408
|
-
fetch: async (request, env) => {
|
|
6409
|
-
if (basePath && request.url) {
|
|
6410
|
-
const url = new URL(request.url);
|
|
6411
|
-
if (url.pathname.startsWith(basePath)) {
|
|
6412
|
-
url.pathname = url.pathname.slice(basePath.length) || "/";
|
|
6413
|
-
const modifiedRequest = new Request(url, request);
|
|
6414
|
-
return await routesApp.fetch(modifiedRequest, env);
|
|
6415
|
-
}
|
|
6416
|
-
}
|
|
6417
|
-
return await routesApp.fetch(request, env);
|
|
6418
|
-
}
|
|
6419
|
-
};
|
|
6583
|
+
const routes2 = routesApp;
|
|
6420
6584
|
return {
|
|
6421
6585
|
routes: routes2,
|
|
6422
6586
|
getSession,
|