@rpcbase/auth 0.68.0 → 0.69.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.
@@ -8,8 +8,8 @@ export declare const responseSchema: z.ZodObject<{
8
8
  phone: z.ZodOptional<z.ZodString>;
9
9
  name: z.ZodOptional<z.ZodString>;
10
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>>>;
11
+ currentTenantId: z.ZodOptional<z.ZodString>;
12
+ signedInTenants: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString>>>;
13
13
  error: z.ZodOptional<z.ZodString>;
14
14
  }, z.core.$strip>;
15
15
  export type ResponsePayload = z.infer<typeof responseSchema>;
@@ -3,14 +3,14 @@ export declare const Route = "/api/rb/auth/sign-in";
3
3
  export declare const requestSchema: z.ZodObject<{
4
4
  email: z.ZodString;
5
5
  password: z.ZodString;
6
- remember_me: z.ZodDefault<z.ZodBoolean>;
6
+ rememberMe: z.ZodDefault<z.ZodBoolean>;
7
7
  }, z.core.$strip>;
8
8
  export type RequestPayload = z.infer<typeof requestSchema>;
9
9
  export declare const responseSchema: z.ZodObject<{
10
10
  success: z.ZodBoolean;
11
11
  error: z.ZodOptional<z.ZodString>;
12
- user_id: z.ZodOptional<z.ZodString>;
13
- tenant_id: z.ZodOptional<z.ZodString>;
12
+ userId: z.ZodOptional<z.ZodString>;
13
+ tenantId: z.ZodOptional<z.ZodString>;
14
14
  }, z.core.$strip>;
15
15
  export type ResponsePayload = z.infer<typeof responseSchema>;
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -3,14 +3,14 @@ export declare const Route = "/api/rb/auth/sign-up";
3
3
  export declare const requestSchema: z.ZodObject<{
4
4
  email: z.ZodString;
5
5
  password: z.ZodString;
6
- remember_me: z.ZodDefault<z.ZodBoolean>;
6
+ rememberMe: z.ZodDefault<z.ZodBoolean>;
7
7
  }, z.core.$strip>;
8
8
  export type RequestPayload = z.infer<typeof requestSchema>;
9
9
  export declare const responseSchema: z.ZodObject<{
10
10
  success: z.ZodBoolean;
11
11
  error: z.ZodOptional<z.ZodString>;
12
- user_id: z.ZodOptional<z.ZodString>;
13
- tenant_id: z.ZodOptional<z.ZodString>;
12
+ userId: z.ZodOptional<z.ZodString>;
13
+ tenantId: z.ZodOptional<z.ZodString>;
14
14
  }, z.core.$strip>;
15
15
  export type ResponsePayload = z.infer<typeof responseSchema>;
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -3,14 +3,14 @@ export declare const Route = "/api/rb/auth/verify-otp";
3
3
  export declare const requestSchema: z.ZodObject<{
4
4
  email: z.ZodString;
5
5
  code: z.ZodString;
6
- remember_me: z.ZodDefault<z.ZodBoolean>;
6
+ rememberMe: z.ZodDefault<z.ZodBoolean>;
7
7
  }, z.core.$strip>;
8
8
  export type RequestPayload = z.infer<typeof requestSchema>;
9
9
  export declare const responseSchema: z.ZodObject<{
10
10
  success: z.ZodBoolean;
11
11
  error: z.ZodOptional<z.ZodString>;
12
- user_id: z.ZodOptional<z.ZodString>;
13
- tenant_id: z.ZodOptional<z.ZodString>;
12
+ userId: z.ZodOptional<z.ZodString>;
13
+ tenantId: z.ZodOptional<z.ZodString>;
14
14
  }, z.core.$strip>;
15
15
  export type ResponsePayload = z.infer<typeof responseSchema>;
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1,6 +1,6 @@
1
1
  import { loadRbModel } from "@rpcbase/db";
2
2
  import { verifyPasswordFromStorage } from "@rpcbase/server";
3
- import { R as Route, r as requestSchema } from "./index-Bdcryyvv.js";
3
+ import { R as Route, r as requestSchema } from "./index-D-Zfc6Rv.js";
4
4
  const signIn = async (payload, ctx) => {
5
5
  const User = await loadRbModel("RBUser", ctx);
6
6
  const parsed = requestSchema.safeParse(payload);
@@ -31,11 +31,11 @@ const signIn = async (payload, ctx) => {
31
31
  }
32
32
  ctx.req.session.user = {
33
33
  id: user._id.toString(),
34
- current_tenant_id: tenantId,
35
- signed_in_tenants: signedInTenants.length ? signedInTenants : [tenantId],
36
- is_entry_gate_authorized: true
34
+ currentTenantId: tenantId,
35
+ signedInTenants: signedInTenants.length ? signedInTenants : [tenantId],
36
+ isEntryGateAuthorized: true
37
37
  };
38
- return { success: true, user_id: user._id.toString(), tenant_id: tenantId };
38
+ return { success: true, userId: user._id.toString(), tenantId };
39
39
  };
40
40
  const handler = (api) => {
41
41
  api.post(Route, signIn);
@@ -4,13 +4,13 @@ const Route = "/api/rb/auth/verify-otp";
4
4
  const requestSchema = object({
5
5
  email: string().email(),
6
6
  code: string().length(6, "Code must be 6 digits"),
7
- remember_me: boolean().default(true)
7
+ rememberMe: boolean().default(true)
8
8
  });
9
9
  object({
10
10
  success: boolean(),
11
11
  error: string().optional(),
12
- user_id: string().optional(),
13
- tenant_id: string().optional()
12
+ userId: string().optional(),
13
+ tenantId: string().optional()
14
14
  });
15
15
  const verifyOtp = async (payload, ctx) => {
16
16
  const User = await loadRbModel("RBUser", ctx);
@@ -20,20 +20,20 @@ const verifyOtp = async (payload, ctx) => {
20
20
  return { success: false, error: "invalid_payload" };
21
21
  }
22
22
  const { email, code } = parsed.data;
23
- const user = await User.findOne({ email }, { email_verification_code: 1, email_verification_expires_at: 1, tenants: 1 });
23
+ const user = await User.findOne({ email }, { emailVerificationCode: 1, emailVerificationExpiresAt: 1, tenants: 1 });
24
24
  if (!user) {
25
25
  ctx.res.status(404);
26
26
  return { success: false, error: "user_not_found" };
27
27
  }
28
- const storedCode = user.email_verification_code;
29
- const expiresAt = user.email_verification_expires_at;
28
+ const storedCode = user.emailVerificationCode;
29
+ const expiresAt = user.emailVerificationExpiresAt;
30
30
  const isExpired = expiresAt instanceof Date && expiresAt.getTime() < Date.now();
31
31
  if (!storedCode || storedCode !== code || isExpired) {
32
32
  ctx.res.status(400);
33
33
  return { success: false, error: "invalid_code" };
34
34
  }
35
- user.email_verification_code = void 0;
36
- user.email_verification_expires_at = void 0;
35
+ user.emailVerificationCode = void 0;
36
+ user.emailVerificationExpiresAt = void 0;
37
37
  await user.save();
38
38
  const tenantId = user.tenants?.[0]?.toString?.() || "00000000";
39
39
  const signedInTenants = (user.tenants || []).map((t) => t.toString?.() || String(t)) || [tenantId];
@@ -43,11 +43,11 @@ const verifyOtp = async (payload, ctx) => {
43
43
  }
44
44
  ctx.req.session.user = {
45
45
  id: user._id.toString(),
46
- current_tenant_id: tenantId,
47
- signed_in_tenants: signedInTenants.length ? signedInTenants : [tenantId],
48
- is_entry_gate_authorized: true
46
+ currentTenantId: tenantId,
47
+ signedInTenants: signedInTenants.length ? signedInTenants : [tenantId],
48
+ isEntryGateAuthorized: true
49
49
  };
50
- return { success: true, user_id: user._id.toString(), tenant_id: tenantId };
50
+ return { success: true, userId: user._id.toString(), tenantId };
51
51
  };
52
52
  const handler = (api) => {
53
53
  api.post(Route, verifyOtp);
@@ -9,8 +9,8 @@ object({
9
9
  phone: string().optional(),
10
10
  name: string().optional(),
11
11
  tenants: array(string()).default([]),
12
- current_tenant_id: string().optional(),
13
- signed_in_tenants: array(string()).default([]).optional(),
12
+ currentTenantId: string().optional(),
13
+ signedInTenants: array(string()).default([]).optional(),
14
14
  error: string().optional()
15
15
  });
16
16
  const me = async (_payload, ctx) => {
@@ -19,8 +19,8 @@ const me = async (_payload, ctx) => {
19
19
  ctx.res.status(401);
20
20
  return {
21
21
  id: "",
22
- current_tenant_id: "",
23
- signed_in_tenants: [],
22
+ currentTenantId: "",
23
+ signedInTenants: [],
24
24
  tenants: [],
25
25
  error: "not_authenticated"
26
26
  };
@@ -31,21 +31,21 @@ const me = async (_payload, ctx) => {
31
31
  ctx.res.status(404);
32
32
  return {
33
33
  id: "",
34
- current_tenant_id: "",
35
- signed_in_tenants: [],
34
+ currentTenantId: "",
35
+ signedInTenants: [],
36
36
  tenants: [],
37
37
  error: "user_not_found"
38
38
  };
39
39
  }
40
- const tenantId = sessionUser.current_tenant_id || user.tenants?.[0]?.toString?.() || "00000000";
40
+ const tenantId = sessionUser.currentTenantId || user.tenants?.[0]?.toString?.() || "00000000";
41
41
  return {
42
42
  id: user._id.toString(),
43
43
  email: user.email,
44
44
  phone: user.phone,
45
45
  name: user.name,
46
46
  tenants: (user.tenants || []).map((t) => t.toString?.() || String(t)),
47
- current_tenant_id: tenantId,
48
- signed_in_tenants: sessionUser.signed_in_tenants || []
47
+ currentTenantId: tenantId,
48
+ signedInTenants: sessionUser.signedInTenants || []
49
49
  };
50
50
  };
51
51
  const handler = (api) => {
@@ -1,7 +1,7 @@
1
1
  import crypto from "crypto";
2
2
  import { loadRbModel } from "@rpcbase/db";
3
3
  import { hashPasswordForStorage, sendEmail } from "@rpcbase/server";
4
- import { R as Route, r as requestSchema } from "./index-DwX0Y2YV.js";
4
+ import { R as Route, r as requestSchema } from "./index-DusvXcjg.js";
5
5
  const signUp = async (payload, ctx) => {
6
6
  const User = await loadRbModel("RBUser", ctx);
7
7
  const Tenant = await loadRbModel("RBTenant", ctx);
@@ -10,7 +10,7 @@ const signUp = async (payload, ctx) => {
10
10
  ctx.res.status(400);
11
11
  return { success: false, error: "invalid_payload" };
12
12
  }
13
- const { email, password, remember_me: _remember_me } = parsed.data;
13
+ const { email, password, rememberMe: _rememberMe } = parsed.data;
14
14
  const existingUser = await User.findOne({ email });
15
15
  if (existingUser) {
16
16
  console.log("user with email already exists", email);
@@ -25,8 +25,8 @@ const signUp = async (payload, ctx) => {
25
25
  email,
26
26
  password: hashedPassword,
27
27
  tenants: [tenantId],
28
- email_verification_code: emailVerificationCode,
29
- email_verification_expires_at: emailVerificationExpiresAt
28
+ emailVerificationCode,
29
+ emailVerificationExpiresAt
30
30
  });
31
31
  await user.save();
32
32
  try {
@@ -45,14 +45,14 @@ const signUp = async (payload, ctx) => {
45
45
  }
46
46
  try {
47
47
  await Tenant.create({
48
- tenant_id: tenantId,
48
+ tenantId,
49
49
  name: email
50
50
  });
51
51
  } catch (err) {
52
52
  console.warn("failed to create tenant for user", err);
53
53
  }
54
54
  console.log("created new user", user._id.toString());
55
- return { success: true, user_id: user._id.toString(), tenant_id: tenantId };
55
+ return { success: true, userId: user._id.toString(), tenantId };
56
56
  };
57
57
  const handler = (api) => {
58
58
  api.post(Route, signUp);
@@ -25,8 +25,8 @@ const resendOtp = async (payload, ctx) => {
25
25
  }
26
26
  const emailVerificationCode = crypto.randomInt(0, 1e6).toString().padStart(6, "0");
27
27
  const emailVerificationExpiresAt = new Date(Date.now() + 10 * 60 * 1e3);
28
- user.email_verification_code = emailVerificationCode;
29
- user.email_verification_expires_at = emailVerificationExpiresAt;
28
+ user.emailVerificationCode = emailVerificationCode;
29
+ user.emailVerificationExpiresAt = emailVerificationExpiresAt;
30
30
  await user.save();
31
31
  try {
32
32
  await sendEmail({
@@ -3,13 +3,13 @@ const Route = "/api/rb/auth/sign-in";
3
3
  const requestSchema = object({
4
4
  email: string().nonempty("Email is required").email("Please enter a valid email address"),
5
5
  password: string().min(1, { message: "Password is required" }),
6
- remember_me: boolean().default(true)
6
+ rememberMe: boolean().default(true)
7
7
  });
8
8
  object({
9
9
  success: boolean(),
10
10
  error: string().optional(),
11
- user_id: string().optional(),
12
- tenant_id: string().optional()
11
+ userId: string().optional(),
12
+ tenantId: string().optional()
13
13
  });
14
14
  export {
15
15
  Route as R,
@@ -3,13 +3,13 @@ const Route = "/api/rb/auth/sign-up";
3
3
  const requestSchema = object({
4
4
  email: string().nonempty("Email is required").email("Please enter a valid email address"),
5
5
  password: string().min(8, { message: "Password must be at least 8 characters long." }),
6
- remember_me: boolean().default(true)
6
+ rememberMe: boolean().default(true)
7
7
  });
8
8
  object({
9
9
  success: boolean(),
10
10
  error: string().optional(),
11
- user_id: string().optional(),
12
- tenant_id: string().optional()
11
+ userId: string().optional(),
12
+ tenantId: string().optional()
13
13
  });
14
14
  export {
15
15
  Route as R,
package/dist/index.js CHANGED
@@ -2,9 +2,9 @@ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import { useLocation, Link, useNavigate, useSearchParams } from "@rpcbase/router";
3
3
  import clsx from "clsx";
4
4
  import { useFormContext, useForm, zodResolver, FormProvider } from "@rpcbase/form";
5
- import { r as requestSchema } from "./index-Bdcryyvv.js";
5
+ import { r as requestSchema } from "./index-D-Zfc6Rv.js";
6
6
  import { useState, useEffect, useCallback, useMemo } from "react";
7
- import { r as requestSchema$1 } from "./index-DwX0Y2YV.js";
7
+ import { r as requestSchema$1 } from "./index-DusvXcjg.js";
8
8
  import { EyeOff, Eye } from "lucide-react";
9
9
  import { b, a, r } from "./middleware-BiMXO6Dq.js";
10
10
  const LINKS_REDIRECTION_MAP = {
@@ -146,7 +146,7 @@ const SignInForm = ({
146
146
  defaultValues: {
147
147
  email: "",
148
148
  password: "",
149
- remember_me: true
149
+ rememberMe: true
150
150
  },
151
151
  navigationGuard: false,
152
152
  resolver: zodResolver(requestSchema)
@@ -190,7 +190,7 @@ const SignUpForm = ({
190
190
  defaultValues: {
191
191
  email: "",
192
192
  password: "",
193
- remember_me: true
193
+ rememberMe: true
194
194
  },
195
195
  navigationGuard: false,
196
196
  resolver: zodResolver(requestSchema$1)
@@ -242,14 +242,14 @@ const RememberMeCheckbox = ({
242
242
  /* @__PURE__ */ jsx(
243
243
  Component,
244
244
  {
245
- id: "remember_me",
246
- ...register("remember_me")
245
+ id: "rememberMe",
246
+ ...register("rememberMe")
247
247
  }
248
248
  ),
249
249
  /* @__PURE__ */ jsx(
250
250
  "label",
251
251
  {
252
- htmlFor: "remember_me",
252
+ htmlFor: "rememberMe",
253
253
  className: "pl-2 block text-sm/6 text-gray-900",
254
254
  children: label
255
255
  }
package/dist/routes.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const routes = Object.entries({
2
- .../* @__PURE__ */ Object.assign({ "./api/me/handler.ts": () => import("./handler-4XBN4nVK.js"), "./api/resend-otp/handler.ts": () => import("./handler-l_ZFKr_v.js"), "./api/sign-in/handler.ts": () => import("./handler-DrTPUoF0.js"), "./api/sign-out/handler.ts": () => import("./handler-CNHucHrj.js"), "./api/sign-up/handler.ts": () => import("./handler-D0JXRtpm.js"), "./api/verify-otp/handler.ts": () => import("./handler-BLs8Y-gl.js") })
2
+ .../* @__PURE__ */ Object.assign({ "./api/me/handler.ts": () => import("./handler-D5EPEBYU.js"), "./api/resend-otp/handler.ts": () => import("./handler-c6CkOrui.js"), "./api/sign-in/handler.ts": () => import("./handler-BB84i8oG.js"), "./api/sign-out/handler.ts": () => import("./handler-CNHucHrj.js"), "./api/sign-up/handler.ts": () => import("./handler-DGKxKbQ0.js"), "./api/verify-otp/handler.ts": () => import("./handler-CJC8FYyM.js") })
3
3
  }).reduce((acc, [path, mod]) => {
4
4
  acc[path.replace("./api/", "@rpcbase/auth/api/")] = mod;
5
5
  return acc;
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type AuthSessionUser = {
2
2
  id: string;
3
- current_tenant_id: string;
4
- signed_in_tenants: string[];
5
- is_entry_gate_authorized: boolean;
3
+ currentTenantId: string;
4
+ signedInTenants: string[];
5
+ isEntryGateAuthorized: boolean;
6
6
  };
7
7
  //# sourceMappingURL=types.d.ts.map
@@ -1 +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"}
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,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB,qBAAqB,EAAE,OAAO,CAAA;CAC/B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/auth",
3
- "version": "0.68.0",
3
+ "version": "0.69.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",