@cedros/login-react 0.0.39 → 0.0.41

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 (94) hide show
  1. package/dist/{AuthenticationSettings-DUXpyiJ5.js → AuthenticationSettings-CSoFp-_2.js} +1 -1
  2. package/dist/{AuthenticationSettings-DUXpyiJ5.js.map → AuthenticationSettings-CSoFp-_2.js.map} +1 -1
  3. package/dist/{AuthenticationSettings-Dk1LX0CK.cjs → AuthenticationSettings-Cu5Z2mTC.cjs} +1 -1
  4. package/dist/{AuthenticationSettings-Dk1LX0CK.cjs.map → AuthenticationSettings-Cu5Z2mTC.cjs.map} +1 -1
  5. package/dist/{AuthenticationSettings-BF_7Ea6Z.js → AuthenticationSettings-D4ExU-2a.js} +1 -1
  6. package/dist/{AuthenticationSettings-BF_7Ea6Z.js.map → AuthenticationSettings-D4ExU-2a.js.map} +1 -1
  7. package/dist/{AuthenticationSettings-BMDrCVSf.cjs → AuthenticationSettings-DABzZHuI.cjs} +1 -1
  8. package/dist/{AuthenticationSettings-BMDrCVSf.cjs.map → AuthenticationSettings-DABzZHuI.cjs.map} +1 -1
  9. package/dist/AutosaveStatus-B1A1zORa.cjs +1 -0
  10. package/dist/AutosaveStatus-B1A1zORa.cjs.map +1 -0
  11. package/dist/{AutosaveStatus-CSZsp6w7.js → AutosaveStatus-DMjvXzP2.js} +526 -341
  12. package/dist/AutosaveStatus-DMjvXzP2.js.map +1 -0
  13. package/dist/CreditSystemSettings-BWuiRTtA.cjs +1 -0
  14. package/dist/CreditSystemSettings-BWuiRTtA.cjs.map +1 -0
  15. package/dist/{CreditSystemSettings-Cj21_Ug8.js → CreditSystemSettings-BjQdysRS.js} +1 -1
  16. package/dist/{CreditSystemSettings-Cj21_Ug8.js.map → CreditSystemSettings-BjQdysRS.js.map} +1 -1
  17. package/dist/{CreditSystemSettings-CLImarX-.cjs → CreditSystemSettings-DfSfQVE8.cjs} +1 -1
  18. package/dist/{CreditSystemSettings-CLImarX-.cjs.map → CreditSystemSettings-DfSfQVE8.cjs.map} +1 -1
  19. package/dist/{CreditSystemSettings-Buu7Y-7I.js → CreditSystemSettings-Du3ac0ID.js} +12 -7
  20. package/dist/CreditSystemSettings-Du3ac0ID.js.map +1 -0
  21. package/dist/EmailRegisterForm-CMXsa-_r.js +750 -0
  22. package/dist/EmailRegisterForm-CMXsa-_r.js.map +1 -0
  23. package/dist/EmailRegisterForm-i7f4St2N.cjs +1 -0
  24. package/dist/EmailRegisterForm-i7f4St2N.cjs.map +1 -0
  25. package/dist/EmailSettings-ASDHfI0K.js +86 -0
  26. package/dist/EmailSettings-ASDHfI0K.js.map +1 -0
  27. package/dist/EmailSettings-BcHo0cqk.cjs +1 -0
  28. package/dist/EmailSettings-BcHo0cqk.cjs.map +1 -0
  29. package/dist/{EmailSettings-CmxxnrA9.js → EmailSettings-CjngJwDS.js} +1 -1
  30. package/dist/{EmailSettings-CmxxnrA9.js.map → EmailSettings-CjngJwDS.js.map} +1 -1
  31. package/dist/{EmailSettings-9sdEAONl.cjs → EmailSettings-CswtKXhb.cjs} +1 -1
  32. package/dist/{EmailSettings-9sdEAONl.cjs.map → EmailSettings-CswtKXhb.cjs.map} +1 -1
  33. package/dist/{EmbeddedWalletSettings-BuLN_Uqc.cjs → EmbeddedWalletSettings-BXlboZ9-.cjs} +1 -1
  34. package/dist/{EmbeddedWalletSettings-BuLN_Uqc.cjs.map → EmbeddedWalletSettings-BXlboZ9-.cjs.map} +1 -1
  35. package/dist/{EmbeddedWalletSettings-DGq-kXbw.cjs → EmbeddedWalletSettings-BkwIbTkL.cjs} +1 -1
  36. package/dist/{EmbeddedWalletSettings-DGq-kXbw.cjs.map → EmbeddedWalletSettings-BkwIbTkL.cjs.map} +1 -1
  37. package/dist/{EmbeddedWalletSettings-CHkkCjyR.js → EmbeddedWalletSettings-CPLbqlxJ.js} +1 -1
  38. package/dist/{EmbeddedWalletSettings-CHkkCjyR.js.map → EmbeddedWalletSettings-CPLbqlxJ.js.map} +1 -1
  39. package/dist/{EmbeddedWalletSettings-M-D5N0eY.js → EmbeddedWalletSettings-CUY_X7Vj.js} +1 -1
  40. package/dist/{EmbeddedWalletSettings-M-D5N0eY.js.map → EmbeddedWalletSettings-CUY_X7Vj.js.map} +1 -1
  41. package/dist/{PermissionsSection-DEMVp7X3.cjs → PermissionsSection-B-6DJnN8.cjs} +1 -1
  42. package/dist/{PermissionsSection-DEMVp7X3.cjs.map → PermissionsSection-B-6DJnN8.cjs.map} +1 -1
  43. package/dist/{PermissionsSection-DNzOL1xW.js → PermissionsSection-BeFhIgQy.js} +22 -18
  44. package/dist/{PermissionsSection-DNzOL1xW.js.map → PermissionsSection-BeFhIgQy.js.map} +1 -1
  45. package/dist/{ServerSettings-DQemMrNv.js → ServerSettings-B9PNMse1.js} +1 -1
  46. package/dist/{ServerSettings-DQemMrNv.js.map → ServerSettings-B9PNMse1.js.map} +1 -1
  47. package/dist/{ServerSettings-qxi8aZO7.js → ServerSettings-BLoWX7KG.js} +1 -1
  48. package/dist/{ServerSettings-qxi8aZO7.js.map → ServerSettings-BLoWX7KG.js.map} +1 -1
  49. package/dist/{ServerSettings-CMmH5pZv.cjs → ServerSettings-BygCxOTY.cjs} +1 -1
  50. package/dist/{ServerSettings-CMmH5pZv.cjs.map → ServerSettings-BygCxOTY.cjs.map} +1 -1
  51. package/dist/{ServerSettings-DfimU7ay.cjs → ServerSettings-CgBdYspU.cjs} +1 -1
  52. package/dist/{ServerSettings-DfimU7ay.cjs.map → ServerSettings-CgBdYspU.cjs.map} +1 -1
  53. package/dist/{TeamSection-DopbZClq.cjs → TeamSection-B1t1tU-_.cjs} +1 -1
  54. package/dist/{TeamSection-DopbZClq.cjs.map → TeamSection-B1t1tU-_.cjs.map} +1 -1
  55. package/dist/{TeamSection-CoMXyFtz.js → TeamSection-DbSYDRdI.js} +1 -1
  56. package/dist/{TeamSection-CoMXyFtz.js.map → TeamSection-DbSYDRdI.js.map} +1 -1
  57. package/dist/{WebhookSettings-B8hAwhZ2.js → WebhookSettings-C-7Yxueu.js} +1 -1
  58. package/dist/{WebhookSettings-B8hAwhZ2.js.map → WebhookSettings-C-7Yxueu.js.map} +1 -1
  59. package/dist/{WebhookSettings-8QAqvkkO.js → WebhookSettings-C923ZSKa.js} +1 -1
  60. package/dist/{WebhookSettings-8QAqvkkO.js.map → WebhookSettings-C923ZSKa.js.map} +1 -1
  61. package/dist/{WebhookSettings-0sgWRI3U.cjs → WebhookSettings-CbU3cfTJ.cjs} +1 -1
  62. package/dist/{WebhookSettings-0sgWRI3U.cjs.map → WebhookSettings-CbU3cfTJ.cjs.map} +1 -1
  63. package/dist/{WebhookSettings-B6Y3Tnjv.cjs → WebhookSettings-D19u9Uok.cjs} +1 -1
  64. package/dist/{WebhookSettings-B6Y3Tnjv.cjs.map → WebhookSettings-D19u9Uok.cjs.map} +1 -1
  65. package/dist/admin-only.cjs +1 -1
  66. package/dist/admin-only.js +1 -1
  67. package/dist/email-only.cjs +1 -1
  68. package/dist/email-only.d.ts +1 -1
  69. package/dist/email-only.js +1 -1
  70. package/dist/index.cjs +13 -13
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.d.ts +5 -8
  73. package/dist/index.js +4639 -4480
  74. package/dist/index.js.map +1 -1
  75. package/dist/login-react.css +1 -1
  76. package/dist/{plugin-C_NDZ2-D.js → plugin-BiftIhZe.js} +1 -1
  77. package/dist/{plugin-C_NDZ2-D.js.map → plugin-BiftIhZe.js.map} +1 -1
  78. package/dist/{plugin-CUxpAjL-.cjs → plugin-BtQdI_Ay.cjs} +1 -1
  79. package/dist/{plugin-CUxpAjL-.cjs.map → plugin-BtQdI_Ay.cjs.map} +1 -1
  80. package/package.json +1 -1
  81. package/dist/AutosaveStatus-BKsCIvPj.cjs +0 -1
  82. package/dist/AutosaveStatus-BKsCIvPj.cjs.map +0 -1
  83. package/dist/AutosaveStatus-CSZsp6w7.js.map +0 -1
  84. package/dist/CreditSystemSettings-Buu7Y-7I.js.map +0 -1
  85. package/dist/CreditSystemSettings-C2HkyMXy.cjs +0 -1
  86. package/dist/CreditSystemSettings-C2HkyMXy.cjs.map +0 -1
  87. package/dist/EmailRegisterForm-CNjYrqU6.cjs +0 -1
  88. package/dist/EmailRegisterForm-CNjYrqU6.cjs.map +0 -1
  89. package/dist/EmailRegisterForm-D2VaJouj.js +0 -750
  90. package/dist/EmailRegisterForm-D2VaJouj.js.map +0 -1
  91. package/dist/EmailSettings-DRfOF0Sf.js +0 -78
  92. package/dist/EmailSettings-DRfOF0Sf.js.map +0 -1
  93. package/dist/EmailSettings-eLlzzI5D.cjs +0 -1
  94. package/dist/EmailSettings-eLlzzI5D.cjs.map +0 -1
@@ -1,750 +0,0 @@
1
- import { jsxs as h, jsx as r, Fragment as R } 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(c = {}) {
9
- const { maxAttempts: u = 5, windowMs: C = 6e4, showCountdown: m = !1 } = c, d = F([]), [s, b] = w(!1), [, g] = w(0), l = E(() => {
10
- g((n) => n + 1);
11
- }, []), i = E(() => {
12
- const n = Date.now();
13
- d.current = d.current.filter((t) => n - t < C);
14
- }, [C]), f = E(() => {
15
- i(), b((n) => d.current.length === 0 && n ? !1 : n);
16
- }, [i]), a = E(() => (i(), Math.max(0, u - d.current.length)), [i, u]), p = E(() => {
17
- if (i(), d.current.length === 0)
18
- return 0;
19
- const t = d.current[0] + C;
20
- return Math.max(0, t - Date.now());
21
- }, [i, C]), k = E(() => (i(), d.current.length < u), [i, u]), N = E(() => {
22
- if (f(), d.current.length >= u) {
23
- const n = p(), t = Math.ceil(n / 1e3);
24
- throw new Error(
25
- `Too many attempts. Please wait ${t} second${t === 1 ? "" : "s"} before trying again.`
26
- );
27
- }
28
- d.current.push(Date.now()), b((n) => n || !0), l();
29
- }, [f, u, p, l]), y = E(() => {
30
- d.current = [], b((n) => n && !1), l();
31
- }, [l]);
32
- return M(() => {
33
- if (!s || !m) return;
34
- const n = window.setInterval(() => {
35
- f(), l();
36
- }, 1e3);
37
- return () => {
38
- window.clearInterval(n);
39
- };
40
- }, [s, m, l, f]), {
41
- checkLimit: N,
42
- isAllowed: k,
43
- getRemainingAttempts: a,
44
- getTimeUntilReset: p,
45
- reset: y
46
- };
47
- }
48
- function le(c) {
49
- return "mfaRequired" in c && c.mfaRequired === !0;
50
- }
51
- function Z() {
52
- const { config: c, _internal: u } = U(), [C, m] = w(!1), [d, s] = w(null), {
53
- checkLimit: b,
54
- getRemainingAttempts: g,
55
- getTimeUntilReset: l,
56
- reset: i
57
- } = K({ maxAttempts: 5, windowMs: 6e4 }), f = z(
58
- () => new H({
59
- baseUrl: c.serverUrl,
60
- timeoutMs: c.requestTimeout,
61
- retryAttempts: c.retryAttempts
62
- }),
63
- [c.serverUrl, c.requestTimeout, c.retryAttempts]
64
- ), a = c.callbacks, p = E(
65
- async (y, n) => {
66
- if (!B(y)) {
67
- const t = {
68
- code: "VALIDATION_ERROR",
69
- message: "Please enter a valid email address"
70
- };
71
- throw s(t), t;
72
- }
73
- try {
74
- b();
75
- } catch (t) {
76
- const e = {
77
- code: "RATE_LIMITED",
78
- message: t instanceof Error ? t.message : "Too many attempts"
79
- };
80
- throw s(e), e;
81
- }
82
- m(!0), s(null);
83
- try {
84
- const t = await f.post("/login", {
85
- email: y,
86
- password: n
87
- });
88
- if (le(t))
89
- return {
90
- mfaRequired: !0,
91
- mfaToken: t.mfaToken,
92
- email: y,
93
- userId: t.userId
94
- };
95
- const e = t;
96
- return a?.onLoginSuccess?.(e.user, "email"), u?.handleLoginSuccess(e.user, e.tokens), i(), {
97
- mfaRequired: !1,
98
- response: e
99
- };
100
- } catch (t) {
101
- const e = P(t, "Unable to sign in. Please try again.");
102
- throw s(e), e;
103
- } finally {
104
- m(!1);
105
- }
106
- },
107
- [f, a, u, b, i]
108
- ), k = E(
109
- async (y, n, t) => {
110
- if (!B(y)) {
111
- const e = {
112
- code: "VALIDATION_ERROR",
113
- message: "Please enter a valid email address"
114
- };
115
- throw s(e), e;
116
- }
117
- try {
118
- b();
119
- } catch (e) {
120
- const o = {
121
- code: "RATE_LIMITED",
122
- message: e instanceof Error ? e.message : "Too many attempts"
123
- };
124
- throw s(o), o;
125
- }
126
- m(!0), s(null);
127
- try {
128
- const e = await f.post("/register", { email: y, password: n, name: t });
129
- return a?.onLoginSuccess?.(e.user, "email"), u?.handleLoginSuccess(e.user, e.tokens), i(), e;
130
- } catch (e) {
131
- const o = P(e, "Unable to create your account. Please try again.");
132
- throw s(o), o;
133
- } finally {
134
- m(!1);
135
- }
136
- },
137
- [f, a, u, b, i]
138
- ), N = E(() => s(null), []);
139
- return {
140
- login: p,
141
- register: k,
142
- isLoading: C,
143
- error: d,
144
- clearError: N,
145
- // M-10: Point-in-time snapshots for UI display (see interface JSDoc)
146
- remainingAttempts: g(),
147
- timeUntilReset: l()
148
- };
149
- }
150
- function q({
151
- label: c = "Password",
152
- labelAction: u,
153
- showStrengthMeter: C = !1,
154
- onValidationChange: m,
155
- error: d,
156
- className: s = "",
157
- onChange: b,
158
- value: g,
159
- ...l
160
- }) {
161
- const [i, f] = w(!1), [a, p] = w(null), k = W(), N = (n) => {
162
- const t = n.target.value;
163
- if (C || m) {
164
- const e = ce(t);
165
- p(e), m?.(e);
166
- }
167
- b?.(n);
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__ */ h("div", { className: `cedros-password-input ${s}`, children: [
175
- /* @__PURE__ */ h("div", { className: "cedros-label-row", children: [
176
- /* @__PURE__ */ r("label", { htmlFor: k, className: "cedros-label", children: c }),
177
- u
178
- ] }),
179
- /* @__PURE__ */ h("div", { className: "cedros-password-wrapper", children: [
180
- /* @__PURE__ */ r(
181
- "input",
182
- {
183
- id: k,
184
- type: i ? "text" : "password",
185
- className: "cedros-input",
186
- onChange: N,
187
- value: g,
188
- "aria-invalid": d ? "true" : void 0,
189
- "aria-describedby": d ? `${k}-error` : void 0,
190
- ...l
191
- }
192
- ),
193
- /* @__PURE__ */ r(
194
- "button",
195
- {
196
- type: "button",
197
- className: "cedros-password-toggle",
198
- onClick: () => f(!i),
199
- "aria-label": i ? "Hide password" : "Show password",
200
- "aria-pressed": i,
201
- children: i ? /* @__PURE__ */ h("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: [
202
- /* @__PURE__ */ r(
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__ */ r("circle", { cx: "10", cy: "10", r: "2.5", stroke: "currentColor", strokeWidth: "1.5" }),
211
- /* @__PURE__ */ r("path", { d: "M3 17L17 3", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" })
212
- ] }) : /* @__PURE__ */ h("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: [
213
- /* @__PURE__ */ r(
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__ */ r("circle", { cx: "10", cy: "10", r: "2.5", stroke: "currentColor", strokeWidth: "1.5" })
222
- ] })
223
- }
224
- )
225
- ] }),
226
- d && /* @__PURE__ */ r("p", { id: `${k}-error`, className: "cedros-input-error", children: d }),
227
- C && a && g?.length > 0 && /* @__PURE__ */ h("div", { className: "cedros-password-strength", children: [
228
- /* @__PURE__ */ r("div", { className: "cedros-strength-bar", children: /* @__PURE__ */ r(
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__ */ r("span", { className: "cedros-strength-label", children: a.strength })
239
- ] })
240
- ] });
241
- }
242
- function de() {
243
- const { config: c, _internal: u } = U(), [C, m] = w("idle"), [d, s] = w(!1), [b, g] = w(null), {
244
- checkLimit: l,
245
- getRemainingAttempts: i,
246
- getTimeUntilReset: f,
247
- reset: a
248
- } = K({ maxAttempts: 5, windowMs: 12e4 }), p = z(
249
- () => new H({
250
- baseUrl: c.serverUrl,
251
- timeoutMs: c.requestTimeout,
252
- retryAttempts: c.retryAttempts
253
- }),
254
- [c.serverUrl, c.requestTimeout, c.retryAttempts]
255
- ), k = E(
256
- async (n, t) => {
257
- const e = /^[A-Z0-9]{16}$/i.test(t) || /^[A-Z0-9]{4}(-[A-Z0-9]{4}){3}$/i.test(t);
258
- if (!(/^\d{6}$/.test(t) || e)) {
259
- const v = {
260
- code: "VALIDATION_ERROR",
261
- message: "Please enter a valid 6-digit code or recovery code"
262
- };
263
- throw g(v), v;
264
- }
265
- try {
266
- l();
267
- } catch (v) {
268
- const L = {
269
- code: "RATE_LIMITED",
270
- message: v instanceof Error ? v.message : "Too many attempts"
271
- };
272
- throw g(L), L;
273
- }
274
- s(!0), g(null), m("verifying");
275
- try {
276
- const v = await p.post("/login/mfa", { mfaToken: n, code: t });
277
- return m("success"), a(), u && v.user && v.tokens && u.handleLoginSuccess(v.user, v.tokens), v;
278
- } catch (v) {
279
- const L = P(v, "Incorrect verification code. Please check and try again.");
280
- throw g(L), m("error"), L;
281
- } finally {
282
- s(!1);
283
- }
284
- },
285
- [p, u, l, a]
286
- ), N = E(() => g(null), []), y = E(() => {
287
- g(null), m("idle"), s(!1);
288
- }, []);
289
- return {
290
- state: C,
291
- isLoading: d,
292
- error: b,
293
- verifyTotp: k,
294
- clearError: N,
295
- reset: y,
296
- // Point-in-time snapshots for UI display
297
- remainingAttempts: i(),
298
- timeUntilReset: f()
299
- };
300
- }
301
- const T = 6;
302
- function ue({
303
- value: c = "",
304
- onChange: u,
305
- onComplete: C,
306
- disabled: m = !1,
307
- error: d,
308
- autoFocus: s = !1,
309
- className: b = ""
310
- }) {
311
- const g = F([]), [l, i] = w(c.padEnd(T, "")), f = W();
312
- M(() => {
313
- i(c.padEnd(T, ""));
314
- }, [c]);
315
- const a = E((t) => {
316
- t >= 0 && t < T && g.current[t]?.focus();
317
- }, []), p = E(
318
- (t) => {
319
- const e = t.replace(/\D/g, "").slice(0, T);
320
- i(e.padEnd(T, "")), u?.(e), e.length === T && C?.(e);
321
- },
322
- [u, C]
323
- ), k = E(
324
- (t, e) => {
325
- if (!/^\d?$/.test(e)) return;
326
- const o = l.split("");
327
- o[t] = e;
328
- const v = o.join("").replace(/ /g, "");
329
- p(v), e && t < T - 1 && a(t + 1);
330
- },
331
- [l, p, a]
332
- ), N = E(
333
- (t, e) => {
334
- if (e.key === "Backspace") {
335
- e.preventDefault();
336
- const o = l.split("");
337
- o[t] && o[t] !== " " ? (o[t] = " ", p(o.join("").replace(/ /g, ""))) : t > 0 && (o[t - 1] = " ", p(o.join("").replace(/ /g, "")), a(t - 1));
338
- } else e.key === "ArrowLeft" && t > 0 ? (e.preventDefault(), a(t - 1)) : e.key === "ArrowRight" && t < T - 1 && (e.preventDefault(), a(t + 1));
339
- },
340
- [l, p, a]
341
- ), y = E(
342
- (t) => {
343
- t.preventDefault();
344
- const o = t.clipboardData.getData("text").replace(/\D/g, "").slice(0, T);
345
- o && (p(o), a(Math.min(o.length, T - 1)));
346
- },
347
- [p, a]
348
- ), n = E((t) => {
349
- t.target.select();
350
- }, []);
351
- return M(() => {
352
- s && !m && g.current[0]?.focus();
353
- }, [s, m]), /* @__PURE__ */ h("div", { className: `cedros-otp-input ${b}`, children: [
354
- /* @__PURE__ */ r("div", { className: "cedros-otp-slots", role: "group", "aria-label": "One-time password", children: Array.from({ length: T }).map((t, e) => /* @__PURE__ */ r(
355
- "input",
356
- {
357
- ref: (o) => {
358
- g.current[e] = o;
359
- },
360
- id: `${f}-${e}`,
361
- type: "text",
362
- inputMode: "numeric",
363
- pattern: "[0-9]*",
364
- maxLength: 1,
365
- className: `cedros-otp-slot ${d ? "cedros-otp-slot-error" : ""}`,
366
- value: l[e] === " " ? "" : l[e] || "",
367
- onChange: (o) => k(e, o.target.value),
368
- onKeyDown: (o) => N(e, o),
369
- onPaste: y,
370
- onFocus: n,
371
- disabled: m,
372
- autoComplete: "one-time-code",
373
- "aria-label": `Digit ${e + 1}`,
374
- "aria-invalid": d ? "true" : void 0
375
- },
376
- e
377
- )) }),
378
- d && /* @__PURE__ */ r("p", { className: "cedros-otp-error", role: "alert", children: d })
379
- ] });
380
- }
381
- function me({
382
- mfaToken: c,
383
- email: u,
384
- onSuccess: C,
385
- onBack: m,
386
- className: d = ""
387
- }) {
388
- const { verifyTotp: s, isLoading: b, error: g, clearError: l } = de(), [i, f] = w(""), [a, p] = w(!1), [k, N] = w(""), y = async (e) => {
389
- const o = e || (a ? k : i);
390
- if (o)
391
- try {
392
- await s(c, o), C?.();
393
- } catch {
394
- a ? N("") : f("");
395
- }
396
- }, n = (e) => {
397
- y(e);
398
- }, t = () => {
399
- p(!a), l(), f(""), N("");
400
- };
401
- return /* @__PURE__ */ h("div", { className: `cedros-totp-verify ${d}`, children: [
402
- /* @__PURE__ */ h("div", { className: "cedros-totp-verify-header", children: [
403
- /* @__PURE__ */ h(
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__ */ r("rect", { x: "8", y: "20", width: "32", height: "24", rx: "4", stroke: "currentColor", strokeWidth: "2" }),
414
- /* @__PURE__ */ r(
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__ */ r("circle", { cx: "24", cy: "32", r: "3", fill: "currentColor" })
424
- ]
425
- }
426
- ),
427
- /* @__PURE__ */ r("h3", { className: "cedros-totp-title", children: "Two-factor authentication" }),
428
- /* @__PURE__ */ r("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__ */ r("p", { className: "cedros-totp-email", children: u })
430
- ] }),
431
- a ? /* @__PURE__ */ h("div", { className: "cedros-totp-backup-input", children: [
432
- /* @__PURE__ */ r(
433
- "input",
434
- {
435
- type: "text",
436
- className: `cedros-input ${g ? "cedros-input-error" : ""}`,
437
- placeholder: "Enter recovery code",
438
- value: k,
439
- onChange: (e) => {
440
- N(e.target.value.toUpperCase()), l();
441
- },
442
- onKeyDown: (e) => {
443
- e.key === "Enter" && k && y();
444
- },
445
- disabled: b,
446
- autoFocus: !0,
447
- autoComplete: "one-time-code"
448
- }
449
- ),
450
- g && /* @__PURE__ */ r("p", { className: "cedros-input-error", role: "alert", children: g.message })
451
- ] }) : /* @__PURE__ */ r(
452
- ue,
453
- {
454
- value: i,
455
- onChange: (e) => {
456
- f(e), l();
457
- },
458
- onComplete: n,
459
- disabled: b,
460
- error: g?.message,
461
- autoFocus: !0
462
- }
463
- ),
464
- /* @__PURE__ */ r(
465
- "button",
466
- {
467
- type: "button",
468
- className: "cedros-button cedros-button-primary cedros-button-md cedros-button-full",
469
- onClick: () => y(),
470
- disabled: b || (a ? !k : i.length !== 6),
471
- children: b ? /* @__PURE__ */ h(R, { children: [
472
- /* @__PURE__ */ r(O, { size: "sm" }),
473
- /* @__PURE__ */ r("span", { children: "Verifying..." })
474
- ] }) : "Verify"
475
- }
476
- ),
477
- /* @__PURE__ */ h("div", { className: "cedros-totp-verify-footer", children: [
478
- /* @__PURE__ */ r(
479
- "button",
480
- {
481
- type: "button",
482
- className: "cedros-link cedros-link-sm",
483
- onClick: t,
484
- disabled: b,
485
- children: a ? "Use authenticator app" : "Use a recovery code"
486
- }
487
- ),
488
- m && /* @__PURE__ */ h(R, { children: [
489
- /* @__PURE__ */ r("span", { className: "cedros-totp-verify-divider", children: "•" }),
490
- /* @__PURE__ */ r(
491
- "button",
492
- {
493
- type: "button",
494
- className: "cedros-link cedros-link-sm",
495
- onClick: m,
496
- disabled: b,
497
- children: "Back to login"
498
- }
499
- )
500
- ] })
501
- ] })
502
- ] });
503
- }
504
- function ke({
505
- onSuccess: c,
506
- onSwitchToRegister: u,
507
- onForgotPassword: C,
508
- className: m = ""
509
- }) {
510
- const { login: d, isLoading: s, error: b, clearError: g } = Z(), [l, i] = w(""), [f, a] = w(""), [p, k] = w(null), [N, y] = w(""), n = async (o) => {
511
- o.preventDefault();
512
- try {
513
- const v = await d(l, f);
514
- v.mfaRequired ? (k(v.mfaToken), y(v.email)) : c?.();
515
- } catch {
516
- }
517
- }, t = () => {
518
- k(null), y(""), c?.();
519
- }, e = () => {
520
- k(null), y(""), a("");
521
- };
522
- return p ? /* @__PURE__ */ r(
523
- me,
524
- {
525
- mfaToken: p,
526
- email: N,
527
- onSuccess: t,
528
- onBack: e,
529
- className: m
530
- }
531
- ) : /* @__PURE__ */ h("form", { onSubmit: n, className: `cedros-form ${m}`, children: [
532
- /* @__PURE__ */ h("div", { className: "cedros-form-field", children: [
533
- /* @__PURE__ */ r("label", { htmlFor: "email", className: "cedros-label", children: "Email" }),
534
- /* @__PURE__ */ r(
535
- "input",
536
- {
537
- id: "email",
538
- type: "email",
539
- className: "cedros-input",
540
- value: l,
541
- onChange: (o) => i(o.target.value),
542
- placeholder: "you@example.com",
543
- required: !0,
544
- "aria-required": "true",
545
- autoComplete: "email",
546
- disabled: s
547
- }
548
- )
549
- ] }),
550
- /* @__PURE__ */ r("div", { className: "cedros-form-field", children: /* @__PURE__ */ r(
551
- q,
552
- {
553
- value: f,
554
- onChange: (o) => a(o.target.value),
555
- placeholder: "Enter your password",
556
- required: !0,
557
- autoComplete: "current-password",
558
- disabled: s,
559
- labelAction: C ? /* @__PURE__ */ r(
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__ */ r(j, { error: b, onDismiss: g }),
571
- /* @__PURE__ */ r(
572
- "button",
573
- {
574
- type: "submit",
575
- className: "cedros-button cedros-button-primary cedros-button-md cedros-button-full",
576
- disabled: s || !l || !f,
577
- "aria-busy": s,
578
- children: s ? /* @__PURE__ */ h(R, { children: [
579
- /* @__PURE__ */ r(O, { size: "sm", announce: !0, label: "Signing in" }),
580
- /* @__PURE__ */ r("span", { children: "Signing in..." })
581
- ] }) : "Sign in"
582
- }
583
- ),
584
- u && /* @__PURE__ */ h("p", { className: "cedros-form-footer", children: [
585
- "Don't have an account?",
586
- " ",
587
- /* @__PURE__ */ r("button", { type: "button", className: "cedros-link cedros-link-muted", onClick: u, children: "Sign up" })
588
- ] })
589
- ] });
590
- }
591
- function Ce({
592
- onSuccess: c,
593
- onSwitchToLogin: u,
594
- className: C = ""
595
- }) {
596
- const { config: m } = U(), { register: d, isLoading: s, error: b, clearError: g } = Z(), [l, i] = w(""), [f, a] = w(""), [p, k] = w(""), [N, y] = w(""), [n, t] = w(null), [e, o] = w(null), v = m.forms?.termsOfService, L = m.forms?.emailOptIn, D = v?.show ?? !1, I = v?.required ?? !0, Y = v?.defaultChecked ?? !1, $ = v?.label ?? "I agree to the Terms of Service", G = v?.url, x = ie(G), J = L?.show ?? !1, Q = L?.defaultChecked ?? !1, X = L?.label ?? "Send me updates and news", [S, ee] = w(Y), [te, re] = w(Q), V = p === N, se = n?.isValid ?? !1, _ = f && p && N && V && se && (!D || !I || S) && !s, oe = async (A) => {
597
- if (A.preventDefault(), o(null), D && I && !S) {
598
- o({
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 d(f, p, l || void 0), c?.();
607
- } catch {
608
- }
609
- }, ae = b || e, ne = () => {
610
- g(), o(null);
611
- };
612
- return /* @__PURE__ */ h("form", { onSubmit: oe, className: `cedros-form ${C}`, children: [
613
- /* @__PURE__ */ h("div", { className: "cedros-form-field", children: [
614
- /* @__PURE__ */ h("label", { htmlFor: "name", className: "cedros-label", children: [
615
- "Name ",
616
- /* @__PURE__ */ r("span", { className: "cedros-optional", children: "(optional)" })
617
- ] }),
618
- /* @__PURE__ */ r(
619
- "input",
620
- {
621
- id: "name",
622
- type: "text",
623
- className: "cedros-input",
624
- value: l,
625
- onChange: (A) => i(A.target.value),
626
- placeholder: "Your name",
627
- autoComplete: "name",
628
- disabled: s
629
- }
630
- )
631
- ] }),
632
- /* @__PURE__ */ h("div", { className: "cedros-form-field", children: [
633
- /* @__PURE__ */ r("label", { htmlFor: "register-email", className: "cedros-label", children: "Email" }),
634
- /* @__PURE__ */ r(
635
- "input",
636
- {
637
- id: "register-email",
638
- type: "email",
639
- className: "cedros-input",
640
- value: f,
641
- onChange: (A) => a(A.target.value),
642
- placeholder: "you@example.com",
643
- required: !0,
644
- "aria-required": "true",
645
- autoComplete: "email",
646
- disabled: s
647
- }
648
- )
649
- ] }),
650
- /* @__PURE__ */ r("div", { className: "cedros-form-field", children: /* @__PURE__ */ r(
651
- q,
652
- {
653
- value: p,
654
- onChange: (A) => k(A.target.value),
655
- placeholder: "Create a password",
656
- required: !0,
657
- autoComplete: "new-password",
658
- disabled: s,
659
- showStrengthMeter: !0,
660
- onValidationChange: t
661
- }
662
- ) }),
663
- /* @__PURE__ */ r("div", { className: "cedros-form-field", children: /* @__PURE__ */ r(
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: s,
673
- "aria-invalid": N && !V ? "true" : void 0,
674
- error: N && !V ? "Passwords do not match" : void 0
675
- }
676
- ) }),
677
- D && /* @__PURE__ */ r("div", { className: "cedros-form-field cedros-checkbox-field", children: /* @__PURE__ */ h("label", { className: "cedros-checkbox-label", children: [
678
- /* @__PURE__ */ r(
679
- "input",
680
- {
681
- type: "checkbox",
682
- className: "cedros-checkbox",
683
- checked: S,
684
- onChange: (A) => ee(A.target.checked),
685
- disabled: s,
686
- "aria-required": I
687
- }
688
- ),
689
- /* @__PURE__ */ h("span", { className: "cedros-checkbox-text", children: [
690
- x ? /* @__PURE__ */ h(R, { children: [
691
- $.replace("Terms of Service", "").trim() || "I agree to the",
692
- " ",
693
- /* @__PURE__ */ r(
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__ */ r("span", { className: "cedros-required", children: "*" })
705
- ] })
706
- ] }) }),
707
- J && /* @__PURE__ */ r("div", { className: "cedros-form-field cedros-checkbox-field", children: /* @__PURE__ */ h("label", { className: "cedros-checkbox-label", children: [
708
- /* @__PURE__ */ r(
709
- "input",
710
- {
711
- type: "checkbox",
712
- className: "cedros-checkbox",
713
- checked: te,
714
- onChange: (A) => re(A.target.checked),
715
- disabled: s
716
- }
717
- ),
718
- /* @__PURE__ */ r("span", { className: "cedros-checkbox-text", children: X })
719
- ] }) }),
720
- /* @__PURE__ */ r(j, { error: ae, onDismiss: ne }),
721
- /* @__PURE__ */ r(
722
- "button",
723
- {
724
- type: "submit",
725
- className: "cedros-button cedros-button-primary cedros-button-md cedros-button-full",
726
- disabled: !_,
727
- "aria-busy": s,
728
- children: s ? /* @__PURE__ */ h(R, { children: [
729
- /* @__PURE__ */ r(O, { size: "sm", announce: !0, label: "Creating account" }),
730
- /* @__PURE__ */ r("span", { children: "Creating account..." })
731
- ] }) : "Create account"
732
- }
733
- ),
734
- u && /* @__PURE__ */ h("p", { className: "cedros-form-footer", children: [
735
- "Already have an account?",
736
- " ",
737
- /* @__PURE__ */ r("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
- };