@insforge/react 0.1.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/index.js ADDED
@@ -0,0 +1,1887 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var sdk = require('@insforge/sdk');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var clsx = require('clsx');
7
+ var tailwindMerge = require('tailwind-merge');
8
+ var lucideReact = require('lucide-react');
9
+ var zod = require('zod');
10
+
11
+ var InsforgeContext = react.createContext(
12
+ void 0
13
+ );
14
+ function InsforgeProvider({
15
+ children,
16
+ baseUrl,
17
+ onAuthChange,
18
+ syncTokenToCookie,
19
+ clearCookie
20
+ }) {
21
+ const [user, setUser] = react.useState(null);
22
+ const [isLoaded, setIsLoaded] = react.useState(false);
23
+ const refreshIntervalRef = react.useRef(null);
24
+ const [insforge] = react.useState(() => sdk.createClient({ baseUrl }));
25
+ const loadAuthState = react.useCallback(async () => {
26
+ try {
27
+ const sessionResult = insforge.auth.getCurrentSession();
28
+ const session = sessionResult.data?.session;
29
+ const token = session?.accessToken || null;
30
+ if (!token) {
31
+ setUser(null);
32
+ if (onAuthChange) {
33
+ onAuthChange(null);
34
+ }
35
+ setIsLoaded(true);
36
+ return { success: false, error: "no_session" };
37
+ }
38
+ const userResult = await insforge.auth.getCurrentUser();
39
+ if (userResult.data) {
40
+ const profile = userResult.data.profile;
41
+ const userData = {
42
+ id: userResult.data.user.id,
43
+ email: userResult.data.user.email,
44
+ name: profile?.nickname || "",
45
+ avatarUrl: profile?.avatarUrl || ""
46
+ };
47
+ setUser(userData);
48
+ if (onAuthChange) {
49
+ onAuthChange(userData);
50
+ }
51
+ setIsLoaded(true);
52
+ return { success: true };
53
+ } else {
54
+ await insforge.auth.signOut();
55
+ if (clearCookie) {
56
+ try {
57
+ await clearCookie();
58
+ } catch (error) {
59
+ }
60
+ }
61
+ setUser(null);
62
+ if (onAuthChange) {
63
+ onAuthChange(null);
64
+ }
65
+ setIsLoaded(true);
66
+ return { success: false, error: "invalid_token" };
67
+ }
68
+ } catch (error) {
69
+ console.error("[InsforgeProvider] Token validation failed:", error);
70
+ await insforge.auth.signOut();
71
+ if (clearCookie) {
72
+ try {
73
+ await clearCookie();
74
+ } catch (error2) {
75
+ }
76
+ }
77
+ setUser(null);
78
+ if (onAuthChange) {
79
+ onAuthChange(null);
80
+ }
81
+ setIsLoaded(true);
82
+ return {
83
+ success: false,
84
+ error: error instanceof Error ? error.message : "authentication_failed"
85
+ };
86
+ }
87
+ }, [insforge, onAuthChange, syncTokenToCookie, clearCookie]);
88
+ react.useEffect(() => {
89
+ loadAuthState();
90
+ return () => {
91
+ if (refreshIntervalRef.current) {
92
+ clearInterval(refreshIntervalRef.current);
93
+ }
94
+ };
95
+ }, []);
96
+ const handleAuthSuccess = react.useCallback(
97
+ async (authToken, fallbackUser) => {
98
+ const userResult = await insforge.auth.getCurrentUser();
99
+ if (userResult.data) {
100
+ const profile = userResult.data.profile;
101
+ const userData = {
102
+ id: userResult.data.user.id,
103
+ email: userResult.data.user.email,
104
+ name: profile?.nickname || "",
105
+ avatarUrl: profile?.avatarUrl || ""
106
+ };
107
+ setUser(userData);
108
+ if (onAuthChange) {
109
+ onAuthChange(userData);
110
+ }
111
+ if (syncTokenToCookie) {
112
+ try {
113
+ await syncTokenToCookie(authToken);
114
+ } catch (error) {
115
+ }
116
+ }
117
+ } else if (fallbackUser) {
118
+ const userData = {
119
+ id: fallbackUser.id || "",
120
+ email: fallbackUser.email || "",
121
+ name: fallbackUser.name || "",
122
+ avatarUrl: ""
123
+ };
124
+ setUser(userData);
125
+ if (onAuthChange) {
126
+ onAuthChange(userData);
127
+ }
128
+ }
129
+ },
130
+ [insforge, onAuthChange, syncTokenToCookie]
131
+ );
132
+ const signIn = react.useCallback(
133
+ async (email, password) => {
134
+ const sdkResult = await insforge.auth.signInWithPassword({
135
+ email,
136
+ password
137
+ });
138
+ if (sdkResult.data) {
139
+ await handleAuthSuccess(
140
+ sdkResult.data.accessToken || "",
141
+ sdkResult.data.user ? {
142
+ id: sdkResult.data.user.id,
143
+ email: sdkResult.data.user.email,
144
+ name: sdkResult.data.user.name
145
+ } : void 0
146
+ );
147
+ return sdkResult.data;
148
+ } else {
149
+ const errorMessage = sdkResult.error?.message || "Invalid email or password";
150
+ return { error: errorMessage };
151
+ }
152
+ },
153
+ [insforge, handleAuthSuccess]
154
+ );
155
+ const signUp = react.useCallback(
156
+ async (email, password) => {
157
+ const sdkResult = await insforge.auth.signUp({ email, password });
158
+ if (sdkResult.data) {
159
+ await handleAuthSuccess(
160
+ sdkResult.data.accessToken || "",
161
+ sdkResult.data.user ? {
162
+ id: sdkResult.data.user.id,
163
+ email: sdkResult.data.user.email,
164
+ name: sdkResult.data.user.name
165
+ } : void 0
166
+ );
167
+ return sdkResult.data;
168
+ } else {
169
+ const errorMessage = sdkResult.error?.message || "Sign up failed";
170
+ return { error: errorMessage };
171
+ }
172
+ },
173
+ [insforge, handleAuthSuccess]
174
+ );
175
+ const signOut = react.useCallback(async () => {
176
+ await insforge.auth.signOut();
177
+ if (clearCookie) {
178
+ try {
179
+ await clearCookie();
180
+ } catch (error) {
181
+ }
182
+ }
183
+ if (refreshIntervalRef.current) {
184
+ clearInterval(refreshIntervalRef.current);
185
+ }
186
+ setUser(null);
187
+ if (onAuthChange) {
188
+ onAuthChange(null);
189
+ }
190
+ }, [insforge, onAuthChange, clearCookie]);
191
+ const updateUser = react.useCallback(
192
+ async (data) => {
193
+ if (!user) throw new Error("No user signed in");
194
+ const profileUpdate = {
195
+ nickname: data.name,
196
+ avatarUrl: data.avatarUrl
197
+ };
198
+ const result = await insforge.auth.setProfile(profileUpdate);
199
+ if (result.data) {
200
+ const userResult = await insforge.auth.getCurrentUser();
201
+ if (userResult.data) {
202
+ const profile = userResult.data.profile;
203
+ const updatedUser = {
204
+ id: userResult.data.user.id,
205
+ email: userResult.data.user.email,
206
+ name: profile?.nickname || "",
207
+ avatarUrl: profile?.avatarUrl || ""
208
+ };
209
+ setUser(updatedUser);
210
+ if (onAuthChange) {
211
+ onAuthChange(updatedUser);
212
+ }
213
+ }
214
+ }
215
+ },
216
+ [user, onAuthChange, insforge]
217
+ );
218
+ const sendPasswordResetCode = react.useCallback(
219
+ async (email) => {
220
+ const sdkResult = await insforge.auth.sendPasswordResetCode({ email });
221
+ return sdkResult.data;
222
+ },
223
+ [insforge]
224
+ );
225
+ const resetPassword = react.useCallback(
226
+ async (token, newPassword) => {
227
+ const sdkResult = await insforge.auth.resetPassword({ newPassword, otp: token });
228
+ return sdkResult.data;
229
+ },
230
+ [insforge]
231
+ );
232
+ const verifyEmail = react.useCallback(
233
+ async (token) => {
234
+ const sdkResult = await insforge.auth.verifyEmail({ otp: token });
235
+ return sdkResult.data;
236
+ },
237
+ [insforge]
238
+ );
239
+ return /* @__PURE__ */ jsxRuntime.jsx(
240
+ InsforgeContext.Provider,
241
+ {
242
+ value: {
243
+ user,
244
+ isLoaded,
245
+ isSignedIn: !!user,
246
+ setUser,
247
+ signIn,
248
+ signUp,
249
+ signOut,
250
+ updateUser,
251
+ reloadAuth: loadAuthState,
252
+ baseUrl,
253
+ sendPasswordResetCode,
254
+ resetPassword,
255
+ verifyEmail
256
+ },
257
+ children
258
+ }
259
+ );
260
+ }
261
+ function useInsforge() {
262
+ const context = react.useContext(InsforgeContext);
263
+ if (!context) {
264
+ throw new Error("useInsforge must be used within InsforgeProvider");
265
+ }
266
+ return context;
267
+ }
268
+ function usePublicAuthConfig() {
269
+ const { baseUrl } = useInsforge();
270
+ const [oauthProviders2, setOAuthProviders] = react.useState([]);
271
+ const [emailConfig, setEmailConfig] = react.useState(null);
272
+ const [isLoaded, setIsLoaded] = react.useState(false);
273
+ react.useEffect(() => {
274
+ let mounted = true;
275
+ async function fetchConfig() {
276
+ try {
277
+ const response = await fetch(`${baseUrl}/api/auth/public-config`);
278
+ if (!mounted) return;
279
+ if (!response.ok) {
280
+ console.warn("[usePublicAuthConfig] Failed to fetch public auth config:", response.statusText);
281
+ setOAuthProviders([]);
282
+ setEmailConfig(null);
283
+ } else {
284
+ const data = await response.json();
285
+ const providerNames = data.oauth?.data?.map((p) => p.provider) || [];
286
+ setOAuthProviders(providerNames);
287
+ setEmailConfig(data.email || null);
288
+ }
289
+ setIsLoaded(true);
290
+ } catch (error) {
291
+ console.warn("[usePublicAuthConfig] Unexpected error:", error);
292
+ if (mounted) {
293
+ setOAuthProviders([]);
294
+ setEmailConfig(null);
295
+ setIsLoaded(true);
296
+ }
297
+ }
298
+ }
299
+ fetchConfig();
300
+ return () => {
301
+ mounted = false;
302
+ };
303
+ }, [baseUrl]);
304
+ return { oauthProviders: oauthProviders2, emailConfig, isLoaded };
305
+ }
306
+ function AuthBranding() {
307
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-[#FAFAFA] px-2 py-4 flex flex-row justify-center items-center gap-1", children: [
308
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-xs font-medium text-black font-manrope", children: "Secured by" }),
309
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: "https://insforge.dev", target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "83", height: "20", viewBox: "0 0 83 20", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
310
+ /* @__PURE__ */ jsxRuntime.jsx(
311
+ "path",
312
+ {
313
+ d: "M2.16783 8.46797C1.9334 8.23325 1.9334 7.85269 2.16783 7.61797L8.11049 1.66797L16.6 1.66797L6.41259 11.868C6.17815 12.1027 5.79807 12.1027 5.56363 11.868L2.16783 8.46797Z",
314
+ fill: "url(#paint0_linear_2976_9475)"
315
+ }
316
+ ),
317
+ /* @__PURE__ */ jsxRuntime.jsx(
318
+ "path",
319
+ {
320
+ d: "M12.8858 6.44922L16.6 10.168V18.668L8.64108 10.6992L12.8858 6.44922Z",
321
+ fill: "url(#paint1_linear_2976_9475)"
322
+ }
323
+ ),
324
+ /* @__PURE__ */ jsxRuntime.jsx(
325
+ "path",
326
+ {
327
+ d: "M67.5439 6.48828C68.2894 6.48828 68.9145 6.67064 69.418 7.03516C69.5229 7.10943 69.6214 7.1907 69.7158 7.27637V6.70703H71.248V14.959C71.248 15.1583 71.2381 15.3485 71.2188 15.5283C71.2042 15.7129 71.1774 15.8925 71.1387 16.0674C71.0225 16.5776 70.7998 16.9957 70.4707 17.3213C70.1415 17.6518 69.7321 17.8972 69.2432 18.0576C68.7592 18.2179 68.2222 18.2988 67.6318 18.2988C67.1962 18.2988 66.7768 18.2308 66.375 18.0947C65.9782 17.9587 65.6202 17.7614 65.3008 17.5039C64.9813 17.2512 64.7199 16.9446 64.5166 16.585L66.1289 15.7832C66.2789 16.0698 66.4888 16.2819 66.7598 16.418C67.0356 16.5589 67.3289 16.6289 67.6387 16.6289C68.0016 16.6289 68.3258 16.5628 68.6113 16.4316C68.8969 16.3053 69.1176 16.116 69.2725 15.8633C69.4321 15.6155 69.5077 15.3047 69.498 14.9307V14.1797C69.4665 14.2037 69.4359 14.229 69.4033 14.252C68.8855 14.6164 68.2441 14.7988 67.4795 14.7988C66.7582 14.7988 66.1281 14.6165 65.5908 14.252C65.0537 13.8875 64.637 13.3915 64.3418 12.7646C64.0467 12.1378 63.8994 11.4307 63.8994 10.6436C63.8994 9.84651 64.0465 9.13673 64.3418 8.51465C64.6419 7.88768 65.0663 7.39481 65.6133 7.03516C66.1601 6.67077 66.8036 6.48836 67.5439 6.48828ZM37.5 6.48828C38.1099 6.48828 38.6496 6.58294 39.1191 6.77246C39.5935 6.96201 39.9762 7.2321 40.2666 7.58203C40.5569 7.93184 40.7359 8.34227 40.8037 8.81348L39.0176 9.13477C38.974 8.79951 38.8218 8.53424 38.5605 8.33984C38.304 8.14547 37.96 8.03605 37.5293 8.01172C37.1178 7.98742 36.7859 8.05051 36.5342 8.20117C36.2825 8.34698 36.1562 8.55398 36.1562 8.82129C36.1563 8.97184 36.208 9.10017 36.3096 9.20703C36.4112 9.31394 36.614 9.42141 36.9189 9.52832C37.2288 9.63524 37.6889 9.76635 38.2988 9.92188C38.9232 10.0823 39.4222 10.2666 39.7949 10.4756C40.1722 10.6796 40.4428 10.9254 40.6074 11.2119C40.7768 11.4987 40.8623 11.8466 40.8623 12.2549C40.8623 13.047 40.574 13.6691 39.998 14.1211C39.4268 14.5731 38.6348 14.7988 37.623 14.7988C36.6551 14.7988 35.8687 14.5799 35.2637 14.1426C34.6587 13.7052 34.2909 13.0908 34.1602 12.2988L35.9463 12.0215C36.0383 12.4102 36.2411 12.7169 36.5557 12.9404C36.8703 13.164 37.2678 13.2754 37.7471 13.2754C38.1681 13.2754 38.4922 13.1926 38.7197 13.0273C38.9521 12.8572 39.0684 12.6266 39.0684 12.335C39.0684 12.1552 39.0245 12.0122 38.9375 11.9053C38.8552 11.7935 38.6713 11.686 38.3857 11.584C38.1001 11.4819 37.6618 11.3528 37.0713 11.1973C36.4131 11.0223 35.8901 10.8359 35.5029 10.6367C35.1158 10.4327 34.8374 10.192 34.668 9.91504C34.4985 9.63801 34.4141 9.30188 34.4141 8.9082C34.4141 8.41746 34.5423 7.98943 34.7988 7.625C35.0553 7.26073 35.4135 6.98146 35.873 6.78711C36.3329 6.58784 36.8755 6.48828 37.5 6.48828ZM53.3047 6.48828C54.0937 6.48828 54.7815 6.66572 55.3672 7.02051C55.9527 7.37528 56.4072 7.86634 56.7314 8.49316C57.0558 9.11525 57.2187 9.83193 57.2188 10.6436C57.2188 11.46 57.0537 12.1817 56.7246 12.8086C56.4003 13.4307 55.9451 13.9196 55.3594 14.2744C54.7737 14.6242 54.0888 14.7988 53.3047 14.7988C52.5205 14.7988 51.8357 14.6214 51.25 14.2666C50.6643 13.9118 50.2091 13.4238 49.8848 12.8018C49.5653 12.1748 49.4053 11.4552 49.4053 10.6436C49.4053 9.81735 49.5703 9.09279 49.8994 8.4707C50.2286 7.8488 50.6859 7.36255 51.2715 7.0127C51.8572 6.66281 52.5351 6.48828 53.3047 6.48828ZM76.7471 6.48828C77.5603 6.48828 78.25 6.68053 78.8164 7.06445C79.3876 7.44351 79.812 7.97991 80.0879 8.6748C80.3638 9.36976 80.4672 10.189 80.3994 11.1318H74.7256C74.7843 11.6972 74.949 12.1516 75.2227 12.4951C75.5711 12.9325 76.0792 13.1513 76.7471 13.1514C77.1779 13.1514 77.5486 13.0567 77.8584 12.8672C78.173 12.6728 78.4146 12.3928 78.584 12.0283L80.3125 12.5537C80.0124 13.2633 79.5473 13.8153 78.918 14.209C78.2936 14.6025 77.6036 14.7988 76.8486 14.7988C76.0549 14.7988 75.358 14.6263 74.7578 14.2812C74.1576 13.9362 73.6875 13.458 73.3486 12.8457C73.0147 12.2334 72.8477 11.5284 72.8477 10.7314C72.8477 9.87126 73.0127 9.12495 73.3418 8.49316C73.671 7.85651 74.1282 7.36263 74.7139 7.0127C75.2995 6.6628 75.9775 6.48832 76.7471 6.48828ZM23.3301 14.5801H21.5801V4.08203H23.3301V14.5801ZM29.6152 6.48047C30.1959 6.48052 30.6753 6.5781 31.0527 6.77246C31.4301 6.96681 31.7305 7.21443 31.9531 7.51562C32.1758 7.81695 32.3398 8.13831 32.4463 8.47852C32.5528 8.81873 32.6213 9.14205 32.6504 9.44824C32.6843 9.74946 32.7012 9.99508 32.7012 10.1846V14.5801H30.9287V10.7891C30.9287 10.5413 30.9118 10.2669 30.8779 9.96582C30.844 9.66449 30.7645 9.37469 30.6387 9.09766C30.5177 8.81592 30.3337 8.58503 30.0869 8.40527C29.8449 8.22551 29.5157 8.13579 29.0996 8.13574C28.8769 8.13574 28.6563 8.17221 28.4385 8.24512C28.2206 8.31802 28.0219 8.4442 27.8428 8.62402C27.6685 8.79899 27.5284 9.04249 27.4219 9.35352C27.3154 9.65965 27.2617 10.0532 27.2617 10.5342V14.5801H25.4902V6.70703H27.0518V7.58301C27.2521 7.34675 27.486 7.14172 27.7559 6.96973C28.2593 6.64409 28.8794 6.48047 29.6152 6.48047ZM48.748 5.83887H44.2021V8.45605H47.876V10.2061H44.2021V14.5801H42.4521V4.08203H48.748V5.83887ZM62.5137 6.67773C62.7606 6.65829 63.001 6.66815 63.2334 6.70703V8.34766C63.001 8.27961 62.7317 8.25695 62.4268 8.28125C62.1267 8.30557 61.8553 8.39134 61.6133 8.53711C61.3715 8.66829 61.1733 8.83606 61.0186 9.04004C60.8686 9.24404 60.7572 9.47701 60.6846 9.73926C60.612 9.99685 60.5752 10.2768 60.5752 10.5781V14.5801H58.8184V6.70703H60.3652V7.96582C60.4243 7.85986 60.4888 7.75824 60.5605 7.66211C60.7251 7.4434 60.9219 7.26302 61.1494 7.12207C61.3429 6.99098 61.5559 6.88926 61.7881 6.81641C62.0251 6.73869 62.267 6.69235 62.5137 6.67773ZM67.8057 8.0625C67.3362 8.06252 66.9485 8.17982 66.6436 8.41309C66.3389 8.64144 66.1139 8.95232 65.9688 9.3457C65.8235 9.7345 65.751 10.1673 65.751 10.6436C65.751 11.1247 65.8215 11.5624 65.9619 11.9561C66.1071 12.3447 66.3269 12.6535 66.6221 12.8818C66.9174 13.1103 67.293 13.2246 67.748 13.2246C68.2174 13.2246 68.5953 13.1171 68.8809 12.9033C69.1711 12.6846 69.3811 12.3808 69.5117 11.9922C69.6473 11.6034 69.7158 11.1539 69.7158 10.6436C69.7158 10.1284 69.6473 9.67886 69.5117 9.29492C69.381 8.90617 69.1753 8.60445 68.8945 8.39062C68.6138 8.17213 68.2508 8.0625 67.8057 8.0625ZM53.3047 8.13574C52.8351 8.13574 52.4475 8.24222 52.1426 8.45605C51.8425 8.66504 51.6198 8.95977 51.4746 9.33887C51.3295 9.71303 51.2568 10.148 51.2568 10.6436C51.2568 11.4066 51.4288 12.0168 51.7725 12.4736C52.121 12.9256 52.6318 13.1514 53.3047 13.1514C54.0017 13.1514 54.5196 12.9177 54.8584 12.4512C55.1971 11.9846 55.3672 11.3822 55.3672 10.6436C55.3672 9.8807 55.1951 9.27324 54.8516 8.82129C54.5079 8.36444 53.9921 8.13575 53.3047 8.13574ZM76.8203 8.02637C76.1039 8.02637 75.5712 8.25013 75.2227 8.69727C74.9987 8.98144 74.8476 9.35094 74.7676 9.80566H78.6221C78.5589 9.29301 78.4236 8.89686 78.2139 8.61719C77.9186 8.22359 77.4543 8.02645 76.8203 8.02637Z",
328
+ fill: "black"
329
+ }
330
+ ),
331
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
332
+ /* @__PURE__ */ jsxRuntime.jsxs(
333
+ "linearGradient",
334
+ {
335
+ id: "paint0_linear_2976_9475",
336
+ x1: "1.85883",
337
+ y1: "1.92425",
338
+ x2: "24.3072",
339
+ y2: "9.64016",
340
+ gradientUnits: "userSpaceOnUse",
341
+ children: [
342
+ /* @__PURE__ */ jsxRuntime.jsx("stop", {}),
343
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopOpacity: "0.4" })
344
+ ]
345
+ }
346
+ ),
347
+ /* @__PURE__ */ jsxRuntime.jsxs(
348
+ "linearGradient",
349
+ {
350
+ id: "paint1_linear_2976_9475",
351
+ x1: "25.6475",
352
+ y1: "8.65468",
353
+ x2: "10.7901",
354
+ y2: "8.65468",
355
+ gradientUnits: "userSpaceOnUse",
356
+ children: [
357
+ /* @__PURE__ */ jsxRuntime.jsx("stop", {}),
358
+ /* @__PURE__ */ jsxRuntime.jsx("stop", { offset: "1", stopOpacity: "0.4" })
359
+ ]
360
+ }
361
+ )
362
+ ] })
363
+ ] }) })
364
+ ] });
365
+ }
366
+ function cn(...inputs) {
367
+ return tailwindMerge.twMerge(clsx.clsx(inputs));
368
+ }
369
+ function AuthContainer({ children, appearance = {} }) {
370
+ return /* @__PURE__ */ jsxRuntime.jsxs(
371
+ "div",
372
+ {
373
+ className: cn(
374
+ "w-full max-w-[400px] rounded-xl overflow-hidden shadow-lg",
375
+ appearance.containerClassName
376
+ ),
377
+ children: [
378
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
379
+ "bg-white p-6 flex flex-col justify-center items-stretch gap-6",
380
+ appearance.cardClassName
381
+ ), children }),
382
+ /* @__PURE__ */ jsxRuntime.jsx(AuthBranding, {})
383
+ ]
384
+ }
385
+ );
386
+ }
387
+ function AuthHeader({
388
+ title,
389
+ subtitle,
390
+ appearance = {}
391
+ }) {
392
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(
393
+ "flex flex-col justify-start items-start gap-2",
394
+ appearance.containerClassName
395
+ ), children: [
396
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: cn(
397
+ "text-2xl font-semibold text-black leading-8",
398
+ appearance.titleClassName
399
+ ), children: title }),
400
+ subtitle && /* @__PURE__ */ jsxRuntime.jsx("p", { className: cn(
401
+ "text-sm font-normal text-[#828282] leading-6",
402
+ appearance.subtitleClassName
403
+ ), children: subtitle })
404
+ ] });
405
+ }
406
+ function AuthErrorBanner({ error, className }) {
407
+ if (!error) return null;
408
+ return /* @__PURE__ */ jsxRuntime.jsxs(
409
+ "div",
410
+ {
411
+ className: cn(
412
+ "flex items-center gap-2 mb-4 pl-3 py-2 pr-2 bg-red-50 border-2 border-red-600 rounded",
413
+ className
414
+ ),
415
+ children: [
416
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.AlertTriangle, { className: "w-6 h-6 text-red-500 flex-shrink-0" }),
417
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm text-red-600 flex-1", children: error })
418
+ ]
419
+ }
420
+ );
421
+ }
422
+ function AuthFormField({
423
+ label,
424
+ id,
425
+ appearance = {},
426
+ ...props
427
+ }) {
428
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(
429
+ "flex flex-col justify-center items-stretch gap-1",
430
+ appearance.containerClassName
431
+ ), children: [
432
+ /* @__PURE__ */ jsxRuntime.jsx(
433
+ "label",
434
+ {
435
+ htmlFor: id,
436
+ className: cn(
437
+ "text-sm font-normal text-black leading-6",
438
+ appearance.labelClassName
439
+ ),
440
+ children: label
441
+ }
442
+ ),
443
+ /* @__PURE__ */ jsxRuntime.jsx(
444
+ "input",
445
+ {
446
+ id,
447
+ className: cn(
448
+ "w-full flex items-center gap-2 self-stretch",
449
+ "pl-3 pr-2 py-2 rounded-sm border border-[#D4D4D4] bg-white",
450
+ "text-sm font-normal leading-5",
451
+ "placeholder:text-[#A3A3A3] placeholder:font-sm placeholder:font-normal",
452
+ "focus:outline-none focus:border-black",
453
+ appearance.inputClassName
454
+ ),
455
+ ...props
456
+ }
457
+ )
458
+ ] });
459
+ }
460
+ function AuthPasswordStrengthIndicator({
461
+ password,
462
+ config,
463
+ appearance = {}
464
+ }) {
465
+ const requirements = createRequirements(config);
466
+ return /* @__PURE__ */ jsxRuntime.jsx(
467
+ "div",
468
+ {
469
+ className: cn("mt-3 flex flex-col gap-3", appearance.containerClassName),
470
+ children: requirements.map((req) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
471
+ /* @__PURE__ */ jsxRuntime.jsx(
472
+ "div",
473
+ {
474
+ className: cn(
475
+ "flex items-center justify-center w-4 h-4 rounded-full border-2 transition-colors",
476
+ req.test(password) ? "bg-[#059669] border-transparent" : "border-neutral-400 bg-white"
477
+ ),
478
+ children: req.test(password) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "w-3 h-3 text-white" })
479
+ }
480
+ ),
481
+ /* @__PURE__ */ jsxRuntime.jsx(
482
+ "span",
483
+ {
484
+ className: cn(
485
+ "text-sm font-normal leading-5 text-[#525252]",
486
+ appearance.requirementClassName
487
+ ),
488
+ children: req.label
489
+ }
490
+ )
491
+ ] }, req.label))
492
+ }
493
+ );
494
+ }
495
+ function createRequirements(config) {
496
+ const requirements = [];
497
+ const minLength = config.passwordMinLength;
498
+ const requireUppercase = config.requireUppercase;
499
+ const requireLowercase = config.requireLowercase;
500
+ const requireNumber = config.requireNumber;
501
+ const requireSpecialChar = config.requireSpecialChar;
502
+ if (requireUppercase) {
503
+ requirements.push({
504
+ label: "At least 1 Uppercase letter",
505
+ test: (pwd) => /[A-Z]/.test(pwd)
506
+ });
507
+ }
508
+ if (requireLowercase) {
509
+ requirements.push({
510
+ label: "At least 1 Lowercase letter",
511
+ test: (pwd) => /[a-z]/.test(pwd)
512
+ });
513
+ }
514
+ if (requireNumber) {
515
+ requirements.push({
516
+ label: "At least 1 Number",
517
+ test: (pwd) => /\d/.test(pwd)
518
+ });
519
+ }
520
+ if (requireSpecialChar) {
521
+ requirements.push({
522
+ label: "Special character (e.g. !?<>@#$%)",
523
+ test: (pwd) => /[!@#$%^&*()_+\-=[\]{};\\|,.<>/?]/.test(pwd)
524
+ });
525
+ }
526
+ requirements.push({
527
+ label: `${minLength} characters or more`,
528
+ test: (pwd) => pwd.length >= minLength
529
+ });
530
+ return requirements;
531
+ }
532
+ function validatePasswordStrength(password, config) {
533
+ if (!password) return false;
534
+ const requirements = createRequirements(config);
535
+ return requirements.every((req) => req.test(password));
536
+ }
537
+ function AuthPasswordField({
538
+ label,
539
+ id,
540
+ showStrengthIndicator = false,
541
+ emailAuthConfig,
542
+ forgotPasswordLink,
543
+ value,
544
+ appearance = {},
545
+ onFocus,
546
+ ...props
547
+ }) {
548
+ const [showPassword, setShowPassword] = react.useState(false);
549
+ const [showStrength, setShowStrength] = react.useState(false);
550
+ const handleFocus = (e) => {
551
+ if (showStrengthIndicator) {
552
+ setShowStrength(true);
553
+ }
554
+ onFocus?.(e);
555
+ };
556
+ return /* @__PURE__ */ jsxRuntime.jsxs(
557
+ "div",
558
+ {
559
+ className: cn(
560
+ "flex flex-col justify-center items-stretch gap-1",
561
+ appearance.containerClassName
562
+ ),
563
+ children: [
564
+ (label || forgotPasswordLink) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between items-center", children: [
565
+ /* @__PURE__ */ jsxRuntime.jsx(
566
+ "label",
567
+ {
568
+ htmlFor: id,
569
+ className: cn(
570
+ "text-sm font-normal text-black leading-6",
571
+ appearance.labelClassName
572
+ ),
573
+ children: label
574
+ }
575
+ ),
576
+ forgotPasswordLink && /* @__PURE__ */ jsxRuntime.jsx(
577
+ "a",
578
+ {
579
+ href: forgotPasswordLink.href,
580
+ className: "text-right text-sm font-normal text-[#737373] leading-6",
581
+ children: forgotPasswordLink.text || "Forget Password?"
582
+ }
583
+ )
584
+ ] }),
585
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
586
+ /* @__PURE__ */ jsxRuntime.jsx(
587
+ "input",
588
+ {
589
+ id,
590
+ type: showPassword ? "text" : "password",
591
+ className: cn(
592
+ "w-full flex items-center gap-2 self-stretch",
593
+ "pl-3 py-2 pr-8 rounded border border-[#D4D4D4] bg-white",
594
+ "text-sm font-normal leading-5",
595
+ "placeholder:text-[#A3A3A3] placeholder:font-sm placeholder:font-normal",
596
+ "focus:outline-none focus:border-black",
597
+ appearance.inputClassName
598
+ ),
599
+ value,
600
+ onFocus: handleFocus,
601
+ ...props
602
+ }
603
+ ),
604
+ /* @__PURE__ */ jsxRuntime.jsx(
605
+ "button",
606
+ {
607
+ type: "button",
608
+ onClick: () => setShowPassword(!showPassword),
609
+ className: "absolute right-2 top-1/2 -translate-y-1/2 bg-transparent border-none text-[#A6A6A6] cursor-pointer transition-colors hover:text-gray-600 flex items-center justify-center",
610
+ "aria-label": showPassword ? "Hide password" : "Show password",
611
+ children: showPassword ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { size: 20 }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { size: 20 })
612
+ }
613
+ )
614
+ ] }),
615
+ showStrengthIndicator && showStrength && /* @__PURE__ */ jsxRuntime.jsx(
616
+ AuthPasswordStrengthIndicator,
617
+ {
618
+ password: String(value || ""),
619
+ config: emailAuthConfig
620
+ }
621
+ )
622
+ ]
623
+ }
624
+ );
625
+ }
626
+ function AuthSubmitButton({
627
+ children,
628
+ isLoading = false,
629
+ confirmed = false,
630
+ disabled = false,
631
+ className
632
+ }) {
633
+ return /* @__PURE__ */ jsxRuntime.jsxs(
634
+ "button",
635
+ {
636
+ type: "submit",
637
+ className: cn(
638
+ "rounded-sm bg-black w-full flex mt-4 px-4 py-2",
639
+ "justify-center items-center gap-2.5 self-stretch",
640
+ "text-white font-semibold font-manrope text-base leading-normal",
641
+ "border-none cursor-pointer transition-colors",
642
+ "hover:bg-gray-800",
643
+ "disabled:opacity-50 disabled:cursor-not-allowed",
644
+ className
645
+ ),
646
+ disabled: disabled || isLoading || confirmed,
647
+ children: [
648
+ isLoading && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "w-5 h-5 animate-spin", size: 20 }),
649
+ confirmed && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { className: "w-5 h-5", size: 20 }),
650
+ children
651
+ ]
652
+ }
653
+ );
654
+ }
655
+ function AuthLink({ text, linkText, href, appearance = {} }) {
656
+ return /* @__PURE__ */ jsxRuntime.jsxs("p", { className: cn(
657
+ "text-center text-sm font-normal text-[#828282] leading-6",
658
+ appearance.containerClassName
659
+ ), children: [
660
+ text,
661
+ " ",
662
+ /* @__PURE__ */ jsxRuntime.jsx(
663
+ "a",
664
+ {
665
+ href,
666
+ className: cn(
667
+ "text-sm font-medium text-black leading-6",
668
+ appearance.linkClassName
669
+ ),
670
+ children: linkText
671
+ }
672
+ )
673
+ ] });
674
+ }
675
+ function AuthDivider({ text = "or", className }) {
676
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
677
+ "flex justify-center items-center gap-6 self-stretch",
678
+ "before:content-[''] before:flex-1 before:h-px before:bg-[#E5E5E5]",
679
+ "after:content-[''] after:flex-1 after:h-px after:bg-[#E5E5E5]",
680
+ className
681
+ ), children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-semibold font-manrope text-[#A3A3A3] leading-normal", children: text }) });
682
+ }
683
+ var oauthProviders = {
684
+ google: {
685
+ name: "Google",
686
+ svg: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
687
+ /* @__PURE__ */ jsxRuntime.jsx(
688
+ "path",
689
+ {
690
+ d: "M17.64 9.20443C17.64 8.56625 17.5827 7.95262 17.4764 7.36353H9V10.8449H13.8436C13.635 11.9699 13.0009 12.9231 12.0477 13.5613V15.8194H14.9564C16.6582 14.2526 17.64 11.9453 17.64 9.20443Z",
691
+ fill: "#4285F4"
692
+ }
693
+ ),
694
+ /* @__PURE__ */ jsxRuntime.jsx(
695
+ "path",
696
+ {
697
+ d: "M8.99976 18C11.4298 18 13.467 17.1941 14.9561 15.8195L12.0475 13.5613C11.2416 14.1013 10.2107 14.4204 8.99976 14.4204C6.65567 14.4204 4.67158 12.8372 3.96385 10.71H0.957031V13.0418C2.43794 15.9831 5.48158 18 8.99976 18Z",
698
+ fill: "#34A853"
699
+ }
700
+ ),
701
+ /* @__PURE__ */ jsxRuntime.jsx(
702
+ "path",
703
+ {
704
+ d: "M3.96409 10.7098C3.78409 10.1698 3.68182 9.59301 3.68182 8.99983C3.68182 8.40664 3.78409 7.82983 3.96409 7.28983V4.95801H0.957273C0.347727 6.17301 0 7.54755 0 8.99983C0 10.4521 0.347727 11.8266 0.957273 13.0416L3.96409 10.7098Z",
705
+ fill: "#FBBC05"
706
+ }
707
+ ),
708
+ /* @__PURE__ */ jsxRuntime.jsx(
709
+ "path",
710
+ {
711
+ d: "M8.99976 3.57955C10.3211 3.57955 11.5075 4.03364 12.4402 4.92545L15.0216 2.34409C13.4629 0.891818 11.4257 0 8.99976 0C5.48158 0 2.43794 2.01682 0.957031 4.95818L3.96385 7.29C4.67158 5.16273 6.65567 3.57955 8.99976 3.57955Z",
712
+ fill: "#EA4335"
713
+ }
714
+ )
715
+ ] }),
716
+ className: "hover:bg-blue-50"
717
+ },
718
+ github: {
719
+ name: "GitHub",
720
+ svg: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 18 18", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx(
721
+ "path",
722
+ {
723
+ fillRule: "evenodd",
724
+ clipRule: "evenodd",
725
+ d: "M9 0C4.0275 0 0 4.13211 0 9.22838C0 13.3065 2.5785 16.7648 6.15375 17.9841C6.60375 18.0709 6.76875 17.7853 6.76875 17.5403C6.76875 17.3212 6.76125 16.7405 6.7575 15.9712C4.254 16.5277 3.726 14.7332 3.726 14.7332C3.3165 13.6681 2.72475 13.3832 2.72475 13.3832C1.9095 12.8111 2.78775 12.8229 2.78775 12.8229C3.6915 12.887 4.16625 13.7737 4.16625 13.7737C4.96875 15.1847 6.273 14.777 6.7875 14.5414C6.8685 13.9443 7.10025 13.5381 7.3575 13.3073C5.35875 13.0764 3.258 12.2829 3.258 8.74868C3.258 7.74377 3.60675 6.92392 4.18425 6.28123C4.083 6.04805 3.77925 5.10916 4.263 3.83423C4.263 3.83423 5.01675 3.58633 6.738 4.78364C7.458 4.57864 8.223 4.47614 8.988 4.47177C9.753 4.47614 10.518 4.57864 11.238 4.78364C12.948 3.58633 13.7017 3.83423 13.7017 3.83423C14.1855 5.10916 13.8818 6.04805 13.7917 6.28123C14.3655 6.92392 14.7142 7.74377 14.7142 8.74868C14.7142 12.2923 12.6105 13.0725 10.608 13.2995C10.923 13.5765 11.2155 14.1423 11.2155 15.0071C11.2155 16.242 11.205 17.2344 11.205 17.5341C11.205 17.7759 11.3625 18.0647 11.823 17.9723C15.4237 16.7609 18 13.3002 18 9.22838C18 4.13211 13.9703 0 9 0Z",
726
+ fill: "currentColor"
727
+ }
728
+ ) }),
729
+ className: "hover:bg-gray-50"
730
+ },
731
+ discord: {
732
+ name: "Discord",
733
+ svg: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 127.14 96.36", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx(
734
+ "path",
735
+ {
736
+ d: "M107.7,8.07A105.15,105.15,0,0,0,81.47,0a72.06,72.06,0,0,0-3.36,6.83A97.68,97.68,0,0,0,49,6.83,72.37,72.37,0,0,0,45.64,0,105.89,105.89,0,0,0,19.39,8.09C2.79,32.65-1.71,56.6.54,80.21h0A105.73,105.73,0,0,0,32.71,96.36,77.7,77.7,0,0,0,39.6,85.25a68.42,68.42,0,0,1-10.85-5.18c.91-.66,1.8-1.34,2.66-2a75.57,75.57,0,0,0,64.32,0c.87.71,1.76,1.39,2.66,2a68.68,68.68,0,0,1-10.87,5.19,77,77,0,0,0,6.89,11.1A105.25,105.25,0,0,0,126.6,80.22h0C129.24,52.84,122.09,29.11,107.7,8.07ZM42.45,65.69C36.18,65.69,31,60,31,53s5-12.74,11.43-12.74S54,46,53.89,53,48.84,65.69,42.45,65.69Zm42.24,0C78.41,65.69,73.25,60,73.25,53s5-12.74,11.44-12.74S96.23,46,96.12,53,91.08,65.69,84.69,65.69Z",
737
+ fill: "#5865F2"
738
+ }
739
+ ) }),
740
+ className: "hover:bg-indigo-50"
741
+ },
742
+ apple: {
743
+ name: "Apple",
744
+ svg: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 18 22", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx(
745
+ "path",
746
+ {
747
+ d: "M17.769 16.867c-.343.78-.507 1.129-1.014 1.82-.701.961-1.691 2.156-2.917 2.166-1.088.01-1.378-.706-2.87-.697-1.491.008-1.807.708-2.896.697-1.226-.01-2.156-1.09-2.858-2.051C2.66 16.005 1.51 11.58 3.104 8.62c1.12-2.08 2.892-3.397 4.557-3.407 1.343-.009 2.19.708 3.297.708 1.077 0 1.734-.71 3.287-.71 1.172 0 2.781.955 3.799 2.594-3.338 1.832-2.794 6.604.725 8.062zM12.268.695c.856 1.11.72 2.15.694 2.635-.923-.068-2.04-.638-2.68-1.43C9.474.76 9.35-.301 9.402-.8c.977.03 2.04.633 2.866 1.495z",
748
+ fill: "currentColor"
749
+ }
750
+ ) }),
751
+ className: "hover:bg-gray-50"
752
+ },
753
+ microsoft: {
754
+ name: "Microsoft",
755
+ svg: /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "18", height: "18", viewBox: "0 0 23 23", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
756
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M0 0h11v11H0z", fill: "#F25022" }),
757
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 0h11v11H12z", fill: "#7FBA00" }),
758
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M0 12h11v11H0z", fill: "#00A4EF" }),
759
+ /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 12h11v11H12z", fill: "#FFB900" })
760
+ ] }),
761
+ className: "hover:bg-blue-50"
762
+ },
763
+ facebook: {
764
+ name: "Facebook",
765
+ svg: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx(
766
+ "path",
767
+ {
768
+ d: "M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z",
769
+ fill: "#1877F2"
770
+ }
771
+ ) }),
772
+ className: "hover:bg-blue-50"
773
+ }
774
+ };
775
+ function getProviderConfig(provider) {
776
+ return oauthProviders[provider] || null;
777
+ }
778
+ function getAllProviderConfigs() {
779
+ return oauthProviders;
780
+ }
781
+ function AuthOAuthButton({
782
+ provider,
783
+ onClick,
784
+ disabled,
785
+ loading,
786
+ displayMode = "full",
787
+ style,
788
+ className
789
+ }) {
790
+ const config = getProviderConfig(provider);
791
+ if (!config) {
792
+ return null;
793
+ }
794
+ const getButtonText = () => {
795
+ if (loading) return "Authenticating...";
796
+ if (displayMode === "full") return `Continue with ${config.name}`;
797
+ if (displayMode === "short") return config.name;
798
+ return "";
799
+ };
800
+ return /* @__PURE__ */ jsxRuntime.jsxs(
801
+ "button",
802
+ {
803
+ type: "button",
804
+ onClick: () => onClick(provider),
805
+ className: cn(
806
+ "flex w-full h-9 px-3 py-2",
807
+ "flex-row justify-center items-center gap-3",
808
+ "rounded-md border border-[#E4E4E7] bg-white",
809
+ "shadow-[0_1px_2px_0_rgba(0,0,0,0.10)]",
810
+ "text-[#09090B] text-center text-sm font-medium leading-5",
811
+ "cursor-pointer transition-all duration-200",
812
+ "hover:bg-[#f9fafb] hover:border-[#9ca3af]",
813
+ "disabled:opacity-60 disabled:cursor-not-allowed",
814
+ displayMode === "full" && "justify-center",
815
+ displayMode === "short" && "justify-center px-2 gap-2",
816
+ displayMode === "icon" && "justify-center gap-0",
817
+ className
818
+ ),
819
+ disabled: disabled || loading,
820
+ style,
821
+ children: [
822
+ loading ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "w-[18px] h-[18px] animate-spin", size: 18 }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex items-center justify-center flex-shrink-0", children: config.svg }),
823
+ getButtonText() && /* @__PURE__ */ jsxRuntime.jsx("span", { children: getButtonText() })
824
+ ]
825
+ }
826
+ );
827
+ }
828
+ function AuthOAuthProviders({
829
+ providers,
830
+ onClick,
831
+ disabled,
832
+ loading,
833
+ appearance = {}
834
+ }) {
835
+ if (!providers || providers.length === 0) {
836
+ return null;
837
+ }
838
+ const count = providers.length;
839
+ const getDisplayMode = () => {
840
+ if (count === 1) return "full";
841
+ if (count === 2 || count === 4) return "short";
842
+ return "icon";
843
+ };
844
+ const getGridColumnStyle = (index) => {
845
+ if (count <= 4) {
846
+ return {};
847
+ }
848
+ const totalRows = Math.ceil(count / 3);
849
+ const lastRowStartIndex = (totalRows - 1) * 3;
850
+ const isInLastRow = index >= lastRowStartIndex;
851
+ if (!isInLastRow) {
852
+ return { gridColumn: "span 2" };
853
+ }
854
+ const positionInLastRow = index - lastRowStartIndex;
855
+ const itemsInLastRow = count - lastRowStartIndex;
856
+ if (itemsInLastRow === 1) {
857
+ return { gridColumn: "3 / 5" };
858
+ } else if (itemsInLastRow === 2) {
859
+ if (positionInLastRow === 0) {
860
+ return { gridColumn: "2 / 4" };
861
+ } else {
862
+ return { gridColumn: "4 / 6" };
863
+ }
864
+ } else {
865
+ return { gridColumn: "span 2" };
866
+ }
867
+ };
868
+ const getGridClass = () => {
869
+ if (count === 1) return "grid-cols-1";
870
+ if (count === 2) return "grid-cols-2";
871
+ if (count === 3) return "grid-cols-3";
872
+ if (count === 4) return "grid-cols-2";
873
+ return "grid-cols-6";
874
+ };
875
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn(
876
+ "grid gap-3 w-full",
877
+ getGridClass(),
878
+ appearance.containerClassName
879
+ ), children: providers.map((provider, index) => /* @__PURE__ */ jsxRuntime.jsx(
880
+ AuthOAuthButton,
881
+ {
882
+ provider,
883
+ onClick,
884
+ disabled,
885
+ loading: loading === provider,
886
+ displayMode: getDisplayMode(),
887
+ style: getGridColumnStyle(index),
888
+ className: appearance.buttonClassName
889
+ },
890
+ provider
891
+ )) });
892
+ }
893
+ function AuthVerificationCodeInput({
894
+ length = 6,
895
+ value,
896
+ email,
897
+ onChange,
898
+ disabled = false,
899
+ appearance = {}
900
+ }) {
901
+ const inputRefs = react.useRef([]);
902
+ const handleChange = (index, digit) => {
903
+ if (digit.length > 1) return;
904
+ if (digit && !/^\d$/.test(digit)) return;
905
+ const newValue = value.split("");
906
+ newValue[index] = digit;
907
+ const updatedValue = newValue.join("");
908
+ onChange(updatedValue);
909
+ if (digit && index < length - 1) {
910
+ inputRefs.current[index + 1]?.focus();
911
+ }
912
+ };
913
+ const handleKeyDown = (index, e) => {
914
+ if (e.key === "Backspace") {
915
+ if (!value[index] && index > 0) {
916
+ inputRefs.current[index - 1]?.focus();
917
+ } else {
918
+ handleChange(index, "");
919
+ }
920
+ } else if (e.key === "ArrowLeft" && index > 0) {
921
+ inputRefs.current[index - 1]?.focus();
922
+ } else if (e.key === "ArrowRight" && index < length - 1) {
923
+ inputRefs.current[index + 1]?.focus();
924
+ }
925
+ };
926
+ const handlePaste = (e) => {
927
+ e.preventDefault();
928
+ const pastedData = e.clipboardData.getData("text/plain").trim();
929
+ if (/^\d+$/.test(pastedData) && pastedData.length === length) {
930
+ onChange(pastedData);
931
+ inputRefs.current[length - 1]?.focus();
932
+ }
933
+ };
934
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn(
935
+ "flex flex-col justify-center items-center gap-6",
936
+ appearance.containerClassName
937
+ ), children: [
938
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm font-normal text-[#525252] leading-5", children: [
939
+ "We've sent a verification code to your inbox at",
940
+ " ",
941
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-semibold text-black leading-5", children: email }),
942
+ ". Enter it below to proceed."
943
+ ] }),
944
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-3 justify-center items-center", children: Array.from({ length }).map((_, index) => /* @__PURE__ */ jsxRuntime.jsx(
945
+ "input",
946
+ {
947
+ ref: (el) => {
948
+ inputRefs.current[index] = el;
949
+ },
950
+ type: "text",
951
+ inputMode: "numeric",
952
+ maxLength: 1,
953
+ value: value[index] || "",
954
+ onChange: (e) => handleChange(index, e.target.value),
955
+ onKeyDown: (e) => handleKeyDown(index, e),
956
+ onPaste: handlePaste,
957
+ disabled,
958
+ className: cn(
959
+ "w-full h-12 px-3 py-2 rounded border border-[#E0E0E0] bg-white",
960
+ "text-center text-base font-semibold leading-5 text-black",
961
+ "transition-all duration-200 outline-none",
962
+ "focus:border-black focus:shadow-[0_0_0_2px_rgba(0,0,0,0.1)]",
963
+ "disabled:bg-[#F5F5F5] disabled:cursor-not-allowed disabled:opacity-60",
964
+ appearance.inputClassName
965
+ ),
966
+ autoComplete: "one-time-code"
967
+ },
968
+ index
969
+ )) })
970
+ ] });
971
+ }
972
+ function SignInForm({
973
+ email,
974
+ password,
975
+ onEmailChange,
976
+ onPasswordChange,
977
+ onSubmit,
978
+ error,
979
+ loading = false,
980
+ oauthLoading = null,
981
+ availableProviders = [],
982
+ onOAuthClick,
983
+ emailAuthConfig,
984
+ appearance = {},
985
+ title = "Welcome Back",
986
+ subtitle = "Login to your account",
987
+ emailLabel = "Email",
988
+ emailPlaceholder = "example@email.com",
989
+ passwordLabel = "Password",
990
+ passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
991
+ forgotPasswordText = "Forget Password?",
992
+ forgotPasswordUrl,
993
+ submitButtonText = "Sign In",
994
+ loadingButtonText = "Signing in...",
995
+ signUpText = "Don't have an account?",
996
+ signUpLinkText = "Sign Up Now",
997
+ signUpUrl = "/sign-up",
998
+ dividerText = "or"
999
+ }) {
1000
+ const defaultEmailAuthConfig = {
1001
+ requireEmailVerification: false,
1002
+ passwordMinLength: 6,
1003
+ requireNumber: false,
1004
+ requireLowercase: false,
1005
+ requireUppercase: false,
1006
+ requireSpecialChar: false
1007
+ };
1008
+ return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { appearance, children: [
1009
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
1010
+ /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1011
+ /* @__PURE__ */ jsxRuntime.jsxs(
1012
+ "form",
1013
+ {
1014
+ onSubmit,
1015
+ noValidate: true,
1016
+ className: "flex flex-col items-stretch justify-center gap-6",
1017
+ children: [
1018
+ /* @__PURE__ */ jsxRuntime.jsx(
1019
+ AuthFormField,
1020
+ {
1021
+ id: "email",
1022
+ type: "email",
1023
+ label: emailLabel,
1024
+ placeholder: emailPlaceholder,
1025
+ value: email,
1026
+ onChange: (e) => onEmailChange(e.target.value),
1027
+ required: true,
1028
+ autoComplete: "email"
1029
+ }
1030
+ ),
1031
+ /* @__PURE__ */ jsxRuntime.jsx(
1032
+ AuthPasswordField,
1033
+ {
1034
+ id: "password",
1035
+ label: passwordLabel,
1036
+ placeholder: passwordPlaceholder,
1037
+ value: password,
1038
+ onChange: (e) => onPasswordChange(e.target.value),
1039
+ required: true,
1040
+ autoComplete: "current-password",
1041
+ emailAuthConfig: emailAuthConfig || defaultEmailAuthConfig,
1042
+ forgotPasswordLink: forgotPasswordUrl ? {
1043
+ href: forgotPasswordUrl,
1044
+ text: forgotPasswordText
1045
+ } : void 0
1046
+ }
1047
+ ),
1048
+ /* @__PURE__ */ jsxRuntime.jsx(
1049
+ AuthSubmitButton,
1050
+ {
1051
+ isLoading: loading,
1052
+ disabled: loading || oauthLoading !== null,
1053
+ className: appearance.buttonClassName,
1054
+ children: loading ? loadingButtonText : submitButtonText
1055
+ }
1056
+ )
1057
+ ]
1058
+ }
1059
+ ),
1060
+ /* @__PURE__ */ jsxRuntime.jsx(AuthLink, { text: signUpText, linkText: signUpLinkText, href: signUpUrl }),
1061
+ availableProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1062
+ /* @__PURE__ */ jsxRuntime.jsx(AuthDivider, { text: dividerText }),
1063
+ /* @__PURE__ */ jsxRuntime.jsx(
1064
+ AuthOAuthProviders,
1065
+ {
1066
+ providers: availableProviders,
1067
+ onClick: onOAuthClick,
1068
+ disabled: loading || oauthLoading !== null,
1069
+ loading: oauthLoading
1070
+ }
1071
+ )
1072
+ ] })
1073
+ ] });
1074
+ }
1075
+ function SignIn({
1076
+ afterSignInUrl = "/",
1077
+ onSuccess,
1078
+ onError,
1079
+ onRedirect,
1080
+ ...uiProps
1081
+ }) {
1082
+ const { signIn, baseUrl } = useInsforge();
1083
+ const { oauthProviders: oauthProviders2, emailConfig } = usePublicAuthConfig();
1084
+ const [email, setEmail] = react.useState("");
1085
+ const [password, setPassword] = react.useState("");
1086
+ const [error, setError] = react.useState("");
1087
+ const [loading, setLoading] = react.useState(false);
1088
+ const [oauthLoading, setOauthLoading] = react.useState(null);
1089
+ const [insforge] = react.useState(() => sdk.createClient({ baseUrl }));
1090
+ async function handleSubmit(e) {
1091
+ e.preventDefault();
1092
+ setLoading(true);
1093
+ setError("");
1094
+ try {
1095
+ const result = await signIn(email, password);
1096
+ if ("error" in result) {
1097
+ throw new Error(result.error);
1098
+ }
1099
+ const { user, accessToken } = result;
1100
+ if (onSuccess) {
1101
+ if (user) onSuccess(user, accessToken || "");
1102
+ }
1103
+ if (onRedirect) {
1104
+ onRedirect(afterSignInUrl);
1105
+ } else {
1106
+ window.location.href = afterSignInUrl;
1107
+ }
1108
+ } catch (err) {
1109
+ const errorMessage = err.message || "Sign in failed";
1110
+ setError(errorMessage);
1111
+ if (onError) onError(new Error(errorMessage));
1112
+ } finally {
1113
+ setLoading(false);
1114
+ }
1115
+ }
1116
+ async function handleOAuth(provider) {
1117
+ try {
1118
+ setOauthLoading(provider);
1119
+ setError("");
1120
+ const redirectTo = `${window.location.origin}/auth/callback`;
1121
+ sessionStorage.setItem("oauth_final_destination", afterSignInUrl || "/");
1122
+ await insforge.auth.signInWithOAuth({
1123
+ provider,
1124
+ redirectTo
1125
+ });
1126
+ } catch (err) {
1127
+ const errorMessage = err.message || `${provider} sign in failed`;
1128
+ setError(errorMessage);
1129
+ if (onError) onError(new Error(errorMessage));
1130
+ setOauthLoading(null);
1131
+ }
1132
+ }
1133
+ return /* @__PURE__ */ jsxRuntime.jsx(
1134
+ SignInForm,
1135
+ {
1136
+ email,
1137
+ password,
1138
+ onEmailChange: setEmail,
1139
+ onPasswordChange: setPassword,
1140
+ onSubmit: handleSubmit,
1141
+ error,
1142
+ loading,
1143
+ oauthLoading,
1144
+ availableProviders: oauthProviders2,
1145
+ onOAuthClick: handleOAuth,
1146
+ emailAuthConfig: emailConfig || void 0,
1147
+ ...uiProps
1148
+ }
1149
+ );
1150
+ }
1151
+ function SignUpForm({
1152
+ email,
1153
+ password,
1154
+ onEmailChange,
1155
+ onPasswordChange,
1156
+ onSubmit,
1157
+ error,
1158
+ loading = false,
1159
+ oauthLoading = null,
1160
+ availableProviders = [],
1161
+ onOAuthClick,
1162
+ emailAuthConfig,
1163
+ appearance = {},
1164
+ title = "Get Started",
1165
+ subtitle = "Create your account",
1166
+ emailLabel = "Email",
1167
+ emailPlaceholder = "example@email.com",
1168
+ passwordLabel = "Password",
1169
+ passwordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
1170
+ submitButtonText = "Sign Up",
1171
+ loadingButtonText = "Creating account...",
1172
+ signInText = "Already have an account?",
1173
+ signInLinkText = "Login Now",
1174
+ signInUrl = "/sign-in",
1175
+ dividerText = "or"
1176
+ }) {
1177
+ const defaultEmailAuthConfig = {
1178
+ requireEmailVerification: false,
1179
+ passwordMinLength: 6,
1180
+ requireNumber: false,
1181
+ requireLowercase: false,
1182
+ requireUppercase: false,
1183
+ requireSpecialChar: false
1184
+ };
1185
+ return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { appearance, children: [
1186
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
1187
+ /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1188
+ /* @__PURE__ */ jsxRuntime.jsxs(
1189
+ "form",
1190
+ {
1191
+ onSubmit,
1192
+ noValidate: true,
1193
+ className: "flex flex-col items-stretch justify-center gap-6",
1194
+ children: [
1195
+ /* @__PURE__ */ jsxRuntime.jsx(
1196
+ AuthFormField,
1197
+ {
1198
+ id: "email",
1199
+ type: "email",
1200
+ label: emailLabel,
1201
+ placeholder: emailPlaceholder,
1202
+ value: email,
1203
+ onChange: (e) => onEmailChange(e.target.value),
1204
+ required: true,
1205
+ autoComplete: "email"
1206
+ }
1207
+ ),
1208
+ /* @__PURE__ */ jsxRuntime.jsx(
1209
+ AuthPasswordField,
1210
+ {
1211
+ id: "password",
1212
+ label: passwordLabel,
1213
+ placeholder: passwordPlaceholder,
1214
+ value: password,
1215
+ onChange: (e) => onPasswordChange(e.target.value),
1216
+ required: true,
1217
+ minLength: emailAuthConfig?.passwordMinLength ?? 6,
1218
+ autoComplete: "new-password",
1219
+ showStrengthIndicator: true,
1220
+ emailAuthConfig: emailAuthConfig || defaultEmailAuthConfig
1221
+ }
1222
+ ),
1223
+ /* @__PURE__ */ jsxRuntime.jsx(
1224
+ AuthSubmitButton,
1225
+ {
1226
+ isLoading: loading,
1227
+ disabled: loading || oauthLoading !== null,
1228
+ className: appearance.buttonClassName,
1229
+ children: loading ? loadingButtonText : submitButtonText
1230
+ }
1231
+ )
1232
+ ]
1233
+ }
1234
+ ),
1235
+ /* @__PURE__ */ jsxRuntime.jsx(AuthLink, { text: signInText, linkText: signInLinkText, href: signInUrl }),
1236
+ availableProviders.length > 0 && onOAuthClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1237
+ /* @__PURE__ */ jsxRuntime.jsx(AuthDivider, { text: dividerText }),
1238
+ /* @__PURE__ */ jsxRuntime.jsx(
1239
+ AuthOAuthProviders,
1240
+ {
1241
+ providers: availableProviders,
1242
+ onClick: onOAuthClick,
1243
+ disabled: loading || oauthLoading !== null,
1244
+ loading: oauthLoading
1245
+ }
1246
+ )
1247
+ ] })
1248
+ ] });
1249
+ }
1250
+ function SignUp({
1251
+ afterSignUpUrl = "/",
1252
+ onSuccess,
1253
+ onError,
1254
+ onRedirect,
1255
+ ...uiProps
1256
+ }) {
1257
+ const { signUp, baseUrl } = useInsforge();
1258
+ const { oauthProviders: oauthProviders2, emailConfig } = usePublicAuthConfig();
1259
+ const [email, setEmail] = react.useState("");
1260
+ const [password, setPassword] = react.useState("");
1261
+ const [error, setError] = react.useState("");
1262
+ const [loading, setLoading] = react.useState(false);
1263
+ const [oauthLoading, setOauthLoading] = react.useState(
1264
+ null
1265
+ );
1266
+ const [insforge] = react.useState(() => sdk.createClient({ baseUrl }));
1267
+ async function handleSubmit(e) {
1268
+ e.preventDefault();
1269
+ setLoading(true);
1270
+ setError("");
1271
+ if (emailConfig && !validatePasswordStrength(password, emailConfig)) {
1272
+ setError("Password does not meet all requirements");
1273
+ setLoading(false);
1274
+ return;
1275
+ }
1276
+ try {
1277
+ const result = await signUp(email, password);
1278
+ if ("error" in result) {
1279
+ throw new Error(result.error);
1280
+ }
1281
+ const { user, accessToken } = result;
1282
+ if (onSuccess) {
1283
+ if (user) onSuccess(user, accessToken || "");
1284
+ }
1285
+ if (onRedirect) {
1286
+ onRedirect(afterSignUpUrl);
1287
+ } else {
1288
+ window.location.href = afterSignUpUrl;
1289
+ }
1290
+ } catch (err) {
1291
+ const errorMessage = err.message || "Sign up failed";
1292
+ setError(errorMessage);
1293
+ if (onError) onError(new Error(errorMessage));
1294
+ } finally {
1295
+ setLoading(false);
1296
+ }
1297
+ }
1298
+ async function handleOAuth(provider) {
1299
+ try {
1300
+ setOauthLoading(provider);
1301
+ setError("");
1302
+ const redirectTo = `${window.location.origin}/auth/callback`;
1303
+ sessionStorage.setItem("oauth_final_destination", afterSignUpUrl || "/");
1304
+ await insforge.auth.signInWithOAuth({
1305
+ provider,
1306
+ redirectTo
1307
+ });
1308
+ } catch (err) {
1309
+ const errorMessage = err.message || `${provider} sign up failed`;
1310
+ setError(errorMessage);
1311
+ if (onError) onError(new Error(errorMessage));
1312
+ setOauthLoading(null);
1313
+ }
1314
+ }
1315
+ return /* @__PURE__ */ jsxRuntime.jsx(
1316
+ SignUpForm,
1317
+ {
1318
+ email,
1319
+ password,
1320
+ onEmailChange: setEmail,
1321
+ onPasswordChange: setPassword,
1322
+ onSubmit: handleSubmit,
1323
+ error,
1324
+ loading,
1325
+ oauthLoading,
1326
+ availableProviders: oauthProviders2,
1327
+ onOAuthClick: handleOAuth,
1328
+ emailAuthConfig: emailConfig || void 0,
1329
+ ...uiProps
1330
+ }
1331
+ );
1332
+ }
1333
+ function UserButton({
1334
+ afterSignOutUrl = "/",
1335
+ mode = "detailed",
1336
+ appearance = {}
1337
+ }) {
1338
+ const { user, signOut } = useInsforge();
1339
+ const [isOpen, setIsOpen] = react.useState(false);
1340
+ const [imageError, setImageError] = react.useState(false);
1341
+ const dropdownRef = react.useRef(null);
1342
+ react.useEffect(() => {
1343
+ setImageError(false);
1344
+ const avatarUrl = user?.avatarUrl;
1345
+ if (!avatarUrl) return;
1346
+ const checkImageUrl = async () => {
1347
+ try {
1348
+ const response = await fetch(avatarUrl, {
1349
+ method: "HEAD",
1350
+ cache: "no-cache"
1351
+ });
1352
+ if (!response.ok) {
1353
+ setImageError(true);
1354
+ }
1355
+ } catch (error) {
1356
+ setImageError(true);
1357
+ }
1358
+ };
1359
+ checkImageUrl();
1360
+ }, [user?.avatarUrl]);
1361
+ react.useEffect(() => {
1362
+ function handleClickOutside(event) {
1363
+ if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
1364
+ setIsOpen(false);
1365
+ }
1366
+ }
1367
+ if (isOpen) {
1368
+ document.addEventListener("mousedown", handleClickOutside);
1369
+ }
1370
+ return () => {
1371
+ document.removeEventListener("mousedown", handleClickOutside);
1372
+ };
1373
+ }, [isOpen]);
1374
+ async function handleSignOut() {
1375
+ await signOut();
1376
+ setIsOpen(false);
1377
+ window.location.href = afterSignOutUrl;
1378
+ }
1379
+ if (!user) return null;
1380
+ const initials = user.name ? user.name.charAt(0).toUpperCase() : user.email.split("@")[0].slice(0, 2).toUpperCase();
1381
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1382
+ "div",
1383
+ {
1384
+ className: cn("relative inline-block", appearance.containerClassName),
1385
+ ref: dropdownRef,
1386
+ children: [
1387
+ /* @__PURE__ */ jsxRuntime.jsxs(
1388
+ "button",
1389
+ {
1390
+ className: cn(
1391
+ "p-1 bg-transparent border-0 rounded-full cursor-pointer transition-all duration-200",
1392
+ "flex items-center justify-center gap-2",
1393
+ "hover:bg-black/5",
1394
+ mode === "detailed" && "rounded-lg p-2",
1395
+ appearance.buttonClassName
1396
+ ),
1397
+ onClick: () => setIsOpen(!isOpen),
1398
+ "aria-expanded": isOpen,
1399
+ "aria-haspopup": "true",
1400
+ children: [
1401
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center w-10 h-10 bg-blue-500 rounded-full", children: user.avatarUrl && !imageError ? /* @__PURE__ */ jsxRuntime.jsx(
1402
+ "img",
1403
+ {
1404
+ src: user.avatarUrl,
1405
+ alt: user.email,
1406
+ onError: () => setImageError(true),
1407
+ className: "rounded-full object-cover w-full h-full"
1408
+ }
1409
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-white font-semibold text-sm", children: initials }) }),
1410
+ mode === "detailed" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start gap-0.5", children: [
1411
+ user.name && /* @__PURE__ */ jsxRuntime.jsx(
1412
+ "div",
1413
+ {
1414
+ className: cn(
1415
+ "text-sm font-semibold text-gray-900 leading-5 text-left",
1416
+ appearance.nameClassName
1417
+ ),
1418
+ children: user.name
1419
+ }
1420
+ ),
1421
+ /* @__PURE__ */ jsxRuntime.jsx(
1422
+ "div",
1423
+ {
1424
+ className: cn(
1425
+ "text-xs text-gray-500 leading-4 text-left",
1426
+ appearance.emailClassName
1427
+ ),
1428
+ children: user.email
1429
+ }
1430
+ )
1431
+ ] })
1432
+ ]
1433
+ }
1434
+ ),
1435
+ isOpen && /* @__PURE__ */ jsxRuntime.jsx(
1436
+ "div",
1437
+ {
1438
+ className: cn(
1439
+ "absolute top-full right-0 mt-2 min-w-40",
1440
+ "bg-white border border-gray-200 rounded-lg",
1441
+ "shadow-lg z-50 overflow-hidden p-1",
1442
+ appearance.dropdownClassName
1443
+ ),
1444
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1445
+ "button",
1446
+ {
1447
+ onClick: handleSignOut,
1448
+ className: "flex items-center justify-start gap-2 w-full px-3 py-2 text-sm font-normal text-red-600 bg-transparent border-0 rounded-md cursor-pointer transition-colors hover:bg-red-50 text-left",
1449
+ children: [
1450
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.LogOut, { className: "w-5 h-5" }),
1451
+ "Sign out"
1452
+ ]
1453
+ }
1454
+ )
1455
+ }
1456
+ )
1457
+ ]
1458
+ }
1459
+ );
1460
+ }
1461
+ function Protect({
1462
+ children,
1463
+ fallback,
1464
+ redirectTo = "/sign-in",
1465
+ condition,
1466
+ onRedirect
1467
+ }) {
1468
+ const { isSignedIn, isLoaded, user } = useInsforge();
1469
+ react.useEffect(() => {
1470
+ if (isLoaded && !isSignedIn) {
1471
+ if (onRedirect) {
1472
+ onRedirect(redirectTo);
1473
+ } else {
1474
+ window.location.href = redirectTo;
1475
+ }
1476
+ } else if (isLoaded && isSignedIn && condition && user) {
1477
+ if (!condition(user)) {
1478
+ if (onRedirect) {
1479
+ onRedirect(redirectTo);
1480
+ } else {
1481
+ window.location.href = redirectTo;
1482
+ }
1483
+ }
1484
+ }
1485
+ }, [isLoaded, isSignedIn, redirectTo, condition, user, onRedirect]);
1486
+ if (!isLoaded) {
1487
+ return fallback || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "insforge-loading", children: "Loading..." });
1488
+ }
1489
+ if (!isSignedIn) {
1490
+ return fallback || null;
1491
+ }
1492
+ if (condition && user && !condition(user)) {
1493
+ return fallback || null;
1494
+ }
1495
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1496
+ }
1497
+ function SignedIn({ children }) {
1498
+ const { isSignedIn, isLoaded } = useInsforge();
1499
+ if (!isLoaded) return null;
1500
+ if (!isSignedIn) return null;
1501
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1502
+ }
1503
+ function SignedOut({ children }) {
1504
+ const { isSignedIn, isLoaded } = useInsforge();
1505
+ if (!isLoaded) return null;
1506
+ if (isSignedIn) return null;
1507
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1508
+ }
1509
+ function InsforgeCallback({
1510
+ redirectTo,
1511
+ onSuccess,
1512
+ onError,
1513
+ loadingComponent,
1514
+ onRedirect
1515
+ }) {
1516
+ const isProcessingRef = react.useRef(false);
1517
+ const { reloadAuth } = useInsforge();
1518
+ react.useEffect(() => {
1519
+ const processCallback = async () => {
1520
+ if (isProcessingRef.current) return;
1521
+ isProcessingRef.current = true;
1522
+ const searchParams = new URLSearchParams(window.location.search);
1523
+ const error = searchParams.get("error");
1524
+ if (error) {
1525
+ if (onError) {
1526
+ onError(error);
1527
+ } else {
1528
+ const errorUrl = "/?error=" + encodeURIComponent(error);
1529
+ if (onRedirect) {
1530
+ onRedirect(errorUrl);
1531
+ } else {
1532
+ window.location.href = errorUrl;
1533
+ }
1534
+ }
1535
+ return;
1536
+ }
1537
+ const result = await reloadAuth();
1538
+ if (!result.success) {
1539
+ const errorMsg = result.error || "authentication_failed";
1540
+ if (onError) {
1541
+ onError(errorMsg);
1542
+ } else {
1543
+ const errorUrl = "/?error=" + encodeURIComponent(errorMsg);
1544
+ if (onRedirect) {
1545
+ onRedirect(errorUrl);
1546
+ } else {
1547
+ window.location.href = errorUrl;
1548
+ }
1549
+ }
1550
+ return;
1551
+ }
1552
+ window.history.replaceState({}, "", window.location.pathname);
1553
+ if (onSuccess) {
1554
+ onSuccess();
1555
+ }
1556
+ const destination = redirectTo || sessionStorage.getItem("auth_destination") || sessionStorage.getItem("oauth_final_destination") || "/";
1557
+ sessionStorage.removeItem("auth_destination");
1558
+ sessionStorage.removeItem("oauth_final_destination");
1559
+ if (onRedirect) {
1560
+ onRedirect(destination);
1561
+ } else {
1562
+ window.location.href = destination;
1563
+ }
1564
+ };
1565
+ processCallback();
1566
+ }, []);
1567
+ const defaultLoading = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-screen", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-center", children: [
1568
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold mb-4", children: "Completing authentication..." }),
1569
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600 mx-auto" })
1570
+ ] }) });
1571
+ return loadingComponent || defaultLoading;
1572
+ }
1573
+ function ForgotPasswordForm({
1574
+ email,
1575
+ onEmailChange,
1576
+ onSubmit,
1577
+ error,
1578
+ loading = false,
1579
+ success = false,
1580
+ appearance = {},
1581
+ title = "Forgot Password?",
1582
+ subtitle = "Enter your email address and we'll send you a code to reset your password.",
1583
+ emailLabel = "Email",
1584
+ emailPlaceholder = "example@email.com",
1585
+ submitButtonText = "Send Reset Code",
1586
+ loadingButtonText = "Sending...",
1587
+ backToSignInText = "Remember your password?",
1588
+ backToSignInUrl = "/sign-in",
1589
+ successTitle = "Check Your Email",
1590
+ successMessage
1591
+ }) {
1592
+ if (success) {
1593
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthContainer, { appearance, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4", children: [
1594
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-16 h-16 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "w-8 h-8 text-green-600 dark:text-green-400", fill: "none", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 13l4 4L19 7" }) }) }),
1595
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold text-black dark:text-white text-center", children: successTitle }),
1596
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-neutral-600 dark:text-neutral-400 text-center", children: successMessage || `We've sent a password reset link to ${email}. Please check your email and follow the instructions.` }),
1597
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: backToSignInUrl, className: "mt-4 text-black dark:text-white font-medium", children: "Back to Sign In" })
1598
+ ] }) });
1599
+ }
1600
+ return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { appearance, children: [
1601
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
1602
+ /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1603
+ /* @__PURE__ */ jsxRuntime.jsxs(
1604
+ "form",
1605
+ {
1606
+ onSubmit,
1607
+ noValidate: true,
1608
+ className: "flex flex-col items-stretch justify-center gap-6",
1609
+ children: [
1610
+ /* @__PURE__ */ jsxRuntime.jsx(
1611
+ AuthFormField,
1612
+ {
1613
+ id: "email",
1614
+ type: "email",
1615
+ label: emailLabel,
1616
+ placeholder: emailPlaceholder,
1617
+ value: email,
1618
+ onChange: (e) => onEmailChange(e.target.value),
1619
+ required: true,
1620
+ autoComplete: "email"
1621
+ }
1622
+ ),
1623
+ /* @__PURE__ */ jsxRuntime.jsx(
1624
+ AuthSubmitButton,
1625
+ {
1626
+ isLoading: loading,
1627
+ disabled: loading,
1628
+ className: appearance.buttonClassName,
1629
+ children: loading ? loadingButtonText : submitButtonText
1630
+ }
1631
+ )
1632
+ ]
1633
+ }
1634
+ ),
1635
+ /* @__PURE__ */ jsxRuntime.jsx(
1636
+ AuthLink,
1637
+ {
1638
+ text: backToSignInText,
1639
+ linkText: "Back to Sign In",
1640
+ href: backToSignInUrl
1641
+ }
1642
+ )
1643
+ ] });
1644
+ }
1645
+ function ResetPasswordForm({
1646
+ newPassword,
1647
+ confirmPassword,
1648
+ onNewPasswordChange,
1649
+ onConfirmPasswordChange,
1650
+ onSubmit,
1651
+ error,
1652
+ loading = false,
1653
+ emailAuthConfig,
1654
+ appearance = {},
1655
+ title = "Reset Password",
1656
+ subtitle = "Enter your new password below.",
1657
+ newPasswordLabel = "New Password",
1658
+ newPasswordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
1659
+ confirmPasswordLabel = "Confirm Password",
1660
+ confirmPasswordPlaceholder = "\u2022\u2022\u2022\u2022\u2022\u2022",
1661
+ submitButtonText = "Reset Password",
1662
+ loadingButtonText = "Resetting...",
1663
+ backToSignInText = "",
1664
+ backToSignInUrl = "/sign-in"
1665
+ }) {
1666
+ const defaultEmailAuthConfig = {
1667
+ requireEmailVerification: false,
1668
+ passwordMinLength: 6,
1669
+ requireNumber: false,
1670
+ requireLowercase: false,
1671
+ requireUppercase: false,
1672
+ requireSpecialChar: false
1673
+ };
1674
+ return /* @__PURE__ */ jsxRuntime.jsxs(AuthContainer, { appearance, children: [
1675
+ /* @__PURE__ */ jsxRuntime.jsx(AuthHeader, { title, subtitle }),
1676
+ /* @__PURE__ */ jsxRuntime.jsx(AuthErrorBanner, { error: error || "" }),
1677
+ /* @__PURE__ */ jsxRuntime.jsxs(
1678
+ "form",
1679
+ {
1680
+ onSubmit,
1681
+ noValidate: true,
1682
+ className: "flex flex-col items-stretch justify-center gap-6",
1683
+ children: [
1684
+ /* @__PURE__ */ jsxRuntime.jsx(
1685
+ AuthPasswordField,
1686
+ {
1687
+ id: "newPassword",
1688
+ label: newPasswordLabel,
1689
+ placeholder: newPasswordPlaceholder,
1690
+ value: newPassword,
1691
+ onChange: (e) => onNewPasswordChange(e.target.value),
1692
+ required: true,
1693
+ autoComplete: "new-password",
1694
+ showStrengthIndicator: true,
1695
+ emailAuthConfig: emailAuthConfig || defaultEmailAuthConfig
1696
+ }
1697
+ ),
1698
+ /* @__PURE__ */ jsxRuntime.jsx(
1699
+ AuthPasswordField,
1700
+ {
1701
+ id: "confirmPassword",
1702
+ label: confirmPasswordLabel,
1703
+ placeholder: confirmPasswordPlaceholder,
1704
+ value: confirmPassword,
1705
+ onChange: (e) => onConfirmPasswordChange(e.target.value),
1706
+ required: true,
1707
+ autoComplete: "new-password",
1708
+ emailAuthConfig: emailAuthConfig || defaultEmailAuthConfig
1709
+ }
1710
+ ),
1711
+ /* @__PURE__ */ jsxRuntime.jsx(
1712
+ AuthSubmitButton,
1713
+ {
1714
+ isLoading: loading,
1715
+ disabled: loading,
1716
+ className: appearance.buttonClassName,
1717
+ children: loading ? loadingButtonText : submitButtonText
1718
+ }
1719
+ )
1720
+ ]
1721
+ }
1722
+ ),
1723
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-center text-sm text-gray-600 dark:text-gray-400", children: [
1724
+ backToSignInText && /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
1725
+ backToSignInText,
1726
+ " "
1727
+ ] }),
1728
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: backToSignInUrl, className: "text-black dark:text-white font-medium", children: "Back to Sign In" })
1729
+ ] })
1730
+ ] });
1731
+ }
1732
+ function VerifyEmailStatus({
1733
+ status,
1734
+ error,
1735
+ appearance = {},
1736
+ verifyingTitle = "Verifying your email...",
1737
+ successTitle = "Email Verified!",
1738
+ successMessage = "Your email has been verified successfully. You can close this page and return to your app.",
1739
+ errorTitle = "Verification Failed"
1740
+ }) {
1741
+ if (status === "verifying") {
1742
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthContainer, { appearance, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex flex-col items-center justify-center gap-6", children: [
1743
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold text-black dark:text-white", children: verifyingTitle }),
1744
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-spin rounded-full h-12 w-12 border-b-2 border-black dark:border-white" })
1745
+ ] }) });
1746
+ }
1747
+ if (status === "error") {
1748
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthContainer, { appearance, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex flex-col items-stretch justify-center gap-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-start justify-center gap-2", children: [
1749
+ /* @__PURE__ */ jsxRuntime.jsx("h1", { className: "text-2xl font-semibold text-black dark:text-white", children: errorTitle }),
1750
+ /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed", children: [
1751
+ error || "The verification link is invalid or has expired.",
1752
+ " Please try again or contact support if the problem persists. You can close this page and return to your app."
1753
+ ] })
1754
+ ] }) }) });
1755
+ }
1756
+ return /* @__PURE__ */ jsxRuntime.jsx(AuthContainer, { appearance, children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex flex-col items-stretch justify-center gap-6", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-4", children: [
1757
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-16 h-16 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("svg", { className: "w-8 h-8 text-green-600 dark:text-green-400", fill: "none", strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M5 13l4 4L19 7" }) }) }),
1758
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { className: "text-2xl font-semibold text-black dark:text-white text-center", children: successTitle }),
1759
+ /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-neutral-600 dark:text-neutral-400 text-center", children: successMessage })
1760
+ ] }) }) });
1761
+ }
1762
+
1763
+ // src/hooks/useAuth.ts
1764
+ function useAuth() {
1765
+ const { signIn, signUp, signOut, isLoaded, isSignedIn } = useInsforge();
1766
+ return { signIn, signUp, signOut, isLoaded, isSignedIn };
1767
+ }
1768
+
1769
+ // src/hooks/useUser.ts
1770
+ function useUser() {
1771
+ const { user, isLoaded, updateUser, setUser } = useInsforge();
1772
+ return { user, isLoaded, updateUser, setUser };
1773
+ }
1774
+ var emailSchema = zod.z.string().min(1, "Email is required").email("Invalid email address");
1775
+ function createPasswordSchema(options) {
1776
+ const {
1777
+ minLength = 6,
1778
+ requireUppercase = false,
1779
+ requireLowercase = false,
1780
+ requireNumber = false,
1781
+ requireSpecialChar = false
1782
+ } = options || {};
1783
+ let schema = zod.z.string().min(minLength, `Password must be at least ${minLength} characters`);
1784
+ if (requireUppercase) {
1785
+ schema = schema.regex(/[A-Z]/, "Password must contain at least one uppercase letter");
1786
+ }
1787
+ if (requireLowercase) {
1788
+ schema = schema.regex(/[a-z]/, "Password must contain at least one lowercase letter");
1789
+ }
1790
+ if (requireNumber) {
1791
+ schema = schema.regex(/\d/, "Password must contain at least one number");
1792
+ }
1793
+ if (requireSpecialChar) {
1794
+ schema = schema.regex(
1795
+ /[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/,
1796
+ "Password must contain at least one special character"
1797
+ );
1798
+ }
1799
+ return schema;
1800
+ }
1801
+ var passwordSchema = createPasswordSchema();
1802
+ function validateEmail(email) {
1803
+ const result = emailSchema.safeParse(email);
1804
+ if (result.success) {
1805
+ return { valid: true };
1806
+ }
1807
+ return { valid: false, error: result.error.errors[0]?.message };
1808
+ }
1809
+ function validatePassword(password, options) {
1810
+ const schema = createPasswordSchema(options);
1811
+ const result = schema.safeParse(password);
1812
+ if (result.success) {
1813
+ return { valid: true };
1814
+ }
1815
+ return { valid: false, error: result.error.errors[0]?.message };
1816
+ }
1817
+ function checkPasswordStrength(password) {
1818
+ const feedback = [];
1819
+ let score = 0;
1820
+ if (password.length >= 8) {
1821
+ score += 1;
1822
+ } else {
1823
+ feedback.push("Use at least 8 characters");
1824
+ }
1825
+ if (password.length >= 12) {
1826
+ score += 1;
1827
+ }
1828
+ if (/[a-z]/.test(password) && /[A-Z]/.test(password)) {
1829
+ score += 1;
1830
+ } else {
1831
+ feedback.push("Use both uppercase and lowercase letters");
1832
+ }
1833
+ if (/\d/.test(password)) {
1834
+ score += 1;
1835
+ } else {
1836
+ feedback.push("Include at least one number");
1837
+ }
1838
+ if (/[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]/.test(password)) {
1839
+ score += 1;
1840
+ } else {
1841
+ feedback.push("Include at least one special character");
1842
+ }
1843
+ return { score, feedback };
1844
+ }
1845
+
1846
+ exports.AuthBranding = AuthBranding;
1847
+ exports.AuthContainer = AuthContainer;
1848
+ exports.AuthDivider = AuthDivider;
1849
+ exports.AuthErrorBanner = AuthErrorBanner;
1850
+ exports.AuthFormField = AuthFormField;
1851
+ exports.AuthHeader = AuthHeader;
1852
+ exports.AuthLink = AuthLink;
1853
+ exports.AuthOAuthButton = AuthOAuthButton;
1854
+ exports.AuthOAuthProviders = AuthOAuthProviders;
1855
+ exports.AuthPasswordField = AuthPasswordField;
1856
+ exports.AuthPasswordStrengthIndicator = AuthPasswordStrengthIndicator;
1857
+ exports.AuthSubmitButton = AuthSubmitButton;
1858
+ exports.AuthVerificationCodeInput = AuthVerificationCodeInput;
1859
+ exports.ForgotPasswordForm = ForgotPasswordForm;
1860
+ exports.InsforgeCallback = InsforgeCallback;
1861
+ exports.InsforgeProvider = InsforgeProvider;
1862
+ exports.Protect = Protect;
1863
+ exports.ResetPasswordForm = ResetPasswordForm;
1864
+ exports.SignIn = SignIn;
1865
+ exports.SignInForm = SignInForm;
1866
+ exports.SignUp = SignUp;
1867
+ exports.SignUpForm = SignUpForm;
1868
+ exports.SignedIn = SignedIn;
1869
+ exports.SignedOut = SignedOut;
1870
+ exports.UserButton = UserButton;
1871
+ exports.VerifyEmailStatus = VerifyEmailStatus;
1872
+ exports.checkPasswordStrength = checkPasswordStrength;
1873
+ exports.cn = cn;
1874
+ exports.createPasswordSchema = createPasswordSchema;
1875
+ exports.emailSchema = emailSchema;
1876
+ exports.getAllProviderConfigs = getAllProviderConfigs;
1877
+ exports.getProviderConfig = getProviderConfig;
1878
+ exports.passwordSchema = passwordSchema;
1879
+ exports.useAuth = useAuth;
1880
+ exports.useInsforge = useInsforge;
1881
+ exports.usePublicAuthConfig = usePublicAuthConfig;
1882
+ exports.useUser = useUser;
1883
+ exports.validateEmail = validateEmail;
1884
+ exports.validatePassword = validatePassword;
1885
+ exports.validatePasswordStrength = validatePasswordStrength;
1886
+ //# sourceMappingURL=index.js.map
1887
+ //# sourceMappingURL=index.js.map