@wordrhyme/shadcn-auth 1.0.60
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/LICENSE +21 -0
- package/README.md +3 -0
- package/dist/AuthForms.cjs +47 -0
- package/dist/AuthForms.d.cts +23 -0
- package/dist/AuthForms.d.ts +23 -0
- package/dist/AuthForms.js +44 -0
- package/dist/GoogleSignIn.cjs +46 -0
- package/dist/GoogleSignIn.d.cts +10 -0
- package/dist/GoogleSignIn.d.ts +10 -0
- package/dist/GoogleSignIn.js +42 -0
- package/dist/ResetPasswordForm.cjs +106 -0
- package/dist/ResetPasswordForm.d.cts +17 -0
- package/dist/ResetPasswordForm.d.ts +17 -0
- package/dist/ResetPasswordForm.js +100 -0
- package/dist/SignInForm.cjs +164 -0
- package/dist/SignInForm.d.cts +21 -0
- package/dist/SignInForm.d.ts +21 -0
- package/dist/SignInForm.js +159 -0
- package/dist/SignUpForm.cjs +154 -0
- package/dist/SignUpForm.d.cts +19 -0
- package/dist/SignUpForm.d.ts +19 -0
- package/dist/SignUpForm.js +149 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/index.cjs +11 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +7 -0
- package/package.json +69 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
5
|
+
const require_GoogleSignIn = require('./GoogleSignIn.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
8
|
+
let __wordrhyme_shadcn = require("@wordrhyme/shadcn");
|
|
9
|
+
__wordrhyme_shadcn = require_rolldown_runtime.__toESM(__wordrhyme_shadcn);
|
|
10
|
+
let lucide_react = require("lucide-react");
|
|
11
|
+
lucide_react = require_rolldown_runtime.__toESM(lucide_react);
|
|
12
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
13
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
14
|
+
|
|
15
|
+
//#region src/SignInForm.tsx
|
|
16
|
+
const MIN_PASSWORD_LENGTH = 6;
|
|
17
|
+
function SignInForm({ onSignIn, onGoogleSignIn, isLoading, error, onSwitchToSignUp, onSwitchToReset }) {
|
|
18
|
+
const [email, setEmail] = (0, react.useState)("");
|
|
19
|
+
const [password, setPassword] = (0, react.useState)("");
|
|
20
|
+
const [emailError, setEmailError] = (0, react.useState)("");
|
|
21
|
+
const [passwordError, setPasswordError] = (0, react.useState)("");
|
|
22
|
+
const validateEmail = (emailValue) => {
|
|
23
|
+
if (!emailValue.trim()) {
|
|
24
|
+
setEmailError("Email is required");
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const input = document.createElement("input");
|
|
28
|
+
input.type = "email";
|
|
29
|
+
input.value = emailValue;
|
|
30
|
+
if (!input.validity.valid) {
|
|
31
|
+
setEmailError("Please enter a valid email address");
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
setEmailError("");
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
37
|
+
const validatePassword = (passwordValue) => {
|
|
38
|
+
if (!passwordValue.trim()) {
|
|
39
|
+
setPasswordError("Password is required");
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (passwordValue.length < MIN_PASSWORD_LENGTH) {
|
|
43
|
+
setPasswordError(`Password must be at least ${MIN_PASSWORD_LENGTH} characters long`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
setPasswordError("");
|
|
47
|
+
return true;
|
|
48
|
+
};
|
|
49
|
+
const handleSubmit = (e) => {
|
|
50
|
+
e.preventDefault();
|
|
51
|
+
if (!validateEmail(email)) return;
|
|
52
|
+
if (!validatePassword(password)) return;
|
|
53
|
+
onSignIn(email, password).catch(console.error);
|
|
54
|
+
};
|
|
55
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Card, {
|
|
56
|
+
className: "mx-auto w-full max-w-md",
|
|
57
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.CardContent, {
|
|
58
|
+
className: "p-6",
|
|
59
|
+
children: [
|
|
60
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
61
|
+
className: "mb-4 text-center text-2xl font-bold",
|
|
62
|
+
children: "Sign In"
|
|
63
|
+
}),
|
|
64
|
+
error != null && error.trim() !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Alert, {
|
|
65
|
+
variant: "destructive",
|
|
66
|
+
className: "mb-4",
|
|
67
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.AlertDescription, { children: error })
|
|
68
|
+
}),
|
|
69
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
|
|
70
|
+
onSubmit: handleSubmit,
|
|
71
|
+
className: "space-y-4",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
74
|
+
className: "space-y-2",
|
|
75
|
+
children: [
|
|
76
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Label, {
|
|
77
|
+
htmlFor: "email",
|
|
78
|
+
children: "Email"
|
|
79
|
+
}),
|
|
80
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
|
|
81
|
+
id: "email",
|
|
82
|
+
type: "email",
|
|
83
|
+
value: email,
|
|
84
|
+
onChange: (e) => {
|
|
85
|
+
setEmail(e.target.value);
|
|
86
|
+
if (emailError) setEmailError("");
|
|
87
|
+
},
|
|
88
|
+
disabled: isLoading,
|
|
89
|
+
required: true,
|
|
90
|
+
className: emailError ? "border-destructive" : ""
|
|
91
|
+
}),
|
|
92
|
+
emailError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
93
|
+
className: "text-destructive text-sm",
|
|
94
|
+
children: emailError
|
|
95
|
+
})
|
|
96
|
+
]
|
|
97
|
+
}),
|
|
98
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
99
|
+
className: "space-y-2",
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Label, {
|
|
102
|
+
htmlFor: "password",
|
|
103
|
+
children: "Password"
|
|
104
|
+
}),
|
|
105
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
|
|
106
|
+
id: "password",
|
|
107
|
+
type: "password",
|
|
108
|
+
value: password,
|
|
109
|
+
onChange: (e) => {
|
|
110
|
+
setPassword(e.target.value);
|
|
111
|
+
if (passwordError) setPasswordError("");
|
|
112
|
+
},
|
|
113
|
+
disabled: isLoading,
|
|
114
|
+
required: true,
|
|
115
|
+
className: passwordError ? "border-destructive" : ""
|
|
116
|
+
}),
|
|
117
|
+
passwordError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
118
|
+
className: "text-destructive text-sm",
|
|
119
|
+
children: passwordError
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}),
|
|
123
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.Button, {
|
|
124
|
+
type: "submit",
|
|
125
|
+
className: "mt-6 w-full",
|
|
126
|
+
disabled: isLoading,
|
|
127
|
+
children: [isLoading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), isLoading ? "Signing In..." : "Sign In"]
|
|
128
|
+
})
|
|
129
|
+
]
|
|
130
|
+
}),
|
|
131
|
+
onGoogleSignIn != null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.OrContinueWithSeparator, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_GoogleSignIn.GoogleSignIn, {
|
|
132
|
+
onGoogleSignIn,
|
|
133
|
+
isLoading
|
|
134
|
+
})] }),
|
|
135
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Separator, { className: "my-4" }),
|
|
136
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
137
|
+
className: "space-y-2 text-center text-sm",
|
|
138
|
+
children: [onSwitchToSignUp && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [
|
|
139
|
+
"Don't have an account?",
|
|
140
|
+
" ",
|
|
141
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
142
|
+
variant: "link",
|
|
143
|
+
size: "sm",
|
|
144
|
+
onClick: onSwitchToSignUp,
|
|
145
|
+
disabled: isLoading,
|
|
146
|
+
className: "h-auto p-0",
|
|
147
|
+
children: "Sign up"
|
|
148
|
+
})
|
|
149
|
+
] }), onSwitchToReset && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
150
|
+
variant: "link",
|
|
151
|
+
size: "sm",
|
|
152
|
+
onClick: onSwitchToReset,
|
|
153
|
+
disabled: isLoading,
|
|
154
|
+
className: "h-auto p-0",
|
|
155
|
+
children: "Forgot your password?"
|
|
156
|
+
}) })]
|
|
157
|
+
})
|
|
158
|
+
]
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
//#endregion
|
|
164
|
+
exports.SignInForm = SignInForm;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/SignInForm.d.ts
|
|
4
|
+
interface SignInFormProps {
|
|
5
|
+
onSignIn: (email: string, password: string) => Promise<void>;
|
|
6
|
+
onGoogleSignIn?: () => Promise<void>;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
onSwitchToSignUp?: () => void;
|
|
10
|
+
onSwitchToReset?: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare function SignInForm({
|
|
13
|
+
onSignIn,
|
|
14
|
+
onGoogleSignIn,
|
|
15
|
+
isLoading,
|
|
16
|
+
error,
|
|
17
|
+
onSwitchToSignUp,
|
|
18
|
+
onSwitchToReset
|
|
19
|
+
}: SignInFormProps): react_jsx_runtime1.JSX.Element;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SignInForm };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/SignInForm.d.ts
|
|
4
|
+
interface SignInFormProps {
|
|
5
|
+
onSignIn: (email: string, password: string) => Promise<void>;
|
|
6
|
+
onGoogleSignIn?: () => Promise<void>;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
onSwitchToSignUp?: () => void;
|
|
10
|
+
onSwitchToReset?: () => void;
|
|
11
|
+
}
|
|
12
|
+
declare function SignInForm({
|
|
13
|
+
onSignIn,
|
|
14
|
+
onGoogleSignIn,
|
|
15
|
+
isLoading,
|
|
16
|
+
error,
|
|
17
|
+
onSwitchToSignUp,
|
|
18
|
+
onSwitchToReset
|
|
19
|
+
}: SignInFormProps): react_jsx_runtime0.JSX.Element;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SignInForm };
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { GoogleSignIn } from "./GoogleSignIn.js";
|
|
5
|
+
import React, { useState } from "react";
|
|
6
|
+
import { Alert, AlertDescription, Button, Card, CardContent, Input, Label, OrContinueWithSeparator, Separator } from "@wordrhyme/shadcn";
|
|
7
|
+
import { Loader2 } from "lucide-react";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
//#region src/SignInForm.tsx
|
|
11
|
+
const MIN_PASSWORD_LENGTH = 6;
|
|
12
|
+
function SignInForm({ onSignIn, onGoogleSignIn, isLoading, error, onSwitchToSignUp, onSwitchToReset }) {
|
|
13
|
+
const [email, setEmail] = useState("");
|
|
14
|
+
const [password, setPassword] = useState("");
|
|
15
|
+
const [emailError, setEmailError] = useState("");
|
|
16
|
+
const [passwordError, setPasswordError] = useState("");
|
|
17
|
+
const validateEmail = (emailValue) => {
|
|
18
|
+
if (!emailValue.trim()) {
|
|
19
|
+
setEmailError("Email is required");
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
const input = document.createElement("input");
|
|
23
|
+
input.type = "email";
|
|
24
|
+
input.value = emailValue;
|
|
25
|
+
if (!input.validity.valid) {
|
|
26
|
+
setEmailError("Please enter a valid email address");
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
setEmailError("");
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
32
|
+
const validatePassword = (passwordValue) => {
|
|
33
|
+
if (!passwordValue.trim()) {
|
|
34
|
+
setPasswordError("Password is required");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (passwordValue.length < MIN_PASSWORD_LENGTH) {
|
|
38
|
+
setPasswordError(`Password must be at least ${MIN_PASSWORD_LENGTH} characters long`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
setPasswordError("");
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
44
|
+
const handleSubmit = (e) => {
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
if (!validateEmail(email)) return;
|
|
47
|
+
if (!validatePassword(password)) return;
|
|
48
|
+
onSignIn(email, password).catch(console.error);
|
|
49
|
+
};
|
|
50
|
+
return /* @__PURE__ */ jsx(Card, {
|
|
51
|
+
className: "mx-auto w-full max-w-md",
|
|
52
|
+
children: /* @__PURE__ */ jsxs(CardContent, {
|
|
53
|
+
className: "p-6",
|
|
54
|
+
children: [
|
|
55
|
+
/* @__PURE__ */ jsx("h2", {
|
|
56
|
+
className: "mb-4 text-center text-2xl font-bold",
|
|
57
|
+
children: "Sign In"
|
|
58
|
+
}),
|
|
59
|
+
error != null && error.trim() !== "" && /* @__PURE__ */ jsx(Alert, {
|
|
60
|
+
variant: "destructive",
|
|
61
|
+
className: "mb-4",
|
|
62
|
+
children: /* @__PURE__ */ jsx(AlertDescription, { children: error })
|
|
63
|
+
}),
|
|
64
|
+
/* @__PURE__ */ jsxs("form", {
|
|
65
|
+
onSubmit: handleSubmit,
|
|
66
|
+
className: "space-y-4",
|
|
67
|
+
children: [
|
|
68
|
+
/* @__PURE__ */ jsxs("div", {
|
|
69
|
+
className: "space-y-2",
|
|
70
|
+
children: [
|
|
71
|
+
/* @__PURE__ */ jsx(Label, {
|
|
72
|
+
htmlFor: "email",
|
|
73
|
+
children: "Email"
|
|
74
|
+
}),
|
|
75
|
+
/* @__PURE__ */ jsx(Input, {
|
|
76
|
+
id: "email",
|
|
77
|
+
type: "email",
|
|
78
|
+
value: email,
|
|
79
|
+
onChange: (e) => {
|
|
80
|
+
setEmail(e.target.value);
|
|
81
|
+
if (emailError) setEmailError("");
|
|
82
|
+
},
|
|
83
|
+
disabled: isLoading,
|
|
84
|
+
required: true,
|
|
85
|
+
className: emailError ? "border-destructive" : ""
|
|
86
|
+
}),
|
|
87
|
+
emailError && /* @__PURE__ */ jsx("p", {
|
|
88
|
+
className: "text-destructive text-sm",
|
|
89
|
+
children: emailError
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
}),
|
|
93
|
+
/* @__PURE__ */ jsxs("div", {
|
|
94
|
+
className: "space-y-2",
|
|
95
|
+
children: [
|
|
96
|
+
/* @__PURE__ */ jsx(Label, {
|
|
97
|
+
htmlFor: "password",
|
|
98
|
+
children: "Password"
|
|
99
|
+
}),
|
|
100
|
+
/* @__PURE__ */ jsx(Input, {
|
|
101
|
+
id: "password",
|
|
102
|
+
type: "password",
|
|
103
|
+
value: password,
|
|
104
|
+
onChange: (e) => {
|
|
105
|
+
setPassword(e.target.value);
|
|
106
|
+
if (passwordError) setPasswordError("");
|
|
107
|
+
},
|
|
108
|
+
disabled: isLoading,
|
|
109
|
+
required: true,
|
|
110
|
+
className: passwordError ? "border-destructive" : ""
|
|
111
|
+
}),
|
|
112
|
+
passwordError && /* @__PURE__ */ jsx("p", {
|
|
113
|
+
className: "text-destructive text-sm",
|
|
114
|
+
children: passwordError
|
|
115
|
+
})
|
|
116
|
+
]
|
|
117
|
+
}),
|
|
118
|
+
/* @__PURE__ */ jsxs(Button, {
|
|
119
|
+
type: "submit",
|
|
120
|
+
className: "mt-6 w-full",
|
|
121
|
+
disabled: isLoading,
|
|
122
|
+
children: [isLoading && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), isLoading ? "Signing In..." : "Sign In"]
|
|
123
|
+
})
|
|
124
|
+
]
|
|
125
|
+
}),
|
|
126
|
+
onGoogleSignIn != null && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(OrContinueWithSeparator, {}), /* @__PURE__ */ jsx(GoogleSignIn, {
|
|
127
|
+
onGoogleSignIn,
|
|
128
|
+
isLoading
|
|
129
|
+
})] }),
|
|
130
|
+
/* @__PURE__ */ jsx(Separator, { className: "my-4" }),
|
|
131
|
+
/* @__PURE__ */ jsxs("div", {
|
|
132
|
+
className: "space-y-2 text-center text-sm",
|
|
133
|
+
children: [onSwitchToSignUp && /* @__PURE__ */ jsxs("p", { children: [
|
|
134
|
+
"Don't have an account?",
|
|
135
|
+
" ",
|
|
136
|
+
/* @__PURE__ */ jsx(Button, {
|
|
137
|
+
variant: "link",
|
|
138
|
+
size: "sm",
|
|
139
|
+
onClick: onSwitchToSignUp,
|
|
140
|
+
disabled: isLoading,
|
|
141
|
+
className: "h-auto p-0",
|
|
142
|
+
children: "Sign up"
|
|
143
|
+
})
|
|
144
|
+
] }), onSwitchToReset && /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(Button, {
|
|
145
|
+
variant: "link",
|
|
146
|
+
size: "sm",
|
|
147
|
+
onClick: onSwitchToReset,
|
|
148
|
+
disabled: isLoading,
|
|
149
|
+
className: "h-auto p-0",
|
|
150
|
+
children: "Forgot your password?"
|
|
151
|
+
}) })]
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
})
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
export { SignInForm };
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_GoogleSignIn = require('./GoogleSignIn.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
react = require_rolldown_runtime.__toESM(react);
|
|
5
|
+
let __wordrhyme_shadcn = require("@wordrhyme/shadcn");
|
|
6
|
+
__wordrhyme_shadcn = require_rolldown_runtime.__toESM(__wordrhyme_shadcn);
|
|
7
|
+
let lucide_react = require("lucide-react");
|
|
8
|
+
lucide_react = require_rolldown_runtime.__toESM(lucide_react);
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
|
|
11
|
+
|
|
12
|
+
//#region src/SignUpForm.tsx
|
|
13
|
+
const MIN_PASSWORD_LENGTH = 6;
|
|
14
|
+
function SignUpForm({ onSignUp, onGoogleSignIn, isLoading, error, onSwitchToSignIn }) {
|
|
15
|
+
const [email, setEmail] = (0, react.useState)("");
|
|
16
|
+
const [password, setPassword] = (0, react.useState)("");
|
|
17
|
+
const [emailError, setEmailError] = (0, react.useState)("");
|
|
18
|
+
const [passwordError, setPasswordError] = (0, react.useState)("");
|
|
19
|
+
const validateEmail = (emailValue) => {
|
|
20
|
+
if (!emailValue.trim()) {
|
|
21
|
+
setEmailError("Email is required");
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const input = document.createElement("input");
|
|
25
|
+
input.type = "email";
|
|
26
|
+
input.value = emailValue;
|
|
27
|
+
if (!input.validity.valid) {
|
|
28
|
+
setEmailError("Please enter a valid email address");
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
setEmailError("");
|
|
32
|
+
return true;
|
|
33
|
+
};
|
|
34
|
+
const validatePassword = (passwordValue) => {
|
|
35
|
+
if (!passwordValue.trim()) {
|
|
36
|
+
setPasswordError("Password is required");
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (passwordValue.length < MIN_PASSWORD_LENGTH) {
|
|
40
|
+
setPasswordError(`Password must be at least ${MIN_PASSWORD_LENGTH} characters long`);
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
setPasswordError("");
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
const handleSubmit = (e) => {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
if (!validateEmail(email)) return;
|
|
49
|
+
if (!validatePassword(password)) return;
|
|
50
|
+
onSignUp(email, password).catch(console.error);
|
|
51
|
+
};
|
|
52
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Card, {
|
|
53
|
+
className: "mx-auto w-full max-w-md",
|
|
54
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.CardContent, {
|
|
55
|
+
className: "p-6",
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
|
|
58
|
+
className: "mb-4 text-center text-2xl font-bold",
|
|
59
|
+
children: "Sign Up"
|
|
60
|
+
}),
|
|
61
|
+
error != null && error.trim() !== "" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Alert, {
|
|
62
|
+
variant: "destructive",
|
|
63
|
+
className: "mb-4",
|
|
64
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.AlertDescription, { children: error })
|
|
65
|
+
}),
|
|
66
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
|
|
67
|
+
onSubmit: handleSubmit,
|
|
68
|
+
className: "space-y-4",
|
|
69
|
+
children: [
|
|
70
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
71
|
+
className: "space-y-2",
|
|
72
|
+
children: [
|
|
73
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Label, {
|
|
74
|
+
htmlFor: "email",
|
|
75
|
+
children: "Email"
|
|
76
|
+
}),
|
|
77
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
|
|
78
|
+
id: "email",
|
|
79
|
+
type: "email",
|
|
80
|
+
value: email,
|
|
81
|
+
onChange: (e) => {
|
|
82
|
+
setEmail(e.target.value);
|
|
83
|
+
if (emailError) setEmailError("");
|
|
84
|
+
},
|
|
85
|
+
disabled: isLoading,
|
|
86
|
+
required: true,
|
|
87
|
+
className: emailError ? "border-destructive" : ""
|
|
88
|
+
}),
|
|
89
|
+
emailError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
90
|
+
className: "text-destructive text-sm",
|
|
91
|
+
children: emailError
|
|
92
|
+
})
|
|
93
|
+
]
|
|
94
|
+
}),
|
|
95
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
96
|
+
className: "space-y-2",
|
|
97
|
+
children: [
|
|
98
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Label, {
|
|
99
|
+
htmlFor: "password",
|
|
100
|
+
children: "Password"
|
|
101
|
+
}),
|
|
102
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Input, {
|
|
103
|
+
id: "password",
|
|
104
|
+
type: "password",
|
|
105
|
+
value: password,
|
|
106
|
+
onChange: (e) => {
|
|
107
|
+
setPassword(e.target.value);
|
|
108
|
+
if (passwordError) setPasswordError("");
|
|
109
|
+
},
|
|
110
|
+
disabled: isLoading,
|
|
111
|
+
required: true,
|
|
112
|
+
className: passwordError ? "border-destructive" : ""
|
|
113
|
+
}),
|
|
114
|
+
passwordError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
115
|
+
className: "text-destructive text-sm",
|
|
116
|
+
children: passwordError
|
|
117
|
+
})
|
|
118
|
+
]
|
|
119
|
+
}),
|
|
120
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(__wordrhyme_shadcn.Button, {
|
|
121
|
+
type: "submit",
|
|
122
|
+
className: "mt-6 w-full",
|
|
123
|
+
disabled: isLoading,
|
|
124
|
+
children: [isLoading && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Loader2, { className: "mr-2 h-4 w-4 animate-spin" }), isLoading ? "Signing Up..." : "Sign Up"]
|
|
125
|
+
})
|
|
126
|
+
]
|
|
127
|
+
}),
|
|
128
|
+
onGoogleSignIn != null && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.OrContinueWithSeparator, {}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_GoogleSignIn.GoogleSignIn, {
|
|
129
|
+
onGoogleSignIn,
|
|
130
|
+
isLoading
|
|
131
|
+
})] }),
|
|
132
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Separator, { className: "my-4" }),
|
|
133
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
134
|
+
className: "text-center text-sm",
|
|
135
|
+
children: onSwitchToSignIn && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", { children: [
|
|
136
|
+
"Already have an account?",
|
|
137
|
+
" ",
|
|
138
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(__wordrhyme_shadcn.Button, {
|
|
139
|
+
variant: "link",
|
|
140
|
+
size: "sm",
|
|
141
|
+
onClick: onSwitchToSignIn,
|
|
142
|
+
disabled: isLoading,
|
|
143
|
+
className: "h-auto p-0",
|
|
144
|
+
children: "Sign in"
|
|
145
|
+
})
|
|
146
|
+
] })
|
|
147
|
+
})
|
|
148
|
+
]
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
//#endregion
|
|
154
|
+
exports.SignUpForm = SignUpForm;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/SignUpForm.d.ts
|
|
4
|
+
interface SignUpFormProps {
|
|
5
|
+
onSignUp: (email: string, password: string) => Promise<void>;
|
|
6
|
+
onGoogleSignIn?: () => Promise<void>;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
onSwitchToSignIn?: () => void;
|
|
10
|
+
}
|
|
11
|
+
declare function SignUpForm({
|
|
12
|
+
onSignUp,
|
|
13
|
+
onGoogleSignIn,
|
|
14
|
+
isLoading,
|
|
15
|
+
error,
|
|
16
|
+
onSwitchToSignIn
|
|
17
|
+
}: SignUpFormProps): react_jsx_runtime0.JSX.Element;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { SignUpForm };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
+
|
|
3
|
+
//#region src/SignUpForm.d.ts
|
|
4
|
+
interface SignUpFormProps {
|
|
5
|
+
onSignUp: (email: string, password: string) => Promise<void>;
|
|
6
|
+
onGoogleSignIn?: () => Promise<void>;
|
|
7
|
+
isLoading: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
onSwitchToSignIn?: () => void;
|
|
10
|
+
}
|
|
11
|
+
declare function SignUpForm({
|
|
12
|
+
onSignUp,
|
|
13
|
+
onGoogleSignIn,
|
|
14
|
+
isLoading,
|
|
15
|
+
error,
|
|
16
|
+
onSwitchToSignIn
|
|
17
|
+
}: SignUpFormProps): react_jsx_runtime0.JSX.Element;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { SignUpForm };
|