@cedros/login-react 0.0.46 → 0.0.47

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.
Files changed (83) hide show
  1. package/README.md +32 -2
  2. package/dist/EmailRegisterForm-ByYQ43yL.cjs +1 -0
  3. package/dist/EmailRegisterForm-ByYQ43yL.cjs.map +1 -0
  4. package/dist/EmailRegisterForm-DMUcNQT-.js +781 -0
  5. package/dist/EmailRegisterForm-DMUcNQT-.js.map +1 -0
  6. package/dist/GoogleLoginButton-DEwtBp56.cjs +1 -0
  7. package/dist/GoogleLoginButton-DEwtBp56.cjs.map +1 -0
  8. package/dist/{GoogleLoginButton-C1WNu7W3.js → GoogleLoginButton-DwyxvhnL.js} +82 -80
  9. package/dist/GoogleLoginButton-DwyxvhnL.js.map +1 -0
  10. package/dist/{PermissionsSection-mm9hfp-u.js → PermissionsSection-0oNHPZzL.js} +383 -415
  11. package/dist/PermissionsSection-0oNHPZzL.js.map +1 -0
  12. package/dist/PermissionsSection-CZsJuxo4.cjs +1 -0
  13. package/dist/PermissionsSection-CZsJuxo4.cjs.map +1 -0
  14. package/dist/SolanaLoginButton-2504p6cr.cjs +1 -0
  15. package/dist/SolanaLoginButton-2504p6cr.cjs.map +1 -0
  16. package/dist/SolanaLoginButton-C7Kc_m6n.js +234 -0
  17. package/dist/SolanaLoginButton-C7Kc_m6n.js.map +1 -0
  18. package/dist/{TeamSection-Km7EwLWD.cjs → TeamSection-DN8PEHH3.cjs} +1 -1
  19. package/dist/{TeamSection-Km7EwLWD.cjs.map → TeamSection-DN8PEHH3.cjs.map} +1 -1
  20. package/dist/{TeamSection-C_eODdLU.js → TeamSection-gUyP4YDM.js} +1 -1
  21. package/dist/{TeamSection-C_eODdLU.js.map → TeamSection-gUyP4YDM.js.map} +1 -1
  22. package/dist/{UsersSection-C1Tt0ePx.cjs → UsersSection-8wLuD0fr.cjs} +1 -1
  23. package/dist/{UsersSection-C1Tt0ePx.cjs.map → UsersSection-8wLuD0fr.cjs.map} +1 -1
  24. package/dist/{UsersSection-Ct_E-MBF.js → UsersSection-CnsFrG-6.js} +1 -1
  25. package/dist/{UsersSection-Ct_E-MBF.js.map → UsersSection-CnsFrG-6.js.map} +1 -1
  26. package/dist/admin-only.cjs +1 -1
  27. package/dist/admin-only.js +1 -1
  28. package/dist/email-only.cjs +1 -1
  29. package/dist/email-only.d.ts +10 -2
  30. package/dist/email-only.js +2 -2
  31. package/dist/google-only.cjs +1 -1
  32. package/dist/google-only.d.ts +7 -2
  33. package/dist/google-only.js +2 -2
  34. package/dist/index.cjs +12 -12
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.ts +182 -11
  37. package/dist/index.js +5221 -4657
  38. package/dist/index.js.map +1 -1
  39. package/dist/login-react.css +1 -1
  40. package/dist/{plugin-Ci67QMGG.cjs → plugin-DNFjEfYp.cjs} +1 -1
  41. package/dist/{plugin-Ci67QMGG.cjs.map → plugin-DNFjEfYp.cjs.map} +1 -1
  42. package/dist/{plugin-Cm8Q6O4-.js → plugin-WYMrRNbz.js} +1 -1
  43. package/dist/{plugin-Cm8Q6O4-.js.map → plugin-WYMrRNbz.js.map} +1 -1
  44. package/dist/solana-only.cjs +1 -1
  45. package/dist/solana-only.d.ts +6 -1
  46. package/dist/solana-only.js +2 -2
  47. package/dist/useAuth-2vgrAH-M.cjs +1 -0
  48. package/dist/useAuth-2vgrAH-M.cjs.map +1 -0
  49. package/dist/{useAuth-l-itM5am.js → useAuth-CNflw856.js} +465 -469
  50. package/dist/useAuth-CNflw856.js.map +1 -0
  51. package/dist/useServerFeatures-9_aNPaa6.cjs +1 -0
  52. package/dist/useServerFeatures-9_aNPaa6.cjs.map +1 -0
  53. package/dist/useServerFeatures-DSkYdan-.js +82 -0
  54. package/dist/useServerFeatures-DSkYdan-.js.map +1 -0
  55. package/dist/{useUsersStatsSummary-BGeh3RnI.js → useUsersStatsSummary-B4_RBEYy.js} +504 -442
  56. package/dist/useUsersStatsSummary-B4_RBEYy.js.map +1 -0
  57. package/dist/useUsersStatsSummary-CHRMrlk4.cjs +1 -0
  58. package/dist/useUsersStatsSummary-CHRMrlk4.cjs.map +1 -0
  59. package/package.json +1 -1
  60. package/dist/EmailRegisterForm-p2X5QP58.js +0 -750
  61. package/dist/EmailRegisterForm-p2X5QP58.js.map +0 -1
  62. package/dist/EmailRegisterForm-xFb6MaVA.cjs +0 -1
  63. package/dist/EmailRegisterForm-xFb6MaVA.cjs.map +0 -1
  64. package/dist/GoogleLoginButton-2zNTIKMm.cjs +0 -1
  65. package/dist/GoogleLoginButton-2zNTIKMm.cjs.map +0 -1
  66. package/dist/GoogleLoginButton-C1WNu7W3.js.map +0 -1
  67. package/dist/PermissionsSection-4zcE9Zs9.cjs +0 -1
  68. package/dist/PermissionsSection-4zcE9Zs9.cjs.map +0 -1
  69. package/dist/PermissionsSection-mm9hfp-u.js.map +0 -1
  70. package/dist/SolanaLoginButton-CqdzSSeJ.cjs +0 -1
  71. package/dist/SolanaLoginButton-CqdzSSeJ.cjs.map +0 -1
  72. package/dist/SolanaLoginButton-CyeX35eU.js +0 -232
  73. package/dist/SolanaLoginButton-CyeX35eU.js.map +0 -1
  74. package/dist/sanitization-Bo_tn-L2.cjs +0 -1
  75. package/dist/sanitization-Bo_tn-L2.cjs.map +0 -1
  76. package/dist/sanitization-CQ-H1MSg.js +0 -39
  77. package/dist/sanitization-CQ-H1MSg.js.map +0 -1
  78. package/dist/useAuth-B1yS_YiD.cjs +0 -1
  79. package/dist/useAuth-B1yS_YiD.cjs.map +0 -1
  80. package/dist/useAuth-l-itM5am.js.map +0 -1
  81. package/dist/useUsersStatsSummary-BGeh3RnI.js.map +0 -1
  82. package/dist/useUsersStatsSummary-DnsYtFGX.cjs +0 -1
  83. package/dist/useUsersStatsSummary-DnsYtFGX.cjs.map +0 -1
@@ -1,750 +0,0 @@
1
- import { jsxs as f, jsx as t, Fragment as L } from "react/jsx-runtime";
2
- import { useRef as F, useState as w, useCallback as E, useEffect as M, useMemo as z, useId as W } from "react";
3
- import { L as O } from "./LoadingSpinner-6vml-zwr.js";
4
- import { E as j } from "./ErrorMessage-CcEK0pYO.js";
5
- import { u as U, A as H, h as P } from "./useCedrosLogin-CFfID-0i.js";
6
- import { b as B, v as ce } from "./validation-B8kMV3BL.js";
7
- import { s as ie } from "./sanitization-CQ-H1MSg.js";
8
- function K(i = {}) {
9
- const { maxAttempts: u = 5, windowMs: C = 6e4, showCountdown: p = !1 } = i, m = F([]), [o, v] = w(!1), [, b] = w(0), d = E(() => {
10
- b((c) => c + 1);
11
- }, []), l = E(() => {
12
- const c = Date.now();
13
- m.current = m.current.filter((e) => c - e < C);
14
- }, [C]), g = E(() => {
15
- l(), v((c) => m.current.length === 0 && c ? !1 : c);
16
- }, [l]), a = E(() => (l(), Math.max(0, u - m.current.length)), [l, u]), h = E(() => {
17
- if (l(), m.current.length === 0)
18
- return 0;
19
- const e = m.current[0] + C;
20
- return Math.max(0, e - Date.now());
21
- }, [l, C]), k = E(() => (l(), m.current.length < u), [l, u]), N = E(() => {
22
- if (g(), m.current.length >= u) {
23
- const c = h(), e = Math.ceil(c / 1e3);
24
- throw new Error(
25
- `Too many attempts. Please wait ${e} second${e === 1 ? "" : "s"} before trying again.`
26
- );
27
- }
28
- m.current.push(Date.now()), v((c) => c || !0), d();
29
- }, [g, u, h, d]), y = E(() => {
30
- m.current = [], v((c) => c && !1), d();
31
- }, [d]);
32
- return M(() => {
33
- if (!o || !p) return;
34
- const c = window.setInterval(() => {
35
- g(), d();
36
- }, 1e3);
37
- return () => {
38
- window.clearInterval(c);
39
- };
40
- }, [o, p, d, g]), {
41
- checkLimit: N,
42
- isAllowed: k,
43
- getRemainingAttempts: a,
44
- getTimeUntilReset: h,
45
- reset: y
46
- };
47
- }
48
- function le(i) {
49
- return "mfaRequired" in i && i.mfaRequired === !0;
50
- }
51
- function Z() {
52
- const { config: i, _internal: u } = U(), [C, p] = w(!1), [m, o] = w(null), {
53
- checkLimit: v,
54
- getRemainingAttempts: b,
55
- getTimeUntilReset: d,
56
- reset: l
57
- } = K({ maxAttempts: 5, windowMs: 6e4 }), g = z(
58
- () => new H({
59
- baseUrl: i.serverUrl,
60
- timeoutMs: i.requestTimeout,
61
- retryAttempts: i.retryAttempts
62
- }),
63
- [i.serverUrl, i.requestTimeout, i.retryAttempts]
64
- ), a = i.callbacks, h = E(
65
- async (y, c) => {
66
- if (!B(y)) {
67
- const e = {
68
- code: "VALIDATION_ERROR",
69
- message: "Please enter a valid email address"
70
- };
71
- throw o(e), e;
72
- }
73
- try {
74
- v();
75
- } catch (e) {
76
- const r = {
77
- code: "RATE_LIMITED",
78
- message: e instanceof Error ? e.message : "Too many attempts"
79
- };
80
- throw o(r), r;
81
- }
82
- p(!0), o(null);
83
- try {
84
- const e = await g.post("/login", {
85
- email: y,
86
- password: c
87
- });
88
- if (le(e))
89
- return {
90
- mfaRequired: !0,
91
- mfaToken: e.mfaToken,
92
- email: y,
93
- userId: e.userId
94
- };
95
- const r = e;
96
- return a?.onLoginSuccess?.(r.user, "email"), u?.handleLoginSuccess(r.user, r.tokens), l(), {
97
- mfaRequired: !1,
98
- response: r
99
- };
100
- } catch (e) {
101
- const r = P(e, "Unable to sign in. Please try again.");
102
- throw o(r), r;
103
- } finally {
104
- p(!1);
105
- }
106
- },
107
- [g, a, u, v, l]
108
- ), k = E(
109
- async (y, c, e, r) => {
110
- if (!B(y)) {
111
- const s = {
112
- code: "VALIDATION_ERROR",
113
- message: "Please enter a valid email address"
114
- };
115
- throw o(s), s;
116
- }
117
- try {
118
- v();
119
- } catch (s) {
120
- const n = {
121
- code: "RATE_LIMITED",
122
- message: s instanceof Error ? s.message : "Too many attempts"
123
- };
124
- throw o(n), n;
125
- }
126
- p(!0), o(null);
127
- try {
128
- const s = r ?? u?.getReferralCode?.() ?? void 0, n = await g.post("/register", { email: y, password: c, name: e, referral: s });
129
- return a?.onLoginSuccess?.(n.user, "email"), u?.handleLoginSuccess(n.user, n.tokens), l(), n;
130
- } catch (s) {
131
- const n = P(s, "Unable to create your account. Please try again.");
132
- throw o(n), n;
133
- } finally {
134
- p(!1);
135
- }
136
- },
137
- [g, a, u, v, l]
138
- ), N = E(() => o(null), []);
139
- return {
140
- login: h,
141
- register: k,
142
- isLoading: C,
143
- error: m,
144
- clearError: N,
145
- // M-10: Point-in-time snapshots for UI display (see interface JSDoc)
146
- remainingAttempts: b(),
147
- timeUntilReset: d()
148
- };
149
- }
150
- function q({
151
- label: i = "Password",
152
- labelAction: u,
153
- showStrengthMeter: C = !1,
154
- onValidationChange: p,
155
- error: m,
156
- className: o = "",
157
- onChange: v,
158
- value: b,
159
- ...d
160
- }) {
161
- const [l, g] = w(!1), [a, h] = w(null), k = W(), N = (c) => {
162
- const e = c.target.value;
163
- if (C || p) {
164
- const r = ce(e);
165
- h(r), p?.(r);
166
- }
167
- v?.(c);
168
- }, y = {
169
- weak: "var(--cedros-destructive, #ef4444)",
170
- fair: "var(--cedros-warning, #f59e0b)",
171
- good: "var(--cedros-success, #22c55e)",
172
- strong: "var(--cedros-success, #22c55e)"
173
- };
174
- return /* @__PURE__ */ f("div", { className: `cedros-password-input ${o}`, children: [
175
- /* @__PURE__ */ f("div", { className: "cedros-label-row", children: [
176
- /* @__PURE__ */ t("label", { htmlFor: k, className: "cedros-label", children: i }),
177
- u
178
- ] }),
179
- /* @__PURE__ */ f("div", { className: "cedros-password-wrapper", children: [
180
- /* @__PURE__ */ t(
181
- "input",
182
- {
183
- id: k,
184
- type: l ? "text" : "password",
185
- className: "cedros-input",
186
- onChange: N,
187
- value: b,
188
- "aria-invalid": m ? "true" : void 0,
189
- "aria-describedby": m ? `${k}-error` : void 0,
190
- ...d
191
- }
192
- ),
193
- /* @__PURE__ */ t(
194
- "button",
195
- {
196
- type: "button",
197
- className: "cedros-password-toggle",
198
- onClick: () => g(!l),
199
- "aria-label": l ? "Hide password" : "Show password",
200
- "aria-pressed": l,
201
- children: l ? /* @__PURE__ */ f("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: [
202
- /* @__PURE__ */ t(
203
- "path",
204
- {
205
- d: "M2.5 10s3-6 7.5-6 7.5 6 7.5 6-3 6-7.5 6-7.5-6-7.5-6z",
206
- stroke: "currentColor",
207
- strokeWidth: "1.5"
208
- }
209
- ),
210
- /* @__PURE__ */ t("circle", { cx: "10", cy: "10", r: "2.5", stroke: "currentColor", strokeWidth: "1.5" }),
211
- /* @__PURE__ */ t("path", { d: "M3 17L17 3", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
212
- ] }) : /* @__PURE__ */ f("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: [
213
- /* @__PURE__ */ t(
214
- "path",
215
- {
216
- d: "M2.5 10s3-6 7.5-6 7.5 6 7.5 6-3 6-7.5 6-7.5-6-7.5-6z",
217
- stroke: "currentColor",
218
- strokeWidth: "1.5"
219
- }
220
- ),
221
- /* @__PURE__ */ t("circle", { cx: "10", cy: "10", r: "2.5", stroke: "currentColor", strokeWidth: "1.5" })
222
- ] })
223
- }
224
- )
225
- ] }),
226
- m && /* @__PURE__ */ t("p", { id: `${k}-error`, className: "cedros-input-error", children: m }),
227
- C && a && b?.length > 0 && /* @__PURE__ */ f("div", { className: "cedros-password-strength", children: [
228
- /* @__PURE__ */ t("div", { className: "cedros-strength-bar", children: /* @__PURE__ */ t(
229
- "div",
230
- {
231
- className: "cedros-strength-fill",
232
- style: {
233
- width: `${a.strength === "weak" ? 25 : a.strength === "fair" ? 50 : a.strength === "good" ? 75 : 100}%`,
234
- backgroundColor: y[a.strength]
235
- }
236
- }
237
- ) }),
238
- /* @__PURE__ */ t("span", { className: "cedros-strength-label", children: a.strength })
239
- ] })
240
- ] });
241
- }
242
- function de() {
243
- const { config: i, _internal: u } = U(), [C, p] = w("idle"), [m, o] = w(!1), [v, b] = w(null), {
244
- checkLimit: d,
245
- getRemainingAttempts: l,
246
- getTimeUntilReset: g,
247
- reset: a
248
- } = K({ maxAttempts: 5, windowMs: 12e4 }), h = z(
249
- () => new H({
250
- baseUrl: i.serverUrl,
251
- timeoutMs: i.requestTimeout,
252
- retryAttempts: i.retryAttempts
253
- }),
254
- [i.serverUrl, i.requestTimeout, i.retryAttempts]
255
- ), k = E(
256
- async (c, e) => {
257
- const r = /^[A-Z0-9]{16}$/i.test(e) || /^[A-Z0-9]{4}(-[A-Z0-9]{4}){3}$/i.test(e);
258
- if (!(/^\d{6}$/.test(e) || r)) {
259
- const n = {
260
- code: "VALIDATION_ERROR",
261
- message: "Please enter a valid 6-digit code or recovery code"
262
- };
263
- throw b(n), n;
264
- }
265
- try {
266
- d();
267
- } catch (n) {
268
- const R = {
269
- code: "RATE_LIMITED",
270
- message: n instanceof Error ? n.message : "Too many attempts"
271
- };
272
- throw b(R), R;
273
- }
274
- o(!0), b(null), p("verifying");
275
- try {
276
- const n = await h.post("/login/mfa", { mfaToken: c, code: e });
277
- return p("success"), a(), u && n.user && n.tokens && u.handleLoginSuccess(n.user, n.tokens), n;
278
- } catch (n) {
279
- const R = P(n, "Incorrect verification code. Please check and try again.");
280
- throw b(R), p("error"), R;
281
- } finally {
282
- o(!1);
283
- }
284
- },
285
- [h, u, d, a]
286
- ), N = E(() => b(null), []), y = E(() => {
287
- b(null), p("idle"), o(!1);
288
- }, []);
289
- return {
290
- state: C,
291
- isLoading: m,
292
- error: v,
293
- verifyTotp: k,
294
- clearError: N,
295
- reset: y,
296
- // Point-in-time snapshots for UI display
297
- remainingAttempts: l(),
298
- timeUntilReset: g()
299
- };
300
- }
301
- const T = 6;
302
- function ue({
303
- value: i = "",
304
- onChange: u,
305
- onComplete: C,
306
- disabled: p = !1,
307
- error: m,
308
- autoFocus: o = !1,
309
- className: v = ""
310
- }) {
311
- const b = F([]), [d, l] = w(i.padEnd(T, "")), g = W();
312
- M(() => {
313
- l(i.padEnd(T, ""));
314
- }, [i]);
315
- const a = E((e) => {
316
- e >= 0 && e < T && b.current[e]?.focus();
317
- }, []), h = E(
318
- (e) => {
319
- const r = e.replace(/\D/g, "").slice(0, T);
320
- l(r.padEnd(T, "")), u?.(r), r.length === T && C?.(r);
321
- },
322
- [u, C]
323
- ), k = E(
324
- (e, r) => {
325
- if (!/^\d?$/.test(r)) return;
326
- const s = d.split("");
327
- s[e] = r;
328
- const n = s.join("").replace(/ /g, "");
329
- h(n), r && e < T - 1 && a(e + 1);
330
- },
331
- [d, h, a]
332
- ), N = E(
333
- (e, r) => {
334
- if (r.key === "Backspace") {
335
- r.preventDefault();
336
- const s = d.split("");
337
- s[e] && s[e] !== " " ? (s[e] = " ", h(s.join("").replace(/ /g, ""))) : e > 0 && (s[e - 1] = " ", h(s.join("").replace(/ /g, "")), a(e - 1));
338
- } else r.key === "ArrowLeft" && e > 0 ? (r.preventDefault(), a(e - 1)) : r.key === "ArrowRight" && e < T - 1 && (r.preventDefault(), a(e + 1));
339
- },
340
- [d, h, a]
341
- ), y = E(
342
- (e) => {
343
- e.preventDefault();
344
- const s = e.clipboardData.getData("text").replace(/\D/g, "").slice(0, T);
345
- s && (h(s), a(Math.min(s.length, T - 1)));
346
- },
347
- [h, a]
348
- ), c = E((e) => {
349
- e.target.select();
350
- }, []);
351
- return M(() => {
352
- o && !p && b.current[0]?.focus();
353
- }, [o, p]), /* @__PURE__ */ f("div", { className: `cedros-otp-input ${v}`, children: [
354
- /* @__PURE__ */ t("div", { className: "cedros-otp-slots", role: "group", "aria-label": "One-time password", children: Array.from({ length: T }).map((e, r) => /* @__PURE__ */ t(
355
- "input",
356
- {
357
- ref: (s) => {
358
- b.current[r] = s;
359
- },
360
- id: `${g}-${r}`,
361
- type: "text",
362
- inputMode: "numeric",
363
- pattern: "[0-9]*",
364
- maxLength: 1,
365
- className: `cedros-otp-slot ${m ? "cedros-otp-slot-error" : ""}`,
366
- value: d[r] === " " ? "" : d[r] || "",
367
- onChange: (s) => k(r, s.target.value),
368
- onKeyDown: (s) => N(r, s),
369
- onPaste: y,
370
- onFocus: c,
371
- disabled: p,
372
- autoComplete: "one-time-code",
373
- "aria-label": `Digit ${r + 1}`,
374
- "aria-invalid": m ? "true" : void 0
375
- },
376
- r
377
- )) }),
378
- m && /* @__PURE__ */ t("p", { className: "cedros-otp-error", role: "alert", children: m })
379
- ] });
380
- }
381
- function me({
382
- mfaToken: i,
383
- email: u,
384
- onSuccess: C,
385
- onBack: p,
386
- className: m = ""
387
- }) {
388
- const { verifyTotp: o, isLoading: v, error: b, clearError: d } = de(), [l, g] = w(""), [a, h] = w(!1), [k, N] = w(""), y = async (r) => {
389
- const s = r || (a ? k : l);
390
- if (s)
391
- try {
392
- await o(i, s), C?.();
393
- } catch {
394
- a ? N("") : g("");
395
- }
396
- }, c = (r) => {
397
- y(r);
398
- }, e = () => {
399
- h(!a), d(), g(""), N("");
400
- };
401
- return /* @__PURE__ */ f("div", { className: `cedros-totp-verify ${m}`, children: [
402
- /* @__PURE__ */ f("div", { className: "cedros-totp-verify-header", children: [
403
- /* @__PURE__ */ f(
404
- "svg",
405
- {
406
- className: "cedros-totp-verify-icon",
407
- width: "48",
408
- height: "48",
409
- viewBox: "0 0 48 48",
410
- fill: "none",
411
- "aria-hidden": "true",
412
- children: [
413
- /* @__PURE__ */ t("rect", { x: "8", y: "20", width: "32", height: "24", rx: "4", stroke: "currentColor", strokeWidth: "2" }),
414
- /* @__PURE__ */ t(
415
- "path",
416
- {
417
- d: "M16 20V14a8 8 0 1 1 16 0v6",
418
- stroke: "currentColor",
419
- strokeWidth: "2",
420
- strokeLinecap: "round"
421
- }
422
- ),
423
- /* @__PURE__ */ t("circle", { cx: "24", cy: "32", r: "3", fill: "currentColor" })
424
- ]
425
- }
426
- ),
427
- /* @__PURE__ */ t("h3", { className: "cedros-totp-title", children: "Two-factor authentication" }),
428
- /* @__PURE__ */ t("p", { className: "cedros-totp-description", children: a ? "Enter one of your recovery codes to sign in." : "Enter the 6-digit code from your authenticator app." }),
429
- u && /* @__PURE__ */ t("p", { className: "cedros-totp-email", children: u })
430
- ] }),
431
- a ? /* @__PURE__ */ f("div", { className: "cedros-totp-backup-input", children: [
432
- /* @__PURE__ */ t(
433
- "input",
434
- {
435
- type: "text",
436
- className: `cedros-input ${b ? "cedros-input-error" : ""}`,
437
- placeholder: "Enter recovery code",
438
- value: k,
439
- onChange: (r) => {
440
- N(r.target.value.toUpperCase()), d();
441
- },
442
- onKeyDown: (r) => {
443
- r.key === "Enter" && k && y();
444
- },
445
- disabled: v,
446
- autoFocus: !0,
447
- autoComplete: "one-time-code"
448
- }
449
- ),
450
- b && /* @__PURE__ */ t("p", { className: "cedros-input-error", role: "alert", children: b.message })
451
- ] }) : /* @__PURE__ */ t(
452
- ue,
453
- {
454
- value: l,
455
- onChange: (r) => {
456
- g(r), d();
457
- },
458
- onComplete: c,
459
- disabled: v,
460
- error: b?.message,
461
- autoFocus: !0
462
- }
463
- ),
464
- /* @__PURE__ */ t(
465
- "button",
466
- {
467
- type: "button",
468
- className: "cedros-button cedros-button-primary cedros-button-md cedros-button-full",
469
- onClick: () => y(),
470
- disabled: v || (a ? !k : l.length !== 6),
471
- children: v ? /* @__PURE__ */ f(L, { children: [
472
- /* @__PURE__ */ t(O, { size: "sm" }),
473
- /* @__PURE__ */ t("span", { children: "Verifying..." })
474
- ] }) : "Verify"
475
- }
476
- ),
477
- /* @__PURE__ */ f("div", { className: "cedros-totp-verify-footer", children: [
478
- /* @__PURE__ */ t(
479
- "button",
480
- {
481
- type: "button",
482
- className: "cedros-link cedros-link-sm",
483
- onClick: e,
484
- disabled: v,
485
- children: a ? "Use authenticator app" : "Use a recovery code"
486
- }
487
- ),
488
- p && /* @__PURE__ */ f(L, { children: [
489
- /* @__PURE__ */ t("span", { className: "cedros-totp-verify-divider", children: "•" }),
490
- /* @__PURE__ */ t(
491
- "button",
492
- {
493
- type: "button",
494
- className: "cedros-link cedros-link-sm",
495
- onClick: p,
496
- disabled: v,
497
- children: "Back to login"
498
- }
499
- )
500
- ] })
501
- ] })
502
- ] });
503
- }
504
- function ke({
505
- onSuccess: i,
506
- onSwitchToRegister: u,
507
- onForgotPassword: C,
508
- className: p = ""
509
- }) {
510
- const { login: m, isLoading: o, error: v, clearError: b } = Z(), [d, l] = w(""), [g, a] = w(""), [h, k] = w(null), [N, y] = w(""), c = async (s) => {
511
- s.preventDefault();
512
- try {
513
- const n = await m(d, g);
514
- n.mfaRequired ? (k(n.mfaToken), y(n.email)) : i?.();
515
- } catch {
516
- }
517
- }, e = () => {
518
- k(null), y(""), i?.();
519
- }, r = () => {
520
- k(null), y(""), a("");
521
- };
522
- return h ? /* @__PURE__ */ t(
523
- me,
524
- {
525
- mfaToken: h,
526
- email: N,
527
- onSuccess: e,
528
- onBack: r,
529
- className: p
530
- }
531
- ) : /* @__PURE__ */ f("form", { onSubmit: c, className: `cedros-form ${p}`, children: [
532
- /* @__PURE__ */ f("div", { className: "cedros-form-field", children: [
533
- /* @__PURE__ */ t("label", { htmlFor: "email", className: "cedros-label", children: "Email" }),
534
- /* @__PURE__ */ t(
535
- "input",
536
- {
537
- id: "email",
538
- type: "email",
539
- className: "cedros-input",
540
- value: d,
541
- onChange: (s) => l(s.target.value),
542
- placeholder: "you@example.com",
543
- required: !0,
544
- "aria-required": "true",
545
- autoComplete: "email",
546
- disabled: o
547
- }
548
- )
549
- ] }),
550
- /* @__PURE__ */ t("div", { className: "cedros-form-field", children: /* @__PURE__ */ t(
551
- q,
552
- {
553
- value: g,
554
- onChange: (s) => a(s.target.value),
555
- placeholder: "Enter your password",
556
- required: !0,
557
- autoComplete: "current-password",
558
- disabled: o,
559
- labelAction: C ? /* @__PURE__ */ t(
560
- "button",
561
- {
562
- type: "button",
563
- className: "cedros-link cedros-link-muted cedros-link-sm",
564
- onClick: C,
565
- children: "Forgot your password?"
566
- }
567
- ) : void 0
568
- }
569
- ) }),
570
- /* @__PURE__ */ t(j, { error: v, onDismiss: b }),
571
- /* @__PURE__ */ t(
572
- "button",
573
- {
574
- type: "submit",
575
- className: "cedros-button cedros-button-primary cedros-button-md cedros-button-full",
576
- disabled: o || !d || !g,
577
- "aria-busy": o,
578
- children: o ? /* @__PURE__ */ f(L, { children: [
579
- /* @__PURE__ */ t(O, { size: "sm", announce: !0, label: "Signing in" }),
580
- /* @__PURE__ */ t("span", { children: "Signing in..." })
581
- ] }) : "Sign in"
582
- }
583
- ),
584
- u && /* @__PURE__ */ f("p", { className: "cedros-form-footer", children: [
585
- "Don't have an account?",
586
- " ",
587
- /* @__PURE__ */ t("button", { type: "button", className: "cedros-link cedros-link-muted", onClick: u, children: "Sign up" })
588
- ] })
589
- ] });
590
- }
591
- function Ce({
592
- onSuccess: i,
593
- onSwitchToLogin: u,
594
- className: C = ""
595
- }) {
596
- const { config: p } = U(), { register: m, isLoading: o, error: v, clearError: b } = Z(), [d, l] = w(""), [g, a] = w(""), [h, k] = w(""), [N, y] = w(""), [c, e] = w(null), [r, s] = w(null), n = p.forms?.termsOfService, R = p.forms?.emailOptIn, D = n?.show ?? !1, I = n?.required ?? !0, Y = n?.defaultChecked ?? !1, $ = n?.label ?? "I agree to the Terms of Service", G = n?.url, x = ie(G), J = R?.show ?? !1, Q = R?.defaultChecked ?? !1, X = R?.label ?? "Send me updates and news", [S, ee] = w(Y), [te, re] = w(Q), V = h === N, se = c?.isValid ?? !1, _ = g && h && N && V && se && (!D || !I || S) && !o, oe = async (A) => {
597
- if (A.preventDefault(), s(null), D && I && !S) {
598
- s({
599
- code: "VALIDATION_ERROR",
600
- message: "You must agree to the Terms of Service to continue"
601
- });
602
- return;
603
- }
604
- if (_)
605
- try {
606
- await m(g, h, d || void 0), i?.();
607
- } catch {
608
- }
609
- }, ae = v || r, ne = () => {
610
- b(), s(null);
611
- };
612
- return /* @__PURE__ */ f("form", { onSubmit: oe, className: `cedros-form ${C}`, children: [
613
- /* @__PURE__ */ f("div", { className: "cedros-form-field", children: [
614
- /* @__PURE__ */ f("label", { htmlFor: "name", className: "cedros-label", children: [
615
- "Name ",
616
- /* @__PURE__ */ t("span", { className: "cedros-optional", children: "(optional)" })
617
- ] }),
618
- /* @__PURE__ */ t(
619
- "input",
620
- {
621
- id: "name",
622
- type: "text",
623
- className: "cedros-input",
624
- value: d,
625
- onChange: (A) => l(A.target.value),
626
- placeholder: "Your name",
627
- autoComplete: "name",
628
- disabled: o
629
- }
630
- )
631
- ] }),
632
- /* @__PURE__ */ f("div", { className: "cedros-form-field", children: [
633
- /* @__PURE__ */ t("label", { htmlFor: "register-email", className: "cedros-label", children: "Email" }),
634
- /* @__PURE__ */ t(
635
- "input",
636
- {
637
- id: "register-email",
638
- type: "email",
639
- className: "cedros-input",
640
- value: g,
641
- onChange: (A) => a(A.target.value),
642
- placeholder: "you@example.com",
643
- required: !0,
644
- "aria-required": "true",
645
- autoComplete: "email",
646
- disabled: o
647
- }
648
- )
649
- ] }),
650
- /* @__PURE__ */ t("div", { className: "cedros-form-field", children: /* @__PURE__ */ t(
651
- q,
652
- {
653
- value: h,
654
- onChange: (A) => k(A.target.value),
655
- placeholder: "Create a password",
656
- required: !0,
657
- autoComplete: "new-password",
658
- disabled: o,
659
- showStrengthMeter: !0,
660
- onValidationChange: e
661
- }
662
- ) }),
663
- /* @__PURE__ */ t("div", { className: "cedros-form-field", children: /* @__PURE__ */ t(
664
- q,
665
- {
666
- label: "Confirm Password",
667
- value: N,
668
- onChange: (A) => y(A.target.value),
669
- placeholder: "Confirm your password",
670
- required: !0,
671
- autoComplete: "new-password",
672
- disabled: o,
673
- "aria-invalid": N && !V ? "true" : void 0,
674
- error: N && !V ? "Passwords do not match" : void 0
675
- }
676
- ) }),
677
- D && /* @__PURE__ */ t("div", { className: "cedros-form-field cedros-checkbox-field", children: /* @__PURE__ */ f("label", { className: "cedros-checkbox-label", children: [
678
- /* @__PURE__ */ t(
679
- "input",
680
- {
681
- type: "checkbox",
682
- className: "cedros-checkbox",
683
- checked: S,
684
- onChange: (A) => ee(A.target.checked),
685
- disabled: o,
686
- "aria-required": I
687
- }
688
- ),
689
- /* @__PURE__ */ f("span", { className: "cedros-checkbox-text", children: [
690
- x ? /* @__PURE__ */ f(L, { children: [
691
- $.replace("Terms of Service", "").trim() || "I agree to the",
692
- " ",
693
- /* @__PURE__ */ t(
694
- "a",
695
- {
696
- href: x,
697
- target: "_blank",
698
- rel: "noopener noreferrer",
699
- className: "cedros-link",
700
- children: "Terms of Service"
701
- }
702
- )
703
- ] }) : $,
704
- I && /* @__PURE__ */ t("span", { className: "cedros-required", children: "*" })
705
- ] })
706
- ] }) }),
707
- J && /* @__PURE__ */ t("div", { className: "cedros-form-field cedros-checkbox-field", children: /* @__PURE__ */ f("label", { className: "cedros-checkbox-label", children: [
708
- /* @__PURE__ */ t(
709
- "input",
710
- {
711
- type: "checkbox",
712
- className: "cedros-checkbox",
713
- checked: te,
714
- onChange: (A) => re(A.target.checked),
715
- disabled: o
716
- }
717
- ),
718
- /* @__PURE__ */ t("span", { className: "cedros-checkbox-text", children: X })
719
- ] }) }),
720
- /* @__PURE__ */ t(j, { error: ae, onDismiss: ne }),
721
- /* @__PURE__ */ t(
722
- "button",
723
- {
724
- type: "submit",
725
- className: "cedros-button cedros-button-primary cedros-button-md cedros-button-full",
726
- disabled: !_,
727
- "aria-busy": o,
728
- children: o ? /* @__PURE__ */ f(L, { children: [
729
- /* @__PURE__ */ t(O, { size: "sm", announce: !0, label: "Creating account" }),
730
- /* @__PURE__ */ t("span", { children: "Creating account..." })
731
- ] }) : "Create account"
732
- }
733
- ),
734
- u && /* @__PURE__ */ f("p", { className: "cedros-form-footer", children: [
735
- "Already have an account?",
736
- " ",
737
- /* @__PURE__ */ t("button", { type: "button", className: "cedros-link cedros-link-muted", onClick: u, children: "Sign in" })
738
- ] })
739
- ] });
740
- }
741
- export {
742
- ke as E,
743
- ue as O,
744
- q as P,
745
- me as T,
746
- Ce as a,
747
- K as b,
748
- de as c,
749
- Z as u
750
- };