@rpcbase/auth 0.36.0 → 0.38.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.
@@ -2,7 +2,7 @@ import crypto from "crypto";
2
2
  import { i as isEmail } from "./isEmail-IG0hXiQk.js";
3
3
  import { loadModel } from "@rpcbase/api";
4
4
  import { hashPassword } from "@rpcbase/server";
5
- import { a as Route, c as requestSchema } from "./index-DGbE-dXC.js";
5
+ import { R as Route, r as requestSchema } from "./index-BYEYCL3Q.js";
6
6
  const signUp = async (payload, ctx) => {
7
7
  const User = await loadModel("User", ctx);
8
8
  const { email_or_phone, password } = requestSchema.parse(payload);
@@ -1,5 +1,5 @@
1
1
  import { i as isEmail } from "./isEmail-IG0hXiQk.js";
2
- import { R as Route, r as requestSchema } from "./index-DGbE-dXC.js";
2
+ import { R as Route, r as requestSchema } from "./index-BphnyggH.js";
3
3
  const signIn = async (payload, ctx) => {
4
4
  const { email_or_phone } = requestSchema.parse(payload);
5
5
  if (isEmail(email_or_phone)) {
@@ -1,4 +1,4 @@
1
- import { o as object, b as boolean } from "./index-DGbE-dXC.js";
1
+ import { o as object, b as boolean } from "./schemas-DKK0lkQz.js";
2
2
  const Route = "/api/rb/auth/sign-out";
3
3
  object({});
4
4
  object({
@@ -0,0 +1,25 @@
1
+ import { i as isValidNumber } from "./isValidNumber-6pMDGLRn.js";
2
+ import { o as object, s as string, b as boolean } from "./schemas-DKK0lkQz.js";
3
+ const Route = "/api/rb/auth/sign-up";
4
+ const requestSchema = object({
5
+ email_or_phone: string().nonempty("Email or phone number is required").refine(
6
+ (value) => {
7
+ const isEmail = string().email().safeParse(value).success;
8
+ const isPhone = isValidNumber(value);
9
+ return isEmail || isPhone;
10
+ },
11
+ "Please enter a valid email address or phone number"
12
+ ),
13
+ password: string().min(8, { message: "Password must be at least 8 characters long." }),
14
+ password_confirmation: string().nonempty({ message: "Please confirm your password." })
15
+ }).refine((data) => data.password === data.password_confirmation, {
16
+ message: "Passwords do not match.",
17
+ path: ["password_confirmation"]
18
+ });
19
+ object({
20
+ success: boolean()
21
+ });
22
+ export {
23
+ Route as R,
24
+ requestSchema as r
25
+ };
@@ -0,0 +1,21 @@
1
+ import { i as isValidNumber } from "./isValidNumber-6pMDGLRn.js";
2
+ import { o as object, b as boolean, s as string } from "./schemas-DKK0lkQz.js";
3
+ const Route = "/api/rb/auth/sign-in";
4
+ const requestSchema = object({
5
+ email_or_phone: string().nonempty("Email or phone number is required").default("").refine(
6
+ (value) => {
7
+ const isEmail = string().email().safeParse(value).success;
8
+ const isPhone = isValidNumber(value);
9
+ return isEmail || isPhone;
10
+ },
11
+ "Please enter a valid email address or phone number"
12
+ ),
13
+ remember_me: boolean().default(true)
14
+ });
15
+ object({
16
+ success: boolean()
17
+ });
18
+ export {
19
+ Route as R,
20
+ requestSchema as r
21
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * from './components';
2
- export * from './routes';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
package/dist/index.js CHANGED
@@ -1,10 +1,178 @@
1
- import { d, A, E, f, S, e, g } from "./index-DGbE-dXC.js";
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
+ import { useLocation, Link } from "@rpcbase/router";
3
+ import clsx from "clsx";
4
+ import { useFormContext, useForm, zodResolver, FormProvider } from "@rpcbase/form";
5
+ import { useEffect } from "react";
6
+ import { r as requestSchema } from "./index-BphnyggH.js";
7
+ import { r as requestSchema$1 } from "./index-BYEYCL3Q.js";
8
+ const LINKS_REDIRECTION_MAP = {
9
+ "/auth/sign-in": {
10
+ "title": "Sign Up",
11
+ "location": "/auth/sign-up"
12
+ },
13
+ "/auth/sign-up": {
14
+ "title": "Sign In",
15
+ "location": "/auth/sign-in"
16
+ },
17
+ "/auth/forgot-password": {
18
+ "title": "Sign In",
19
+ "location": "/auth/sign-in"
20
+ },
21
+ "/auth/logout-success": {
22
+ "title": "Sign In",
23
+ "location": "/auth/sign-in"
24
+ }
25
+ };
26
+ const AuthLayout = ({
27
+ sidePanel = null,
28
+ children
29
+ }) => {
30
+ const location = useLocation();
31
+ const linkTitle = LINKS_REDIRECTION_MAP[location.pathname]?.title;
32
+ const linkLocation = LINKS_REDIRECTION_MAP[location.pathname]?.location;
33
+ return /* @__PURE__ */ jsxs("div", { className: "container relative hidden h-dvh flex-col items-center justify-center md:grid md:w-full lg:max-w-none lg:grid-cols-2 lg:px-0", children: [
34
+ /* @__PURE__ */ jsx(
35
+ Link,
36
+ {
37
+ className: "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 hover:bg-accent hover:text-accent-foreground h-9 px-4 py-2 absolute right-4 top-4 md:right-8 md:top-8",
38
+ to: linkLocation,
39
+ children: linkTitle
40
+ }
41
+ ),
42
+ /* @__PURE__ */ jsx("div", { className: "relative hidden h-full flex-col bg-muted p-10 text-white dark:border-r lg:flex", children: sidePanel }),
43
+ /* @__PURE__ */ jsx("div", { className: "mx-auto flex w-full flex-col justify-center gap-6 /*sm:w-[350px]*/", children })
44
+ ] });
45
+ };
46
+ const AppleSignInButton = ({
47
+ onPress,
48
+ className
49
+ }) => {
50
+ return /* @__PURE__ */ jsxs(
51
+ "button",
52
+ {
53
+ onClick: onPress,
54
+ className: clsx(`
55
+ w-full
56
+ bg-black text-white hover:bg-gray-800
57
+ flex items-center justify-center
58
+ px-6 py-2
59
+ rounded-lg
60
+ font-medium
61
+ transition duration-150 ease-in-out
62
+ focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black
63
+ `, className),
64
+ children: [
65
+ /* @__PURE__ */ jsx(
66
+ "svg",
67
+ {
68
+ className: "w-5 h-5 mr-3",
69
+ xmlns: "http://www.w3.org/2000/svg",
70
+ viewBox: "0 0 24 24",
71
+ fill: "white",
72
+ children: /* @__PURE__ */ jsx("path", { d: "M12.152 6.896c-.948 0-2.415-1.078-3.96-1.04-2.04.027-3.91 1.183-4.961 3.014-2.117 3.675-.539 9.103 1.519 12.09 1.013 1.454 2.208 3.09 3.792 3.039 1.52-.065 2.09-.987 3.935-.987 1.831 0 2.35.987 3.96.948 1.637-.026 2.676-1.48 3.676-2.948 1.156-1.688 1.636-3.325 1.662-3.415-.039-.013-3.182-1.221-3.22-4.857-.026-3.04 2.48-4.494 2.597-4.559-1.429-2.09-3.623-2.324-4.39-2.376-2-.156-3.675 1.09-4.61 1.09zM15.53 3.83c.843-1.012 1.4-2.427 1.245-3.83-1.207.052-2.662.805-3.532 1.818-.78.896-1.454 2.338-1.273 3.714 1.338.104 2.715-.688 3.559-1.701" })
73
+ }
74
+ ),
75
+ /* @__PURE__ */ jsx("span", { children: "Continue with Apple" })
76
+ ]
77
+ }
78
+ );
79
+ };
80
+ const EmailOrPhoneInput = ({
81
+ id,
82
+ className,
83
+ placeholder
84
+ }) => {
85
+ const { register, formState } = useFormContext();
86
+ const error = formState.errors.email_or_phone;
87
+ let errorMessage;
88
+ if (typeof error === "string") {
89
+ errorMessage = error;
90
+ } else if (error && typeof error.message === "string") {
91
+ errorMessage = error.message;
92
+ }
93
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
94
+ /* @__PURE__ */ jsx(
95
+ "input",
96
+ {
97
+ id,
98
+ type: "text",
99
+ required: true,
100
+ autoComplete: "on",
101
+ className,
102
+ placeholder,
103
+ ...register("email_or_phone")
104
+ }
105
+ ),
106
+ errorMessage ? /* @__PURE__ */ jsx("p", { className: "mt-1 -mb-2 text-sm/6 text-red-500", children: errorMessage }) : null
107
+ ] });
108
+ };
109
+ const SignInForm = ({
110
+ children,
111
+ className
112
+ }) => {
113
+ const methods = useForm({
114
+ defaultValues: {
115
+ email_or_phone: "",
116
+ remember_me: true
117
+ },
118
+ resolver: zodResolver(requestSchema)
119
+ });
120
+ const onSubmit = async (data) => {
121
+ console.log("SUBMIT SIGNIN", data);
122
+ };
123
+ useEffect(() => {
124
+ console.log(methods.formState.errors);
125
+ }, [methods.formState.errors]);
126
+ return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsx("form", { method: "post", noValidate: true, className, onSubmit: methods.handleSubmit(onSubmit), children }) });
127
+ };
128
+ const SignUpForm = ({
129
+ children,
130
+ className
131
+ }) => {
132
+ const methods = useForm({
133
+ defaultValues: {
134
+ email_or_phone: "",
135
+ password: "",
136
+ password_confirmation: ""
137
+ },
138
+ resolver: zodResolver(requestSchema$1)
139
+ });
140
+ const onSubmit = async (data) => {
141
+ console.log("SUBMIT SIGNUp", data);
142
+ };
143
+ useEffect(() => {
144
+ console.log(methods.formState.errors);
145
+ }, [methods.formState.errors]);
146
+ return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsx("form", { method: "post", noValidate: true, className, onSubmit: methods.handleSubmit(onSubmit), children }) });
147
+ };
148
+ const RememberMeCheckbox = ({
149
+ label,
150
+ as: Component = "input"
151
+ }) => {
152
+ const { register } = useFormContext();
153
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
154
+ /* @__PURE__ */ jsx(
155
+ Component,
156
+ {
157
+ id: "remember_me",
158
+ ...register("remember_me")
159
+ }
160
+ ),
161
+ /* @__PURE__ */ jsx(
162
+ "label",
163
+ {
164
+ htmlFor: "remember_me",
165
+ className: "pl-2 block text-sm/6 text-gray-900",
166
+ children: label
167
+ }
168
+ )
169
+ ] });
170
+ };
2
171
  export {
3
- d as AppleSignInButton,
4
- A as AuthLayout,
5
- E as EmailOrPhoneInput,
6
- f as RememberMeCheckbox,
7
- S as SignInForm,
8
- e as SignUpForm,
9
- g as routes
172
+ AppleSignInButton,
173
+ AuthLayout,
174
+ EmailOrPhoneInput,
175
+ RememberMeCheckbox,
176
+ SignInForm,
177
+ SignUpForm
10
178
  };