@rpcbase/auth 0.43.0 → 0.45.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/dist/api/me/handler.d.ts +5 -0
- package/dist/api/me/handler.d.ts.map +1 -0
- package/dist/api/me/index.d.ts +16 -0
- package/dist/api/me/index.d.ts.map +1 -0
- package/dist/api/sign-in/handler.d.ts +2 -1
- package/dist/api/sign-in/handler.d.ts.map +1 -1
- package/dist/api/sign-in/index.d.ts +4 -0
- package/dist/api/sign-in/index.d.ts.map +1 -1
- package/dist/api/sign-out/handler.d.ts.map +1 -1
- package/dist/api/sign-up/handler.d.ts +2 -1
- package/dist/api/sign-up/handler.d.ts.map +1 -1
- package/dist/api/sign-up/index.d.ts +4 -0
- package/dist/api/sign-up/index.d.ts.map +1 -1
- package/dist/components/PasswordInput/index.d.ts +10 -0
- package/dist/components/PasswordInput/index.d.ts.map +1 -0
- package/dist/components/SignInForm/index.d.ts.map +1 -1
- package/dist/components/SignUpForm/index.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/handler-BSoyBLZM.js +50 -0
- package/dist/handler-Ba3pgtfZ.js +57 -0
- package/dist/{handler-rzI-pkuD.js → handler-CNHucHrj.js} +4 -1
- package/dist/handler-rZR_dx7n.js +71 -0
- package/dist/{index-BYEYCL3Q.js → index-Cq04nmsE.js} +7 -3
- package/dist/{index-BphnyggH.js → index-r56vqjph.js} +6 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +87 -6
- package/dist/middleware-BiMXO6Dq.js +21 -0
- package/dist/middleware.d.ts +6 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/routes.js +1 -1
- package/dist/{schemas-DKK0lkQz.js → schemas-KL7REOdt.js} +58 -48
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/handler-Bl5DlLdb.js +0 -32
- package/dist/handler-CSmOkoqC.js +0 -17
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/me/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAA8B,MAAM,cAAc,CAAA;AAE9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;yBAkDlC,KAAK,GAAG,CAAC,eAAe,CAAC;AAAzC,wBAGC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from '../../../../vite/node_modules/zod';
|
|
2
|
+
export declare const Route = "/api/rb/auth/me";
|
|
3
|
+
export declare const requestSchema: z.ZodObject<{}, z.core.$strip>;
|
|
4
|
+
export type RequestPayload = z.infer<typeof requestSchema>;
|
|
5
|
+
export declare const responseSchema: z.ZodObject<{
|
|
6
|
+
id: z.ZodOptional<z.ZodString>;
|
|
7
|
+
email: z.ZodOptional<z.ZodString>;
|
|
8
|
+
phone: z.ZodOptional<z.ZodString>;
|
|
9
|
+
name: z.ZodOptional<z.ZodString>;
|
|
10
|
+
tenants: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
11
|
+
current_tenant_id: z.ZodOptional<z.ZodString>;
|
|
12
|
+
signed_in_tenants: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
|
|
13
|
+
error: z.ZodOptional<z.ZodString>;
|
|
14
|
+
}, z.core.$strip>;
|
|
15
|
+
export type ResponsePayload = z.infer<typeof responseSchema>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/me/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,eAAO,MAAM,KAAK,oBAAoB,CAAA;AAEtC,eAAO,MAAM,aAAa,gCAAe,CAAA;AACzC,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAE1D,eAAO,MAAM,cAAc;;;;;;;;;iBASzB,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-in/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-in/handler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAA8B,MAAM,cAAc,CAAA;AAG9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;yBAgElC,KAAK,GAAG,CAAC,eAAe,CAAC;AAAzC,wBAEC"}
|
|
@@ -2,11 +2,15 @@ import { z } from '../../../../vite/node_modules/zod';
|
|
|
2
2
|
export declare const Route = "/api/rb/auth/sign-in";
|
|
3
3
|
export declare const requestSchema: z.ZodObject<{
|
|
4
4
|
email_or_phone: z.ZodDefault<z.ZodString>;
|
|
5
|
+
password: z.ZodString;
|
|
5
6
|
remember_me: z.ZodDefault<z.ZodBoolean>;
|
|
6
7
|
}, z.core.$strip>;
|
|
7
8
|
export type RequestPayload = z.infer<typeof requestSchema>;
|
|
8
9
|
export declare const responseSchema: z.ZodObject<{
|
|
9
10
|
success: z.ZodBoolean;
|
|
11
|
+
error: z.ZodOptional<z.ZodString>;
|
|
12
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
13
|
+
tenant_id: z.ZodOptional<z.ZodString>;
|
|
10
14
|
}, z.core.$strip>;
|
|
11
15
|
export type ResponsePayload = z.infer<typeof responseSchema>;
|
|
12
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/sign-in/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,KAAK,yBAAyB,CAAA;AAE3C,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/sign-in/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,KAAK,yBAAyB,CAAA;AAE3C,eAAO,MAAM,aAAa;;;;iBAexB,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAE1D,eAAO,MAAM,cAAc;;;;;iBAKzB,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-out/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-out/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAO,MAAM,cAAc,CAAA;yBAkBvB,KAAK,GAAG;AAAxB,wBAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-up/handler.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/api/sign-up/handler.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAA8B,MAAM,cAAc,CAAA;AAG9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;yBAwFlC,KAAK,GAAG,CAAC,eAAe,CAAC;AAAzC,wBAEC"}
|
|
@@ -4,10 +4,14 @@ export declare const requestSchema: z.ZodObject<{
|
|
|
4
4
|
email_or_phone: z.ZodString;
|
|
5
5
|
password: z.ZodString;
|
|
6
6
|
password_confirmation: z.ZodString;
|
|
7
|
+
remember_me: z.ZodDefault<z.ZodBoolean>;
|
|
7
8
|
}, z.core.$strip>;
|
|
8
9
|
export type RequestPayload = z.infer<typeof requestSchema>;
|
|
9
10
|
export declare const responseSchema: z.ZodObject<{
|
|
10
11
|
success: z.ZodBoolean;
|
|
12
|
+
error: z.ZodOptional<z.ZodString>;
|
|
13
|
+
user_id: z.ZodOptional<z.ZodString>;
|
|
14
|
+
tenant_id: z.ZodOptional<z.ZodString>;
|
|
11
15
|
}, z.core.$strip>;
|
|
12
16
|
export type ResponsePayload = z.infer<typeof responseSchema>;
|
|
13
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/sign-up/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,KAAK,yBAAyB,CAAA;AAE3C,eAAO,MAAM,aAAa
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/sign-up/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,KAAK,yBAAyB,CAAA;AAE3C,eAAO,MAAM,aAAa;;;;;iBAoBtB,CAAA;AAEJ,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAA;AAE1D,eAAO,MAAM,cAAc;;;;;iBAKzB,CAAA;AAEF,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type PasswordInputProps = {
|
|
2
|
+
id: string;
|
|
3
|
+
name?: string;
|
|
4
|
+
className?: string;
|
|
5
|
+
placeholder?: string;
|
|
6
|
+
autoComplete?: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const PasswordInput: ({ id, name, className, placeholder, autoComplete, }: PasswordInputProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PasswordInput/index.tsx"],"names":[],"mappings":"AAGA,KAAK,kBAAkB,GAAG;IACxB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,qDAM3B,kBAAkB,4CA0BpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SignInForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAY,MAAM,OAAO,CAAA;AAW1C,eAAO,MAAM,UAAU,GAAI,yBAGxB;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SignInForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAY,MAAM,OAAO,CAAA;AAW1C,eAAO,MAAM,UAAU,GAAI,yBAGxB;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,4CA6CA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SignUpForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SignUpForm/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAsB,MAAM,OAAO,CAAA;AAWpD,eAAO,MAAM,UAAU,GAAI,yBAGxB;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,4CAyEA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import { i as isEmail } from "./isEmail-IG0hXiQk.js";
|
|
3
|
+
import { loadModel } from "@rpcbase/api";
|
|
4
|
+
import { hashPassword } from "@rpcbase/server";
|
|
5
|
+
import { R as Route, r as requestSchema } from "./index-r56vqjph.js";
|
|
6
|
+
const signIn = async (payload, ctx) => {
|
|
7
|
+
const User = await loadModel("User", ctx);
|
|
8
|
+
const parsed = requestSchema.safeParse(payload);
|
|
9
|
+
if (!parsed.success) {
|
|
10
|
+
ctx.res.status(400);
|
|
11
|
+
return { success: false, error: "invalid_payload" };
|
|
12
|
+
}
|
|
13
|
+
const { email_or_phone, password } = parsed.data;
|
|
14
|
+
const query = isEmail(email_or_phone) ? { email: email_or_phone } : { phone: email_or_phone };
|
|
15
|
+
const user = await User.findOne(query, { password: 1, tenants: 1 });
|
|
16
|
+
if (!user?.password) {
|
|
17
|
+
ctx.res.status(401);
|
|
18
|
+
return { success: false, error: "invalid_credentials" };
|
|
19
|
+
}
|
|
20
|
+
const [salt, hashedPassword] = String(user.password).split(":");
|
|
21
|
+
if (!salt || !hashedPassword) {
|
|
22
|
+
ctx.res.status(500);
|
|
23
|
+
return { success: false, error: "invalid_password_format" };
|
|
24
|
+
}
|
|
25
|
+
const derivedKey = await hashPassword(password, salt);
|
|
26
|
+
const passwordMatches = crypto.timingSafeEqual(Buffer.from(hashedPassword, "hex"), derivedKey);
|
|
27
|
+
if (!passwordMatches) {
|
|
28
|
+
ctx.res.status(401);
|
|
29
|
+
return { success: false, error: "invalid_credentials" };
|
|
30
|
+
}
|
|
31
|
+
const tenantId = user.tenants?.[0]?.toString?.() || "00000000";
|
|
32
|
+
const signedInTenants = (user.tenants || []).map((t) => t.toString?.() || String(t)) || [tenantId];
|
|
33
|
+
if (!ctx.req.session) {
|
|
34
|
+
ctx.res.status(500);
|
|
35
|
+
return { success: false, error: "session_unavailable" };
|
|
36
|
+
}
|
|
37
|
+
ctx.req.session.user = {
|
|
38
|
+
id: user._id.toString(),
|
|
39
|
+
current_tenant_id: tenantId,
|
|
40
|
+
signed_in_tenants: signedInTenants.length ? signedInTenants : [tenantId],
|
|
41
|
+
is_entry_gate_authorized: true
|
|
42
|
+
};
|
|
43
|
+
return { success: true, user_id: user._id.toString(), tenant_id: tenantId };
|
|
44
|
+
};
|
|
45
|
+
const handler = (api) => {
|
|
46
|
+
api.post(Route, signIn);
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
handler as default
|
|
50
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { loadModel } from "@rpcbase/api";
|
|
2
|
+
import { r as restrictSessionMiddleware } from "./middleware-BiMXO6Dq.js";
|
|
3
|
+
import { o as object, s as string, a as array } from "./schemas-KL7REOdt.js";
|
|
4
|
+
const Route = "/api/rb/auth/me";
|
|
5
|
+
object({});
|
|
6
|
+
object({
|
|
7
|
+
id: string().optional(),
|
|
8
|
+
email: string().email().optional(),
|
|
9
|
+
phone: string().optional(),
|
|
10
|
+
name: string().optional(),
|
|
11
|
+
tenants: array(string()).default([]),
|
|
12
|
+
current_tenant_id: string().optional(),
|
|
13
|
+
signed_in_tenants: array(string()).default([]).optional(),
|
|
14
|
+
error: string().optional()
|
|
15
|
+
});
|
|
16
|
+
const me = async (_payload, ctx) => {
|
|
17
|
+
const sessionUser = ctx.req.session?.user;
|
|
18
|
+
if (!sessionUser?.id) {
|
|
19
|
+
ctx.res.status(401);
|
|
20
|
+
return {
|
|
21
|
+
id: "",
|
|
22
|
+
current_tenant_id: "",
|
|
23
|
+
signed_in_tenants: [],
|
|
24
|
+
tenants: [],
|
|
25
|
+
error: "not_authenticated"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const User = await loadModel("User", ctx);
|
|
29
|
+
const user = await User.findById(sessionUser.id);
|
|
30
|
+
if (!user) {
|
|
31
|
+
ctx.res.status(404);
|
|
32
|
+
return {
|
|
33
|
+
id: "",
|
|
34
|
+
current_tenant_id: "",
|
|
35
|
+
signed_in_tenants: [],
|
|
36
|
+
tenants: [],
|
|
37
|
+
error: "user_not_found"
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const tenantId = sessionUser.current_tenant_id || user.tenants?.[0]?.toString?.() || "00000000";
|
|
41
|
+
return {
|
|
42
|
+
id: user._id.toString(),
|
|
43
|
+
email: user.email,
|
|
44
|
+
phone: user.phone,
|
|
45
|
+
name: user.name,
|
|
46
|
+
tenants: (user.tenants || []).map((t) => t.toString?.() || String(t)),
|
|
47
|
+
current_tenant_id: tenantId,
|
|
48
|
+
signed_in_tenants: sessionUser.signed_in_tenants || []
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
const handler = (api) => {
|
|
52
|
+
api.use(Route, restrictSessionMiddleware);
|
|
53
|
+
api.get(Route, me);
|
|
54
|
+
};
|
|
55
|
+
export {
|
|
56
|
+
handler as default
|
|
57
|
+
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { o as object, b as boolean } from "./schemas-
|
|
1
|
+
import { o as object, b as boolean } from "./schemas-KL7REOdt.js";
|
|
2
2
|
const Route = "/api/rb/auth/sign-out";
|
|
3
3
|
object({});
|
|
4
4
|
object({
|
|
5
5
|
success: boolean()
|
|
6
6
|
});
|
|
7
7
|
const handleSignOut = async (_, ctx) => {
|
|
8
|
+
if (!ctx.req.session) {
|
|
9
|
+
return { success: true };
|
|
10
|
+
}
|
|
8
11
|
await new Promise((resolve) => ctx.req.session.destroy(() => resolve()));
|
|
9
12
|
return {
|
|
10
13
|
success: true
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
import { i as isEmail } from "./isEmail-IG0hXiQk.js";
|
|
3
|
+
import { loadModel } from "@rpcbase/api";
|
|
4
|
+
import { hashPassword, sendEmail } from "@rpcbase/server";
|
|
5
|
+
import { R as Route, r as requestSchema } from "./index-Cq04nmsE.js";
|
|
6
|
+
const signUp = async (payload, ctx) => {
|
|
7
|
+
const User = await loadModel("User", ctx);
|
|
8
|
+
const Tenant = await loadModel("Tenant", ctx);
|
|
9
|
+
const parsed = requestSchema.safeParse(payload);
|
|
10
|
+
if (!parsed.success) {
|
|
11
|
+
ctx.res.status(400);
|
|
12
|
+
return { success: false, error: "invalid_payload" };
|
|
13
|
+
}
|
|
14
|
+
const { email_or_phone, password, remember_me: _remember_me } = parsed.data;
|
|
15
|
+
const is_email = isEmail(email_or_phone);
|
|
16
|
+
const query = is_email ? { email: email_or_phone } : { phone: email_or_phone };
|
|
17
|
+
const existingUser = await User.findOne(query);
|
|
18
|
+
if (existingUser) {
|
|
19
|
+
console.log("user with email or phone already exists", email_or_phone);
|
|
20
|
+
ctx.res.status(409);
|
|
21
|
+
return { success: false, error: "user_exists" };
|
|
22
|
+
}
|
|
23
|
+
const salt = crypto.randomBytes(16).toString("hex");
|
|
24
|
+
const derivedKey = await hashPassword(password, salt);
|
|
25
|
+
const hashedPassword = `${salt}:${derivedKey.toString("hex")}`;
|
|
26
|
+
const tenantId = crypto.randomUUID();
|
|
27
|
+
const user = new User({
|
|
28
|
+
...query,
|
|
29
|
+
password: hashedPassword,
|
|
30
|
+
tenants: [tenantId]
|
|
31
|
+
});
|
|
32
|
+
await user.save();
|
|
33
|
+
if (is_email) {
|
|
34
|
+
try {
|
|
35
|
+
await sendEmail({
|
|
36
|
+
to: email_or_phone,
|
|
37
|
+
subject: "Verify your email",
|
|
38
|
+
html: "<p>Welcome to rpcbase!</p><p>We created your account. Use this email to sign in and finish verification.</p>",
|
|
39
|
+
text: "Welcome to rpcbase! We created your account. Use this email to sign in and finish verification."
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.warn("failed to send sign-up email", err);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await Tenant.create({
|
|
47
|
+
tenant_id: tenantId,
|
|
48
|
+
name: query.email || query.phone
|
|
49
|
+
});
|
|
50
|
+
} catch (err) {
|
|
51
|
+
console.warn("failed to create tenant for user", err);
|
|
52
|
+
}
|
|
53
|
+
console.log("created new user", user._id.toString());
|
|
54
|
+
if (!ctx.req.session) {
|
|
55
|
+
ctx.res.status(500);
|
|
56
|
+
return { success: false, error: "session_unavailable" };
|
|
57
|
+
}
|
|
58
|
+
ctx.req.session.user = {
|
|
59
|
+
id: user._id.toString(),
|
|
60
|
+
current_tenant_id: tenantId,
|
|
61
|
+
signed_in_tenants: [tenantId],
|
|
62
|
+
is_entry_gate_authorized: true
|
|
63
|
+
};
|
|
64
|
+
return { success: true, user_id: user._id.toString(), tenant_id: tenantId };
|
|
65
|
+
};
|
|
66
|
+
const handler = (api) => {
|
|
67
|
+
api.post(Route, signUp);
|
|
68
|
+
};
|
|
69
|
+
export {
|
|
70
|
+
handler as default
|
|
71
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as isValidNumber } from "./isValidNumber-6pMDGLRn.js";
|
|
2
|
-
import { o as object,
|
|
2
|
+
import { o as object, b as boolean, s as string } from "./schemas-KL7REOdt.js";
|
|
3
3
|
const Route = "/api/rb/auth/sign-up";
|
|
4
4
|
const requestSchema = object({
|
|
5
5
|
email_or_phone: string().nonempty("Email or phone number is required").refine(
|
|
@@ -11,13 +11,17 @@ const requestSchema = object({
|
|
|
11
11
|
"Please enter a valid email address or phone number"
|
|
12
12
|
),
|
|
13
13
|
password: string().min(8, { message: "Password must be at least 8 characters long." }),
|
|
14
|
-
password_confirmation: string().nonempty({ message: "Please confirm your password." })
|
|
14
|
+
password_confirmation: string().nonempty({ message: "Please confirm your password." }),
|
|
15
|
+
remember_me: boolean().default(true)
|
|
15
16
|
}).refine((data) => data.password === data.password_confirmation, {
|
|
16
17
|
message: "Passwords do not match.",
|
|
17
18
|
path: ["password_confirmation"]
|
|
18
19
|
});
|
|
19
20
|
object({
|
|
20
|
-
success: boolean()
|
|
21
|
+
success: boolean(),
|
|
22
|
+
error: string().optional(),
|
|
23
|
+
user_id: string().optional(),
|
|
24
|
+
tenant_id: string().optional()
|
|
21
25
|
});
|
|
22
26
|
export {
|
|
23
27
|
Route as R,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as isValidNumber } from "./isValidNumber-6pMDGLRn.js";
|
|
2
|
-
import { o as object, b as boolean, s as string } from "./schemas-
|
|
2
|
+
import { o as object, b as boolean, s as string } from "./schemas-KL7REOdt.js";
|
|
3
3
|
const Route = "/api/rb/auth/sign-in";
|
|
4
4
|
const requestSchema = object({
|
|
5
5
|
email_or_phone: string().nonempty("Email or phone number is required").default("").refine(
|
|
@@ -10,10 +10,14 @@ const requestSchema = object({
|
|
|
10
10
|
},
|
|
11
11
|
"Please enter a valid email address or phone number"
|
|
12
12
|
),
|
|
13
|
+
password: string().min(1, { message: "Password is required" }),
|
|
13
14
|
remember_me: boolean().default(true)
|
|
14
15
|
});
|
|
15
16
|
object({
|
|
16
|
-
success: boolean()
|
|
17
|
+
success: boolean(),
|
|
18
|
+
error: string().optional(),
|
|
19
|
+
user_id: string().optional(),
|
|
20
|
+
tenant_id: string().optional()
|
|
17
21
|
});
|
|
18
22
|
export {
|
|
19
23
|
Route as R,
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,10 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
|
2
2
|
import { useLocation, Link } from "@rpcbase/router";
|
|
3
3
|
import clsx from "clsx";
|
|
4
4
|
import { useFormContext, useForm, zodResolver, FormProvider } from "@rpcbase/form";
|
|
5
|
-
import { useEffect } from "react";
|
|
6
|
-
import { r as requestSchema } from "./index-
|
|
7
|
-
import { r as requestSchema$1 } from "./index-
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { r as requestSchema } from "./index-r56vqjph.js";
|
|
7
|
+
import { r as requestSchema$1 } from "./index-Cq04nmsE.js";
|
|
8
|
+
import { b, a, r } from "./middleware-BiMXO6Dq.js";
|
|
8
9
|
const LINKS_REDIRECTION_MAP = {
|
|
9
10
|
"/auth/sign-in": {
|
|
10
11
|
"title": "Sign Up",
|
|
@@ -113,12 +114,29 @@ const SignInForm = ({
|
|
|
113
114
|
const methods = useForm({
|
|
114
115
|
defaultValues: {
|
|
115
116
|
email_or_phone: "",
|
|
117
|
+
password: "",
|
|
116
118
|
remember_me: true
|
|
117
119
|
},
|
|
118
120
|
resolver: zodResolver(requestSchema)
|
|
119
121
|
});
|
|
120
122
|
const onSubmit = async (data) => {
|
|
121
123
|
console.log("SUBMIT SIGNIN", data);
|
|
124
|
+
try {
|
|
125
|
+
const res = await fetch("/api/rb/auth/sign-in", {
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: {
|
|
128
|
+
"Content-Type": "application/json"
|
|
129
|
+
},
|
|
130
|
+
body: JSON.stringify(data)
|
|
131
|
+
});
|
|
132
|
+
const json = await res.json();
|
|
133
|
+
console.log("SIGN IN RESPONSE", json);
|
|
134
|
+
if (!res.ok) {
|
|
135
|
+
console.error("Sign-in failed", json);
|
|
136
|
+
}
|
|
137
|
+
} catch (err) {
|
|
138
|
+
console.error("Sign-in request error", err);
|
|
139
|
+
}
|
|
122
140
|
};
|
|
123
141
|
useEffect(() => {
|
|
124
142
|
console.log(methods.formState.errors);
|
|
@@ -129,21 +147,55 @@ const SignUpForm = ({
|
|
|
129
147
|
children,
|
|
130
148
|
className
|
|
131
149
|
}) => {
|
|
150
|
+
const [serverMessage, setServerMessage] = useState(null);
|
|
132
151
|
const methods = useForm({
|
|
133
152
|
defaultValues: {
|
|
134
153
|
email_or_phone: "",
|
|
135
154
|
password: "",
|
|
136
|
-
password_confirmation: ""
|
|
155
|
+
password_confirmation: "",
|
|
156
|
+
remember_me: true
|
|
137
157
|
},
|
|
138
158
|
resolver: zodResolver(requestSchema$1)
|
|
139
159
|
});
|
|
140
160
|
const onSubmit = async (data) => {
|
|
161
|
+
setServerMessage(null);
|
|
162
|
+
methods.clearErrors("root");
|
|
141
163
|
console.log("SUBMIT SIGNUp", data);
|
|
164
|
+
try {
|
|
165
|
+
const res = await fetch("/api/rb/auth/sign-up", {
|
|
166
|
+
method: "POST",
|
|
167
|
+
headers: {
|
|
168
|
+
"Content-Type": "application/json"
|
|
169
|
+
},
|
|
170
|
+
body: JSON.stringify(data)
|
|
171
|
+
});
|
|
172
|
+
const json = await res.json();
|
|
173
|
+
console.log("SIGN UP RESPONSE", json);
|
|
174
|
+
if (!res.ok) {
|
|
175
|
+
console.error("Sign-up failed", json);
|
|
176
|
+
const message = json.error === "user_exists" ? "An account already exists with this email or phone." : "Sign-up failed. Please try again.";
|
|
177
|
+
methods.setError("root", { type: "server", message });
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (!json.success) {
|
|
181
|
+
methods.setError("root", { type: "server", message: "Sign-up failed. Please try again." });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
setServerMessage("Account created. Check your inbox to verify your email.");
|
|
185
|
+
methods.reset();
|
|
186
|
+
} catch (err) {
|
|
187
|
+
console.error("Sign-up request error", err);
|
|
188
|
+
methods.setError("root", { type: "server", message: "Network error. Please try again." });
|
|
189
|
+
}
|
|
142
190
|
};
|
|
143
191
|
useEffect(() => {
|
|
144
192
|
console.log(methods.formState.errors);
|
|
145
193
|
}, [methods.formState.errors]);
|
|
146
|
-
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */
|
|
194
|
+
return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsxs("form", { method: "post", noValidate: true, className, onSubmit: methods.handleSubmit(onSubmit), children: [
|
|
195
|
+
children,
|
|
196
|
+
methods.formState.errors.root?.message && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-red-600", role: "alert", children: methods.formState.errors.root.message }),
|
|
197
|
+
serverMessage && /* @__PURE__ */ jsx("p", { className: "mt-2 text-sm text-green-700", role: "status", children: serverMessage })
|
|
198
|
+
] }) });
|
|
147
199
|
};
|
|
148
200
|
const RememberMeCheckbox = ({
|
|
149
201
|
label,
|
|
@@ -168,11 +220,40 @@ const RememberMeCheckbox = ({
|
|
|
168
220
|
)
|
|
169
221
|
] });
|
|
170
222
|
};
|
|
223
|
+
const PasswordInput = ({
|
|
224
|
+
id,
|
|
225
|
+
name = "password",
|
|
226
|
+
className,
|
|
227
|
+
placeholder,
|
|
228
|
+
autoComplete = "current-password"
|
|
229
|
+
}) => {
|
|
230
|
+
const { register, formState } = useFormContext();
|
|
231
|
+
const fieldError = formState.errors[name];
|
|
232
|
+
const errorMessage = typeof fieldError === "string" ? fieldError : typeof fieldError?.message === "string" ? fieldError.message : void 0;
|
|
233
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
234
|
+
/* @__PURE__ */ jsx(
|
|
235
|
+
"input",
|
|
236
|
+
{
|
|
237
|
+
id,
|
|
238
|
+
type: "password",
|
|
239
|
+
autoComplete,
|
|
240
|
+
className,
|
|
241
|
+
placeholder,
|
|
242
|
+
...register(name)
|
|
243
|
+
}
|
|
244
|
+
),
|
|
245
|
+
errorMessage ? /* @__PURE__ */ jsx("p", { className: "mt-1 -mb-2 text-sm/6 text-red-500", children: errorMessage }) : null
|
|
246
|
+
] });
|
|
247
|
+
};
|
|
171
248
|
export {
|
|
172
249
|
AppleSignInButton,
|
|
173
250
|
AuthLayout,
|
|
174
251
|
EmailOrPhoneInput,
|
|
252
|
+
PasswordInput,
|
|
175
253
|
RememberMeCheckbox,
|
|
176
254
|
SignInForm,
|
|
177
|
-
SignUpForm
|
|
255
|
+
SignUpForm,
|
|
256
|
+
b as redirectAuthMiddleware,
|
|
257
|
+
a as requireSession,
|
|
258
|
+
r as restrictSessionMiddleware
|
|
178
259
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const isAuthenticated = (req) => {
|
|
2
|
+
return Boolean(req.session?.user?.id);
|
|
3
|
+
};
|
|
4
|
+
const restrictSessionMiddleware = (req, res, next) => {
|
|
5
|
+
if (isAuthenticated(req)) {
|
|
6
|
+
return next();
|
|
7
|
+
}
|
|
8
|
+
res.status(401).json({ error: "unauthorized" });
|
|
9
|
+
};
|
|
10
|
+
const requireSession = restrictSessionMiddleware;
|
|
11
|
+
const redirectAuthMiddleware = (req, res, next) => {
|
|
12
|
+
if (req.path.startsWith("/app") && !isAuthenticated(req)) {
|
|
13
|
+
return res.redirect("/auth/sign-in");
|
|
14
|
+
}
|
|
15
|
+
next();
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
requireSession as a,
|
|
19
|
+
redirectAuthMiddleware as b,
|
|
20
|
+
restrictSessionMiddleware as r
|
|
21
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Middleware } from '../../api/src';
|
|
2
|
+
import { AuthSessionUser } from './types';
|
|
3
|
+
export declare const restrictSessionMiddleware: Middleware<AuthSessionUser>;
|
|
4
|
+
export declare const requireSession: Middleware<AuthSessionUser>;
|
|
5
|
+
export declare const redirectAuthMiddleware: Middleware<AuthSessionUser>;
|
|
6
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAO9C,eAAO,MAAM,yBAAyB,EAAE,UAAU,CAAC,eAAe,CAMjE,CAAA;AAED,eAAO,MAAM,cAAc,6BAA4B,CAAA;AAEvD,eAAO,MAAM,sBAAsB,EAAE,UAAU,CAAC,eAAe,CAM9D,CAAA"}
|
package/dist/routes.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const routes = Object.entries({
|
|
2
|
-
.../* @__PURE__ */ Object.assign({ "./api/sign-in/handler.ts": () => import("./handler-
|
|
2
|
+
.../* @__PURE__ */ Object.assign({ "./api/me/handler.ts": () => import("./handler-Ba3pgtfZ.js"), "./api/sign-in/handler.ts": () => import("./handler-BSoyBLZM.js"), "./api/sign-out/handler.ts": () => import("./handler-CNHucHrj.js"), "./api/sign-up/handler.ts": () => import("./handler-rZR_dx7n.js") })
|
|
3
3
|
}).reduce((acc, [path, mod]) => {
|
|
4
4
|
acc[path.replace("./api/", "@rpcbase/auth/api/")] = mod;
|
|
5
5
|
return acc;
|
|
@@ -1,29 +1,38 @@
|
|
|
1
1
|
function $constructor(name, initializer2, params) {
|
|
2
2
|
function init(inst, def) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
if (!inst._zod) {
|
|
4
|
+
Object.defineProperty(inst, "_zod", {
|
|
5
|
+
value: {
|
|
6
|
+
def,
|
|
7
|
+
constr: _,
|
|
8
|
+
traits: /* @__PURE__ */ new Set()
|
|
9
|
+
},
|
|
10
|
+
enumerable: false
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (inst._zod.traits.has(name)) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
9
16
|
inst._zod.traits.add(name);
|
|
10
17
|
initializer2(inst, def);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
const proto = _.prototype;
|
|
19
|
+
const keys = Object.keys(proto);
|
|
20
|
+
for (let i = 0; i < keys.length; i++) {
|
|
21
|
+
const k = keys[i];
|
|
22
|
+
if (!(k in inst)) {
|
|
23
|
+
inst[k] = proto[k].bind(inst);
|
|
24
|
+
}
|
|
14
25
|
}
|
|
15
|
-
inst._zod.constr = _;
|
|
16
|
-
inst._zod.def = def;
|
|
17
26
|
}
|
|
18
27
|
const Parent = params?.Parent ?? Object;
|
|
19
28
|
class Definition extends Parent {
|
|
20
29
|
}
|
|
21
30
|
Object.defineProperty(Definition, "name", { value: name });
|
|
22
31
|
function _(def) {
|
|
23
|
-
var
|
|
32
|
+
var _a2;
|
|
24
33
|
const inst = params?.Parent ? new Definition() : this;
|
|
25
34
|
init(inst, def);
|
|
26
|
-
(
|
|
35
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
27
36
|
for (const fn of inst._zod.deferred) {
|
|
28
37
|
fn();
|
|
29
38
|
}
|
|
@@ -126,6 +135,9 @@ function mergeDefs(...defs) {
|
|
|
126
135
|
function esc(str) {
|
|
127
136
|
return JSON.stringify(str);
|
|
128
137
|
}
|
|
138
|
+
function slugify(input) {
|
|
139
|
+
return input.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
140
|
+
}
|
|
129
141
|
const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => {
|
|
130
142
|
};
|
|
131
143
|
function isObject(data) {
|
|
@@ -149,6 +161,8 @@ function isPlainObject(o) {
|
|
|
149
161
|
const ctor = o.constructor;
|
|
150
162
|
if (ctor === void 0)
|
|
151
163
|
return true;
|
|
164
|
+
if (typeof ctor !== "function")
|
|
165
|
+
return true;
|
|
152
166
|
const prot = ctor.prototype;
|
|
153
167
|
if (isObject(prot) === false)
|
|
154
168
|
return false;
|
|
@@ -360,8 +374,8 @@ function aborted(x, startIndex = 0) {
|
|
|
360
374
|
}
|
|
361
375
|
function prefixIssues(path, issues) {
|
|
362
376
|
return issues.map((iss) => {
|
|
363
|
-
var
|
|
364
|
-
(
|
|
377
|
+
var _a2;
|
|
378
|
+
(_a2 = iss).path ?? (_a2.path = []);
|
|
365
379
|
iss.path.unshift(path);
|
|
366
380
|
return iss;
|
|
367
381
|
});
|
|
@@ -565,7 +579,6 @@ const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-
|
|
|
565
579
|
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
566
580
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
567
581
|
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
568
|
-
const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
569
582
|
const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
|
570
583
|
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
571
584
|
const date$1 = /* @__PURE__ */ new RegExp(`^${dateSource}$`);
|
|
@@ -595,15 +608,15 @@ const boolean$1 = /^(?:true|false)$/i;
|
|
|
595
608
|
const lowercase = /^[^A-Z]*$/;
|
|
596
609
|
const uppercase = /^[^a-z]*$/;
|
|
597
610
|
const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
598
|
-
var
|
|
611
|
+
var _a2;
|
|
599
612
|
inst._zod ?? (inst._zod = {});
|
|
600
613
|
inst._zod.def = def;
|
|
601
|
-
(
|
|
614
|
+
(_a2 = inst._zod).onattach ?? (_a2.onattach = []);
|
|
602
615
|
});
|
|
603
616
|
const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
604
|
-
var
|
|
617
|
+
var _a2;
|
|
605
618
|
$ZodCheck.init(inst, def);
|
|
606
|
-
(
|
|
619
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
607
620
|
const val = payload.value;
|
|
608
621
|
return !nullish(val) && val.length !== void 0;
|
|
609
622
|
});
|
|
@@ -630,9 +643,9 @@ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (i
|
|
|
630
643
|
};
|
|
631
644
|
});
|
|
632
645
|
const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
|
|
633
|
-
var
|
|
646
|
+
var _a2;
|
|
634
647
|
$ZodCheck.init(inst, def);
|
|
635
|
-
(
|
|
648
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
636
649
|
const val = payload.value;
|
|
637
650
|
return !nullish(val) && val.length !== void 0;
|
|
638
651
|
});
|
|
@@ -659,9 +672,9 @@ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (i
|
|
|
659
672
|
};
|
|
660
673
|
});
|
|
661
674
|
const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
662
|
-
var
|
|
675
|
+
var _a2;
|
|
663
676
|
$ZodCheck.init(inst, def);
|
|
664
|
-
(
|
|
677
|
+
(_a2 = inst._zod.def).when ?? (_a2.when = (payload) => {
|
|
665
678
|
const val = payload.value;
|
|
666
679
|
return !nullish(val) && val.length !== void 0;
|
|
667
680
|
});
|
|
@@ -690,7 +703,7 @@ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEqual
|
|
|
690
703
|
};
|
|
691
704
|
});
|
|
692
705
|
const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
|
|
693
|
-
var
|
|
706
|
+
var _a2, _b;
|
|
694
707
|
$ZodCheck.init(inst, def);
|
|
695
708
|
inst._zod.onattach.push((inst2) => {
|
|
696
709
|
const bag = inst2._zod.bag;
|
|
@@ -701,7 +714,7 @@ const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringForma
|
|
|
701
714
|
}
|
|
702
715
|
});
|
|
703
716
|
if (def.pattern)
|
|
704
|
-
(
|
|
717
|
+
(_a2 = inst._zod).check ?? (_a2.check = (payload) => {
|
|
705
718
|
def.pattern.lastIndex = 0;
|
|
706
719
|
if (def.pattern.test(payload.value))
|
|
707
720
|
return;
|
|
@@ -857,10 +870,10 @@ class Doc {
|
|
|
857
870
|
const version = {
|
|
858
871
|
major: 4,
|
|
859
872
|
minor: 1,
|
|
860
|
-
patch:
|
|
873
|
+
patch: 13
|
|
861
874
|
};
|
|
862
875
|
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
863
|
-
var
|
|
876
|
+
var _a2;
|
|
864
877
|
inst ?? (inst = {});
|
|
865
878
|
inst._zod.def = def;
|
|
866
879
|
inst._zod.bag = inst._zod.bag || {};
|
|
@@ -875,7 +888,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
875
888
|
}
|
|
876
889
|
}
|
|
877
890
|
if (checks.length === 0) {
|
|
878
|
-
(
|
|
891
|
+
(_a2 = inst._zod).deferred ?? (_a2.deferred = []);
|
|
879
892
|
inst._zod.deferred?.push(() => {
|
|
880
893
|
inst._zod.run = inst._zod.parse;
|
|
881
894
|
});
|
|
@@ -1033,7 +1046,7 @@ const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
|
1033
1046
|
code: "invalid_format",
|
|
1034
1047
|
format: "url",
|
|
1035
1048
|
note: "Invalid hostname",
|
|
1036
|
-
pattern: hostname.source,
|
|
1049
|
+
pattern: def.hostname.source,
|
|
1037
1050
|
input: payload.value,
|
|
1038
1051
|
inst,
|
|
1039
1052
|
continue: !def.abort
|
|
@@ -1118,18 +1131,12 @@ const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, d
|
|
|
1118
1131
|
const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
|
|
1119
1132
|
def.pattern ?? (def.pattern = ipv4);
|
|
1120
1133
|
$ZodStringFormat.init(inst, def);
|
|
1121
|
-
inst._zod.
|
|
1122
|
-
const bag = inst2._zod.bag;
|
|
1123
|
-
bag.format = `ipv4`;
|
|
1124
|
-
});
|
|
1134
|
+
inst._zod.bag.format = `ipv4`;
|
|
1125
1135
|
});
|
|
1126
1136
|
const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
|
|
1127
1137
|
def.pattern ?? (def.pattern = ipv6);
|
|
1128
1138
|
$ZodStringFormat.init(inst, def);
|
|
1129
|
-
inst._zod.
|
|
1130
|
-
const bag = inst2._zod.bag;
|
|
1131
|
-
bag.format = `ipv6`;
|
|
1132
|
-
});
|
|
1139
|
+
inst._zod.bag.format = `ipv6`;
|
|
1133
1140
|
inst._zod.check = (payload) => {
|
|
1134
1141
|
try {
|
|
1135
1142
|
new URL(`http://[${payload.value}]`);
|
|
@@ -1191,9 +1198,7 @@ function isValidBase64(data) {
|
|
|
1191
1198
|
const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
|
|
1192
1199
|
def.pattern ?? (def.pattern = base64);
|
|
1193
1200
|
$ZodStringFormat.init(inst, def);
|
|
1194
|
-
inst._zod.
|
|
1195
|
-
inst2._zod.bag.contentEncoding = "base64";
|
|
1196
|
-
});
|
|
1201
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
1197
1202
|
inst._zod.check = (payload) => {
|
|
1198
1203
|
if (isValidBase64(payload.value))
|
|
1199
1204
|
return;
|
|
@@ -1216,9 +1221,7 @@ function isValidBase64URL(data) {
|
|
|
1216
1221
|
const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1217
1222
|
def.pattern ?? (def.pattern = base64url);
|
|
1218
1223
|
$ZodStringFormat.init(inst, def);
|
|
1219
|
-
inst._zod.
|
|
1220
|
-
inst2._zod.bag.contentEncoding = "base64url";
|
|
1221
|
-
});
|
|
1224
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
1222
1225
|
inst._zod.check = (payload) => {
|
|
1223
1226
|
if (isValidBase64URL(payload.value))
|
|
1224
1227
|
return;
|
|
@@ -1378,7 +1381,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1378
1381
|
const keySet = def.keySet;
|
|
1379
1382
|
const _catchall = def.catchall._zod;
|
|
1380
1383
|
const t = _catchall.def.type;
|
|
1381
|
-
for (const key
|
|
1384
|
+
for (const key in input) {
|
|
1382
1385
|
if (keySet.has(key))
|
|
1383
1386
|
continue;
|
|
1384
1387
|
if (t === "never") {
|
|
@@ -1909,8 +1912,8 @@ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) =>
|
|
|
1909
1912
|
$ZodType.init(inst, def);
|
|
1910
1913
|
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
1911
1914
|
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
1912
|
-
defineLazy(inst._zod, "optin", () => def.innerType
|
|
1913
|
-
defineLazy(inst._zod, "optout", () => def.innerType
|
|
1915
|
+
defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
|
1916
|
+
defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
|
1914
1917
|
inst._zod.parse = (payload, ctx) => {
|
|
1915
1918
|
if (ctx.direction === "backward") {
|
|
1916
1919
|
return def.innerType._zod.run(payload, ctx);
|
|
@@ -1959,6 +1962,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
1959
1962
|
payload.issues.push(issue(_iss));
|
|
1960
1963
|
}
|
|
1961
1964
|
}
|
|
1965
|
+
var _a;
|
|
1962
1966
|
class $ZodRegistry {
|
|
1963
1967
|
constructor() {
|
|
1964
1968
|
this._map = /* @__PURE__ */ new WeakMap();
|
|
@@ -2005,7 +2009,8 @@ class $ZodRegistry {
|
|
|
2005
2009
|
function registry() {
|
|
2006
2010
|
return new $ZodRegistry();
|
|
2007
2011
|
}
|
|
2008
|
-
|
|
2012
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2013
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2009
2014
|
function _string(Class, params) {
|
|
2010
2015
|
return new Class({
|
|
2011
2016
|
type: "string",
|
|
@@ -2352,6 +2357,9 @@ function _toLowerCase() {
|
|
|
2352
2357
|
function _toUpperCase() {
|
|
2353
2358
|
return _overwrite((input) => input.toUpperCase());
|
|
2354
2359
|
}
|
|
2360
|
+
function _slugify() {
|
|
2361
|
+
return _overwrite((input) => slugify(input));
|
|
2362
|
+
}
|
|
2355
2363
|
function _array(Class, element, params) {
|
|
2356
2364
|
return new Class({
|
|
2357
2365
|
type: "array",
|
|
@@ -2568,6 +2576,7 @@ const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
|
|
|
2568
2576
|
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
2569
2577
|
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
2570
2578
|
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
2579
|
+
inst.slugify = () => inst.check(_slugify());
|
|
2571
2580
|
});
|
|
2572
2581
|
const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
|
|
2573
2582
|
$ZodString.init(inst, def);
|
|
@@ -2966,6 +2975,7 @@ function superRefine(fn) {
|
|
|
2966
2975
|
return _superRefine(fn);
|
|
2967
2976
|
}
|
|
2968
2977
|
export {
|
|
2978
|
+
array as a,
|
|
2969
2979
|
boolean as b,
|
|
2970
2980
|
object as o,
|
|
2971
2981
|
string as s
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,iBAAiB,EAAE,MAAM,CAAA;IACzB,iBAAiB,EAAE,MAAM,EAAE,CAAA;IAC3B,wBAAwB,EAAE,OAAO,CAAA;CAClC,CAAA"}
|
package/package.json
CHANGED
package/dist/handler-Bl5DlLdb.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto";
|
|
2
|
-
import { i as isEmail } from "./isEmail-IG0hXiQk.js";
|
|
3
|
-
import { loadModel } from "@rpcbase/api";
|
|
4
|
-
import { hashPassword } from "@rpcbase/server";
|
|
5
|
-
import { R as Route, r as requestSchema } from "./index-BYEYCL3Q.js";
|
|
6
|
-
const signUp = async (payload, ctx) => {
|
|
7
|
-
const User = await loadModel("User", ctx);
|
|
8
|
-
const { email_or_phone, password } = requestSchema.parse(payload);
|
|
9
|
-
const is_email = isEmail(email_or_phone);
|
|
10
|
-
const query = is_email ? { email: email_or_phone } : { phone: email_or_phone };
|
|
11
|
-
const existingUser = await User.findOne(query);
|
|
12
|
-
if (existingUser) {
|
|
13
|
-
console.log("user with email or phone already exists", email_or_phone);
|
|
14
|
-
return { success: false };
|
|
15
|
-
}
|
|
16
|
-
const salt = crypto.randomBytes(16).toString("hex");
|
|
17
|
-
const derivedKey = await hashPassword(password, salt);
|
|
18
|
-
const hashedPassword = `${salt}:${derivedKey.toString("hex")}`;
|
|
19
|
-
const user = new User({
|
|
20
|
-
...query,
|
|
21
|
-
password: hashedPassword
|
|
22
|
-
});
|
|
23
|
-
await user.save();
|
|
24
|
-
console.log("created new user", user._id.toString());
|
|
25
|
-
return { success: true };
|
|
26
|
-
};
|
|
27
|
-
const handler = (api) => {
|
|
28
|
-
api.post(Route, signUp);
|
|
29
|
-
};
|
|
30
|
-
export {
|
|
31
|
-
handler as default
|
|
32
|
-
};
|
package/dist/handler-CSmOkoqC.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { i as isEmail } from "./isEmail-IG0hXiQk.js";
|
|
2
|
-
import { R as Route, r as requestSchema } from "./index-BphnyggH.js";
|
|
3
|
-
const signIn = async (payload, ctx) => {
|
|
4
|
-
const { email_or_phone } = requestSchema.parse(payload);
|
|
5
|
-
if (isEmail(email_or_phone)) {
|
|
6
|
-
console.log("is valid email");
|
|
7
|
-
} else {
|
|
8
|
-
console.log("is not valid email");
|
|
9
|
-
}
|
|
10
|
-
return { success: true };
|
|
11
|
-
};
|
|
12
|
-
const handler = (api) => {
|
|
13
|
-
api.post(Route, signIn);
|
|
14
|
-
};
|
|
15
|
-
export {
|
|
16
|
-
handler as default
|
|
17
|
-
};
|