@nice2dev/auth 1.1.7 → 1.1.10
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/CHANGELOG.md +83 -0
- package/dist/NiceOAuthButtons.d.ts +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +160 -132
- package/dist/marks.d.ts +40 -0
- package/package.json +2 -2
- package/dist/NiceCaptcha.d.ts.map +0 -1
- package/dist/NiceChangePassword.d.ts.map +0 -1
- package/dist/NiceLoginForm.d.ts.map +0 -1
- package/dist/NiceOAuthButtons.d.ts.map +0 -1
- package/dist/NicePasswordStrength.d.ts.map +0 -1
- package/dist/NiceRegistrationForm.d.ts.map +0 -1
- package/dist/NiceTokenManagement.d.ts.map +0 -1
- package/dist/NiceTwoFaSetup.d.ts.map +0 -1
- package/dist/__tests__/NiceCaptcha.test.d.ts.map +0 -1
- package/dist/__tests__/NiceChangePassword.test.d.ts.map +0 -1
- package/dist/__tests__/NiceLoginForm.test.d.ts.map +0 -1
- package/dist/__tests__/NiceOAuthButtons.test.d.ts.map +0 -1
- package/dist/__tests__/NicePasswordStrength.test.d.ts.map +0 -1
- package/dist/__tests__/NiceRegistrationForm.test.d.ts.map +0 -1
- package/dist/__tests__/NiceTokenManagement.test.d.ts.map +0 -1
- package/dist/__tests__/NiceTwoFaSetup.test.d.ts.map +0 -1
- package/dist/__tests__/setup.d.ts.map +0 -1
- package/dist/__tests__/useAuth.test.d.ts.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/useAuth.d.ts.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useState as _, useCallback as w, forwardRef as
|
|
2
|
-
import { jsxs as a, jsx as e, Fragment as
|
|
3
|
-
function
|
|
4
|
-
const { onLogin: t, onRefresh:
|
|
1
|
+
import { useState as _, useCallback as w, forwardRef as B, useMemo as X, useRef as U, useImperativeHandle as ae, useEffect as W } from "react";
|
|
2
|
+
import { jsxs as a, jsx as e, Fragment as ie } from "react/jsx-runtime";
|
|
3
|
+
function ye(c = {}) {
|
|
4
|
+
const { onLogin: t, onRefresh: i, onLogout: n, storageKey: r = "nice_auth", persistAuth: l = !1 } = c, [o, p] = _(() => {
|
|
5
5
|
if (l && typeof window < "u")
|
|
6
6
|
try {
|
|
7
7
|
const h = localStorage.getItem(r);
|
|
@@ -47,15 +47,15 @@ function ve(i = {}) {
|
|
|
47
47
|
n == null || n(), d({ isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null });
|
|
48
48
|
}, [n, d]), C = w(async () => {
|
|
49
49
|
var h;
|
|
50
|
-
if (!((h = o.tokens) != null && h.refreshToken) || !
|
|
50
|
+
if (!((h = o.tokens) != null && h.refreshToken) || !i)
|
|
51
51
|
return !1;
|
|
52
52
|
try {
|
|
53
|
-
const m = await
|
|
53
|
+
const m = await i(o.tokens.refreshToken);
|
|
54
54
|
return d({ tokens: m }), !0;
|
|
55
55
|
} catch {
|
|
56
56
|
return s(), !1;
|
|
57
57
|
}
|
|
58
|
-
}, [o.tokens,
|
|
58
|
+
}, [o.tokens, i, d, s]), b = w(
|
|
59
59
|
(h, m) => {
|
|
60
60
|
d({ isAuthenticated: !0, user: h, tokens: m, loading: !1, error: null });
|
|
61
61
|
},
|
|
@@ -80,11 +80,11 @@ function ve(i = {}) {
|
|
|
80
80
|
clearError: F
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
const
|
|
83
|
+
const ce = B(
|
|
84
84
|
({
|
|
85
|
-
onSubmit:
|
|
85
|
+
onSubmit: c,
|
|
86
86
|
loading: t = !1,
|
|
87
|
-
error:
|
|
87
|
+
error: i,
|
|
88
88
|
showRememberMe: n = !0,
|
|
89
89
|
showForgotPassword: r = !0,
|
|
90
90
|
onForgotPassword: l,
|
|
@@ -101,13 +101,13 @@ const ie = O(
|
|
|
101
101
|
tracelessPolicy: h,
|
|
102
102
|
privacyMessage: m
|
|
103
103
|
}, f) => {
|
|
104
|
-
const [T, N] = _(""), [P, S] = _(""), [E, k] = _(!1),
|
|
104
|
+
const [T, N] = _(""), [P, S] = _(""), [E, k] = _(!1), D = X(() => !(!n || h && !h.cookiesAllowed), [n, h]), O = w(
|
|
105
105
|
(A) => {
|
|
106
106
|
A.preventDefault();
|
|
107
|
-
const
|
|
108
|
-
|
|
107
|
+
const M = (h == null ? void 0 : h.cookiesAllowed) === !1 ? !1 : E;
|
|
108
|
+
c == null || c({ email: T, password: P, rememberMe: M });
|
|
109
109
|
},
|
|
110
|
-
[T, P, E,
|
|
110
|
+
[T, P, E, c, h]
|
|
111
111
|
);
|
|
112
112
|
return /* @__PURE__ */ a(
|
|
113
113
|
"form",
|
|
@@ -115,12 +115,12 @@ const ie = O(
|
|
|
115
115
|
ref: f,
|
|
116
116
|
className: `nice-login-form${b ? ` ${b}` : ""}`,
|
|
117
117
|
style: x,
|
|
118
|
-
onSubmit:
|
|
118
|
+
onSubmit: O,
|
|
119
119
|
noValidate: !0,
|
|
120
120
|
children: [
|
|
121
121
|
s && /* @__PURE__ */ e("div", { className: "nice-login-form__logo", children: s }),
|
|
122
122
|
/* @__PURE__ */ e("h2", { className: "nice-login-form__title", children: d }),
|
|
123
|
-
|
|
123
|
+
i && /* @__PURE__ */ e("div", { className: "nice-login-form__error", role: "alert", children: i }),
|
|
124
124
|
/* @__PURE__ */ a("div", { className: "nice-login-form__field", children: [
|
|
125
125
|
/* @__PURE__ */ e("label", { htmlFor: "nice-login-email", children: g }),
|
|
126
126
|
/* @__PURE__ */ e(
|
|
@@ -154,7 +154,7 @@ const ie = O(
|
|
|
154
154
|
)
|
|
155
155
|
] }),
|
|
156
156
|
/* @__PURE__ */ a("div", { className: "nice-login-form__options", children: [
|
|
157
|
-
|
|
157
|
+
D && /* @__PURE__ */ a("label", { className: "nice-login-form__remember", children: [
|
|
158
158
|
/* @__PURE__ */ e(
|
|
159
159
|
"input",
|
|
160
160
|
{
|
|
@@ -166,7 +166,7 @@ const ie = O(
|
|
|
166
166
|
),
|
|
167
167
|
/* @__PURE__ */ e("span", { children: "Remember me" })
|
|
168
168
|
] }),
|
|
169
|
-
!
|
|
169
|
+
!D && n && m && /* @__PURE__ */ e("span", { className: "nice-login-form__privacy-notice", children: m }),
|
|
170
170
|
r && /* @__PURE__ */ e(
|
|
171
171
|
"button",
|
|
172
172
|
{
|
|
@@ -197,7 +197,7 @@ const ie = O(
|
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
);
|
|
200
|
-
|
|
200
|
+
ce.displayName = "NiceLoginForm";
|
|
201
201
|
const re = {
|
|
202
202
|
0: "Very weak",
|
|
203
203
|
1: "Weak",
|
|
@@ -211,15 +211,15 @@ const re = {
|
|
|
211
211
|
3: "#5cb85c",
|
|
212
212
|
4: "#2e7d32"
|
|
213
213
|
};
|
|
214
|
-
function J(
|
|
215
|
-
if (!
|
|
214
|
+
function J(c) {
|
|
215
|
+
if (!c)
|
|
216
216
|
return 0;
|
|
217
217
|
let t = 0;
|
|
218
|
-
return
|
|
218
|
+
return c.length >= 8 && t++, c.length >= 12 && t++, /[a-z]/.test(c) && /[A-Z]/.test(c) && t++, /\d/.test(c) && t++, /[^a-zA-Z0-9]/.test(c) && t++, Math.min(4, t);
|
|
219
219
|
}
|
|
220
|
-
const Z =
|
|
221
|
-
({ password:
|
|
222
|
-
const o = t ?? J(
|
|
220
|
+
const Z = B(
|
|
221
|
+
({ password: c, strength: t, showLabel: i = !0, labels: n = re, className: r }, l) => {
|
|
222
|
+
const o = t ?? J(c), p = se[o], d = (o + 1) / 5 * 100;
|
|
223
223
|
return /* @__PURE__ */ a("div", { ref: l, className: `nice-password-strength${r ? ` ${r}` : ""}`, children: [
|
|
224
224
|
/* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e(
|
|
225
225
|
"div",
|
|
@@ -228,16 +228,16 @@ const Z = O(
|
|
|
228
228
|
style: { width: `${d}%`, backgroundColor: p }
|
|
229
229
|
}
|
|
230
230
|
) }),
|
|
231
|
-
|
|
231
|
+
i && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: p }, children: n[o] })
|
|
232
232
|
] });
|
|
233
233
|
}
|
|
234
234
|
);
|
|
235
235
|
Z.displayName = "NicePasswordStrength";
|
|
236
|
-
const le =
|
|
236
|
+
const le = B(
|
|
237
237
|
({
|
|
238
|
-
onSubmit:
|
|
238
|
+
onSubmit: c,
|
|
239
239
|
loading: t = !1,
|
|
240
|
-
error:
|
|
240
|
+
error: i,
|
|
241
241
|
onLoginClick: n,
|
|
242
242
|
showPasswordStrength: r = !0,
|
|
243
243
|
minPasswordStrength: l = 2,
|
|
@@ -249,11 +249,11 @@ const le = O(
|
|
|
249
249
|
className: C,
|
|
250
250
|
style: b
|
|
251
251
|
}, x) => {
|
|
252
|
-
const [g, F] = _(""), [h, m] = _(""), [f, T] = _(""), [N, P] = _(""), [S, E] = _(""), [k,
|
|
252
|
+
const [g, F] = _(""), [h, m] = _(""), [f, T] = _(""), [N, P] = _(""), [S, E] = _(""), [k, D] = _(!1), O = J(N), A = N === S, M = g && f && N && A && k && O >= l && !t, u = w(
|
|
253
253
|
(v) => {
|
|
254
|
-
v.preventDefault(),
|
|
254
|
+
v.preventDefault(), M && (c == null || c({ firstName: g, lastName: h, email: f, password: N, acceptTerms: k }));
|
|
255
255
|
},
|
|
256
|
-
[
|
|
256
|
+
[M, g, h, f, N, k, c]
|
|
257
257
|
);
|
|
258
258
|
return /* @__PURE__ */ a(
|
|
259
259
|
"form",
|
|
@@ -266,7 +266,7 @@ const le = O(
|
|
|
266
266
|
children: [
|
|
267
267
|
$ && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: $ }),
|
|
268
268
|
/* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: d }),
|
|
269
|
-
|
|
269
|
+
i && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: i }),
|
|
270
270
|
/* @__PURE__ */ a("div", { className: "nice-register-form__row", children: [
|
|
271
271
|
/* @__PURE__ */ a("div", { className: "nice-register-form__field", children: [
|
|
272
272
|
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
|
|
@@ -356,7 +356,7 @@ const le = O(
|
|
|
356
356
|
{
|
|
357
357
|
type: "checkbox",
|
|
358
358
|
checked: k,
|
|
359
|
-
onChange: (v) =>
|
|
359
|
+
onChange: (v) => D(v.target.checked),
|
|
360
360
|
disabled: t
|
|
361
361
|
}
|
|
362
362
|
),
|
|
@@ -364,7 +364,7 @@ const le = O(
|
|
|
364
364
|
"I accept the",
|
|
365
365
|
" ",
|
|
366
366
|
o ? /* @__PURE__ */ e("a", { href: o, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
|
|
367
|
-
p && /* @__PURE__ */ a(
|
|
367
|
+
p && /* @__PURE__ */ a(ie, { children: [
|
|
368
368
|
" ",
|
|
369
369
|
"and",
|
|
370
370
|
" ",
|
|
@@ -378,7 +378,7 @@ const le = O(
|
|
|
378
378
|
{
|
|
379
379
|
type: "submit",
|
|
380
380
|
className: "nice-btn nice-btn--primary nice-register-form__submit",
|
|
381
|
-
disabled: !
|
|
381
|
+
disabled: !M,
|
|
382
382
|
children: t ? "…" : "Register"
|
|
383
383
|
}
|
|
384
384
|
),
|
|
@@ -393,11 +393,11 @@ const le = O(
|
|
|
393
393
|
}
|
|
394
394
|
);
|
|
395
395
|
le.displayName = "NiceRegistrationForm";
|
|
396
|
-
const oe =
|
|
396
|
+
const oe = B(
|
|
397
397
|
({
|
|
398
|
-
requireCurrentPassword:
|
|
398
|
+
requireCurrentPassword: c = !0,
|
|
399
399
|
onSubmit: t,
|
|
400
|
-
loading:
|
|
400
|
+
loading: i = !1,
|
|
401
401
|
error: n,
|
|
402
402
|
success: r,
|
|
403
403
|
minPasswordStrength: l = 2,
|
|
@@ -405,14 +405,14 @@ const oe = O(
|
|
|
405
405
|
className: p,
|
|
406
406
|
style: d
|
|
407
407
|
}, $) => {
|
|
408
|
-
const [s, C] = _(""), [b, x] = _(""), [g, F] = _(""), h = J(b), m = b === g, f = (!
|
|
408
|
+
const [s, C] = _(""), [b, x] = _(""), [g, F] = _(""), h = J(b), m = b === g, f = (!c || s.length > 0) && b.length > 0 && m && h >= l && !i, T = w(
|
|
409
409
|
(N) => {
|
|
410
410
|
N.preventDefault(), f && (t == null || t({
|
|
411
|
-
currentPassword:
|
|
411
|
+
currentPassword: c ? s : void 0,
|
|
412
412
|
newPassword: b
|
|
413
413
|
}));
|
|
414
414
|
},
|
|
415
|
-
[f, s, b,
|
|
415
|
+
[f, s, b, c, t]
|
|
416
416
|
);
|
|
417
417
|
return /* @__PURE__ */ a(
|
|
418
418
|
"form",
|
|
@@ -426,7 +426,7 @@ const oe = O(
|
|
|
426
426
|
/* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: o }),
|
|
427
427
|
n && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: n }),
|
|
428
428
|
r && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: r }),
|
|
429
|
-
|
|
429
|
+
c && /* @__PURE__ */ a("div", { className: "nice-change-password__field", children: [
|
|
430
430
|
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
|
|
431
431
|
/* @__PURE__ */ e(
|
|
432
432
|
"input",
|
|
@@ -437,7 +437,7 @@ const oe = O(
|
|
|
437
437
|
value: s,
|
|
438
438
|
onChange: (N) => C(N.target.value),
|
|
439
439
|
autoComplete: "current-password",
|
|
440
|
-
disabled:
|
|
440
|
+
disabled: i,
|
|
441
441
|
required: !0
|
|
442
442
|
}
|
|
443
443
|
)
|
|
@@ -453,7 +453,7 @@ const oe = O(
|
|
|
453
453
|
value: b,
|
|
454
454
|
onChange: (N) => x(N.target.value),
|
|
455
455
|
autoComplete: "new-password",
|
|
456
|
-
disabled:
|
|
456
|
+
disabled: i,
|
|
457
457
|
required: !0
|
|
458
458
|
}
|
|
459
459
|
),
|
|
@@ -470,24 +470,24 @@ const oe = O(
|
|
|
470
470
|
value: g,
|
|
471
471
|
onChange: (N) => F(N.target.value),
|
|
472
472
|
autoComplete: "new-password",
|
|
473
|
-
disabled:
|
|
473
|
+
disabled: i,
|
|
474
474
|
required: !0
|
|
475
475
|
}
|
|
476
476
|
),
|
|
477
477
|
g && !m && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
|
|
478
478
|
] }),
|
|
479
|
-
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !f, children:
|
|
479
|
+
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !f, children: i ? "…" : "Change Password" })
|
|
480
480
|
]
|
|
481
481
|
}
|
|
482
482
|
);
|
|
483
483
|
}
|
|
484
484
|
);
|
|
485
485
|
oe.displayName = "NiceChangePassword";
|
|
486
|
-
const de =
|
|
486
|
+
const de = B(
|
|
487
487
|
({
|
|
488
|
-
secret:
|
|
488
|
+
secret: c,
|
|
489
489
|
qrCodeUrl: t,
|
|
490
|
-
issuer:
|
|
490
|
+
issuer: i,
|
|
491
491
|
accountName: n,
|
|
492
492
|
onVerify: r,
|
|
493
493
|
loading: l = !1,
|
|
@@ -504,7 +504,7 @@ const de = O(
|
|
|
504
504
|
S.preventDefault(), g.length >= 6 && (r == null || r(g));
|
|
505
505
|
},
|
|
506
506
|
[g, r]
|
|
507
|
-
), P = `otpauth://totp/${
|
|
507
|
+
), P = `otpauth://totp/${i ? `${i}:` : ""}${n ?? "user"}?secret=${c}${i ? `&issuer=${i}` : ""}&digits=6&period=30`;
|
|
508
508
|
return /* @__PURE__ */ a("div", { ref: x, className: `nice-2fa-setup${C ? ` ${C}` : ""}`, style: b, children: [
|
|
509
509
|
/* @__PURE__ */ e("h3", { className: "nice-2fa-setup__title", children: "Two-Factor Authentication" }),
|
|
510
510
|
$ === "setup" && /* @__PURE__ */ a("div", { className: "nice-2fa-setup__step", children: [
|
|
@@ -515,7 +515,7 @@ const de = O(
|
|
|
515
515
|
] }),
|
|
516
516
|
/* @__PURE__ */ a("div", { className: "nice-2fa-setup__secret", children: [
|
|
517
517
|
/* @__PURE__ */ e("span", { children: "Or enter manually: " }),
|
|
518
|
-
h ? /* @__PURE__ */ e("code", { className: "nice-2fa-setup__secret-key", children:
|
|
518
|
+
h ? /* @__PURE__ */ e("code", { className: "nice-2fa-setup__secret-key", children: c }) : /* @__PURE__ */ e("button", { type: "button", onClick: () => m(!0), children: "Show secret key" })
|
|
519
519
|
] }),
|
|
520
520
|
/* @__PURE__ */ e(
|
|
521
521
|
"button",
|
|
@@ -581,23 +581,38 @@ const de = O(
|
|
|
581
581
|
}
|
|
582
582
|
);
|
|
583
583
|
de.displayName = "NiceTwoFaSetup";
|
|
584
|
-
const he =
|
|
585
|
-
|
|
586
|
-
|
|
584
|
+
const he = ({ style: c }) => /* @__PURE__ */ e(
|
|
585
|
+
"span",
|
|
586
|
+
{
|
|
587
|
+
"aria-hidden": "true",
|
|
588
|
+
style: {
|
|
589
|
+
display: "inline-block",
|
|
590
|
+
width: "0.85em",
|
|
591
|
+
height: "0.85em",
|
|
592
|
+
borderRadius: "50%",
|
|
593
|
+
border: "0.12em solid currentColor",
|
|
594
|
+
borderTopColor: "transparent",
|
|
595
|
+
transform: "rotate(-45deg)",
|
|
596
|
+
...c
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
), ue = 500;
|
|
600
|
+
function I(c, t) {
|
|
601
|
+
return Math.floor(Math.random() * (t - c + 1)) + c;
|
|
587
602
|
}
|
|
588
|
-
function
|
|
603
|
+
function me() {
|
|
589
604
|
return `${Math.random().toString(36).slice(2)}${Date.now().toString(36)}`;
|
|
590
605
|
}
|
|
591
|
-
function
|
|
592
|
-
switch (
|
|
606
|
+
function pe(c, t) {
|
|
607
|
+
switch (c) {
|
|
593
608
|
case "math": {
|
|
594
|
-
const
|
|
609
|
+
const i = t === "easy" ? 5 : t === "hard" ? 20 : 10, n = I(1, i), r = I(1, i), l = t !== "easy" && n >= r && Math.random() < 0.5, o = l ? n - r : n + r;
|
|
595
610
|
return { kind: "math", prompt: `${n} ${l ? "−" : "+"} ${r}`, answer: o };
|
|
596
611
|
}
|
|
597
612
|
case "text": {
|
|
598
|
-
const
|
|
613
|
+
const i = t === "easy" ? 4 : t === "hard" ? 7 : 5, n = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
|
|
599
614
|
let r = "";
|
|
600
|
-
for (let l = 0; l <
|
|
615
|
+
for (let l = 0; l < i; l++)
|
|
601
616
|
r += n[I(0, n.length - 1)];
|
|
602
617
|
return { kind: "text", text: r };
|
|
603
618
|
}
|
|
@@ -608,26 +623,26 @@ function me(i, t) {
|
|
|
608
623
|
return { kind: "checkbox" };
|
|
609
624
|
}
|
|
610
625
|
}
|
|
611
|
-
function
|
|
612
|
-
if (!
|
|
626
|
+
function fe(c, t, i) {
|
|
627
|
+
if (!c)
|
|
613
628
|
return;
|
|
614
|
-
const n =
|
|
629
|
+
const n = c.getContext("2d");
|
|
615
630
|
if (!n)
|
|
616
631
|
return;
|
|
617
|
-
const r =
|
|
618
|
-
n.clearRect(0, 0, r, l), n.fillStyle =
|
|
632
|
+
const r = c.width, l = c.height;
|
|
633
|
+
n.clearRect(0, 0, r, l), n.fillStyle = i ? "#1a1a1a" : "#f3f4f6", n.fillRect(0, 0, r, l), n.strokeStyle = i ? "rgba(255,255,255,0.18)" : "rgba(0,0,0,0.18)", n.lineWidth = 1;
|
|
619
634
|
for (let p = 0; p < 6; p++)
|
|
620
635
|
n.beginPath(), n.moveTo(I(0, r), I(0, l)), n.lineTo(I(0, r), I(0, l)), n.stroke();
|
|
621
|
-
n.fillStyle =
|
|
636
|
+
n.fillStyle = i ? "#e5e7eb" : "#111827", n.textBaseline = "middle";
|
|
622
637
|
const o = r / (t.length + 1);
|
|
623
638
|
for (let p = 0; p < t.length; p++) {
|
|
624
639
|
const d = I(22, 30);
|
|
625
640
|
n.save(), n.translate(o * (p + 1), l / 2 + I(-4, 4)), n.rotate(I(-22, 22) * Math.PI / 180), n.font = `bold ${d}px monospace`, n.fillText(t[p], -d / 3, 0), n.restore();
|
|
626
641
|
}
|
|
627
642
|
}
|
|
628
|
-
const
|
|
643
|
+
const ge = B((c, t) => {
|
|
629
644
|
const {
|
|
630
|
-
variant:
|
|
645
|
+
variant: i,
|
|
631
646
|
difficulty: n = "medium",
|
|
632
647
|
refreshable: r = !0,
|
|
633
648
|
verifyToken: l,
|
|
@@ -644,11 +659,11 @@ const fe = O((i, t) => {
|
|
|
644
659
|
customRender: h,
|
|
645
660
|
className: m,
|
|
646
661
|
style: f
|
|
647
|
-
} =
|
|
648
|
-
() =>
|
|
649
|
-
[
|
|
662
|
+
} = c, T = U(null), N = U(null), P = U(void 0), [S, E] = _(0), [k, D] = _("idle"), [O, A] = _(""), [M, u] = _(""), [v, z] = _(0), R = X(
|
|
663
|
+
() => pe(i ?? "checkbox", n),
|
|
664
|
+
[i, n, S]
|
|
650
665
|
), K = w(() => {
|
|
651
|
-
|
|
666
|
+
D("idle"), A(""), u(""), z(0), E((y) => y + 1);
|
|
652
667
|
}, []), G = w(() => {
|
|
653
668
|
K(), x == null || x();
|
|
654
669
|
}, [K, x]);
|
|
@@ -657,8 +672,8 @@ const fe = O((i, t) => {
|
|
|
657
672
|
() => ({ reset: K, refresh: G, container: T.current }),
|
|
658
673
|
[K, G]
|
|
659
674
|
), W(() => {
|
|
660
|
-
|
|
661
|
-
}, [
|
|
675
|
+
i === "text" && R.kind === "text" && fe(N.current, R.text, g === "dark");
|
|
676
|
+
}, [i, R, g]), W(() => {
|
|
662
677
|
if (k !== "verified" || !o)
|
|
663
678
|
return;
|
|
664
679
|
const y = setTimeout(() => {
|
|
@@ -666,28 +681,28 @@ const fe = O((i, t) => {
|
|
|
666
681
|
}, o);
|
|
667
682
|
return () => clearTimeout(y);
|
|
668
683
|
}, [k, o, C, K]);
|
|
669
|
-
const
|
|
670
|
-
const y = `ntd-cap:${
|
|
671
|
-
l ? (
|
|
672
|
-
Q ? (
|
|
684
|
+
const q = w(() => {
|
|
685
|
+
const y = `ntd-cap:${i}:${me()}`;
|
|
686
|
+
l ? (D("verifying"), A(""), Promise.resolve().then(() => l(y)).then((Q) => {
|
|
687
|
+
Q ? (D("verified"), s == null || s(y)) : (D("error"), A("Verification failed. Please try again."), E((ne) => ne + 1), u(""));
|
|
673
688
|
}).catch((Q) => {
|
|
674
|
-
|
|
675
|
-
})) : (
|
|
676
|
-
}, [
|
|
677
|
-
|
|
689
|
+
D("error"), A("Verification error. Please try again."), b == null || b(Q);
|
|
690
|
+
})) : (D("verified"), s == null || s(y));
|
|
691
|
+
}, [i, l, s, b]), H = w(() => {
|
|
692
|
+
D("error"), A("Incorrect, please try again."), E((y) => y + 1), u("");
|
|
678
693
|
}, []), Y = w(() => {
|
|
679
|
-
k === "verifying" || k === "verified" || (
|
|
680
|
-
}, [k,
|
|
694
|
+
k === "verifying" || k === "verified" || (D("verifying"), A(""), P.current = setTimeout(q, ue));
|
|
695
|
+
}, [k, q]);
|
|
681
696
|
W(() => () => clearTimeout(P.current), []);
|
|
682
697
|
const j = w(() => {
|
|
683
|
-
R.kind === "math" ?
|
|
684
|
-
}, [R,
|
|
698
|
+
R.kind === "math" ? M.trim() !== "" && Number(M) === R.answer ? q() : H() : R.kind === "text" && (M.trim().toUpperCase() === R.text ? q() : H());
|
|
699
|
+
}, [R, M, q, H]), ee = w(
|
|
685
700
|
(y) => {
|
|
686
|
-
z(y), !(R.kind !== "slider" || k === "verified" || k === "verifying") && Math.abs(y - R.target) <= R.tolerance &&
|
|
701
|
+
z(y), !(R.kind !== "slider" || k === "verified" || k === "verifying") && Math.abs(y - R.target) <= R.tolerance && q();
|
|
687
702
|
},
|
|
688
|
-
[R, k,
|
|
703
|
+
[R, k, q]
|
|
689
704
|
);
|
|
690
|
-
if (!
|
|
705
|
+
if (!i)
|
|
691
706
|
return d === "custom" && h ? /* @__PURE__ */ e(
|
|
692
707
|
"div",
|
|
693
708
|
{
|
|
@@ -707,7 +722,7 @@ const fe = O((i, t) => {
|
|
|
707
722
|
"data-size": F,
|
|
708
723
|
children: /* @__PURE__ */ a("div", { className: "nice-captcha__placeholder", children: [
|
|
709
724
|
/* @__PURE__ */ a("span", { children: [
|
|
710
|
-
"
|
|
725
|
+
"Captcha (",
|
|
711
726
|
d,
|
|
712
727
|
")"
|
|
713
728
|
] }),
|
|
@@ -719,7 +734,7 @@ const fe = O((i, t) => {
|
|
|
719
734
|
] })
|
|
720
735
|
}
|
|
721
736
|
);
|
|
722
|
-
const L = k === "verifying", V = k === "verified", te = `nice-captcha nice-captcha--${
|
|
737
|
+
const L = k === "verifying", V = k === "verified", te = `nice-captcha nice-captcha--${i} nice-captcha--${g} nice-captcha--${k}${F === "compact" ? " nice-captcha--compact" : ""}${m ? ` ${m}` : ""}`;
|
|
723
738
|
return /* @__PURE__ */ a(
|
|
724
739
|
"div",
|
|
725
740
|
{
|
|
@@ -728,11 +743,11 @@ const fe = O((i, t) => {
|
|
|
728
743
|
style: f,
|
|
729
744
|
role: "group",
|
|
730
745
|
"aria-label": "Captcha challenge",
|
|
731
|
-
"data-variant":
|
|
746
|
+
"data-variant": i,
|
|
732
747
|
"data-status": k,
|
|
733
748
|
"data-theme": g,
|
|
734
749
|
children: [
|
|
735
|
-
|
|
750
|
+
i === "checkbox" && /* @__PURE__ */ a(
|
|
736
751
|
"button",
|
|
737
752
|
{
|
|
738
753
|
type: "button",
|
|
@@ -743,12 +758,25 @@ const fe = O((i, t) => {
|
|
|
743
758
|
disabled: L || V,
|
|
744
759
|
onClick: Y,
|
|
745
760
|
children: [
|
|
746
|
-
/* @__PURE__ */ e("span", { className: "nice-captcha__box", "aria-hidden": "true", children: L ? "…" : V ?
|
|
761
|
+
/* @__PURE__ */ e("span", { className: "nice-captcha__box", "aria-hidden": "true", children: L ? "…" : V ? /* @__PURE__ */ e(
|
|
762
|
+
"span",
|
|
763
|
+
{
|
|
764
|
+
style: {
|
|
765
|
+
display: "inline-block",
|
|
766
|
+
width: "0.3em",
|
|
767
|
+
height: "0.6em",
|
|
768
|
+
marginBottom: "0.15em",
|
|
769
|
+
borderRight: "0.12em solid currentColor",
|
|
770
|
+
borderBottom: "0.12em solid currentColor",
|
|
771
|
+
transform: "rotate(45deg)"
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
) : "" }),
|
|
747
775
|
/* @__PURE__ */ e("span", { className: "nice-captcha__label", children: p })
|
|
748
776
|
]
|
|
749
777
|
}
|
|
750
778
|
),
|
|
751
|
-
|
|
779
|
+
i === "math" && R.kind === "math" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge", children: [
|
|
752
780
|
/* @__PURE__ */ a("span", { className: "nice-captcha__prompt", "aria-hidden": "true", children: [
|
|
753
781
|
R.prompt,
|
|
754
782
|
" ="
|
|
@@ -759,7 +787,7 @@ const fe = O((i, t) => {
|
|
|
759
787
|
className: "nice-input nice-captcha__answer",
|
|
760
788
|
type: "number",
|
|
761
789
|
inputMode: "numeric",
|
|
762
|
-
value:
|
|
790
|
+
value: M,
|
|
763
791
|
"aria-label": `What is ${R.prompt}?`,
|
|
764
792
|
disabled: L || V,
|
|
765
793
|
onChange: (y) => u(y.target.value),
|
|
@@ -773,13 +801,13 @@ const fe = O((i, t) => {
|
|
|
773
801
|
{
|
|
774
802
|
type: "button",
|
|
775
803
|
className: "nice-btn nice-btn--primary nice-captcha__verify",
|
|
776
|
-
disabled: L || V ||
|
|
804
|
+
disabled: L || V || M.trim() === "",
|
|
777
805
|
onClick: j,
|
|
778
806
|
children: L ? "…" : "Verify"
|
|
779
807
|
}
|
|
780
808
|
)
|
|
781
809
|
] }),
|
|
782
|
-
|
|
810
|
+
i === "text" && R.kind === "text" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge", children: [
|
|
783
811
|
/* @__PURE__ */ e(
|
|
784
812
|
"canvas",
|
|
785
813
|
{
|
|
@@ -797,7 +825,7 @@ const fe = O((i, t) => {
|
|
|
797
825
|
type: "text",
|
|
798
826
|
autoCapitalize: "characters",
|
|
799
827
|
autoComplete: "off",
|
|
800
|
-
value:
|
|
828
|
+
value: M,
|
|
801
829
|
"aria-label": "Type the characters shown in the image",
|
|
802
830
|
disabled: L || V,
|
|
803
831
|
onChange: (y) => u(y.target.value),
|
|
@@ -811,14 +839,14 @@ const fe = O((i, t) => {
|
|
|
811
839
|
{
|
|
812
840
|
type: "button",
|
|
813
841
|
className: "nice-btn nice-btn--primary nice-captcha__verify",
|
|
814
|
-
disabled: L || V ||
|
|
842
|
+
disabled: L || V || M.trim() === "",
|
|
815
843
|
onClick: j,
|
|
816
844
|
children: L ? "…" : "Verify"
|
|
817
845
|
}
|
|
818
846
|
)
|
|
819
847
|
] }),
|
|
820
|
-
|
|
821
|
-
/* @__PURE__ */ e("span", { className: "nice-captcha__slider-hint", "aria-hidden": "true", children: V ? "Verified
|
|
848
|
+
i === "slider" && R.kind === "slider" && /* @__PURE__ */ a("div", { className: "nice-captcha__challenge nice-captcha__challenge--slider", children: [
|
|
849
|
+
/* @__PURE__ */ e("span", { className: "nice-captcha__slider-hint", "aria-hidden": "true", children: V ? "Verified" : "Slide to the marker" }),
|
|
822
850
|
/* @__PURE__ */ a("div", { className: "nice-captcha__track", children: [
|
|
823
851
|
/* @__PURE__ */ e(
|
|
824
852
|
"span",
|
|
@@ -845,7 +873,7 @@ const fe = O((i, t) => {
|
|
|
845
873
|
] })
|
|
846
874
|
] }),
|
|
847
875
|
/* @__PURE__ */ a("div", { className: "nice-captcha__footer", children: [
|
|
848
|
-
/* @__PURE__ */ e("div", { className: "nice-captcha__message", role: "status", "aria-live": "polite", children:
|
|
876
|
+
/* @__PURE__ */ e("div", { className: "nice-captcha__message", role: "status", "aria-live": "polite", children: O }),
|
|
849
877
|
r && /* @__PURE__ */ e(
|
|
850
878
|
"button",
|
|
851
879
|
{
|
|
@@ -854,7 +882,7 @@ const fe = O((i, t) => {
|
|
|
854
882
|
"aria-label": "Refresh challenge",
|
|
855
883
|
title: "Refresh challenge",
|
|
856
884
|
onClick: G,
|
|
857
|
-
children:
|
|
885
|
+
children: /* @__PURE__ */ e(he, {})
|
|
858
886
|
}
|
|
859
887
|
)
|
|
860
888
|
] })
|
|
@@ -862,18 +890,18 @@ const fe = O((i, t) => {
|
|
|
862
890
|
}
|
|
863
891
|
);
|
|
864
892
|
});
|
|
865
|
-
|
|
866
|
-
const
|
|
867
|
-
{ id: "google", label: "Google",
|
|
868
|
-
{ id: "microsoft", label: "Microsoft",
|
|
869
|
-
{ id: "discord", label: "Discord",
|
|
870
|
-
{ id: "spotify", label: "Spotify",
|
|
871
|
-
{ id: "github", label: "GitHub",
|
|
872
|
-
],
|
|
893
|
+
ge.displayName = "NiceCaptcha";
|
|
894
|
+
const _e = [
|
|
895
|
+
{ id: "google", label: "Google", color: "#4285f4", textColor: "#fff" },
|
|
896
|
+
{ id: "microsoft", label: "Microsoft", color: "#00a4ef", textColor: "#fff" },
|
|
897
|
+
{ id: "discord", label: "Discord", color: "#5865f2", textColor: "#fff" },
|
|
898
|
+
{ id: "spotify", label: "Spotify", color: "#1db954", textColor: "#fff" },
|
|
899
|
+
{ id: "github", label: "GitHub", color: "#24292e", textColor: "#fff" }
|
|
900
|
+
], be = B(
|
|
873
901
|
({
|
|
874
|
-
providers:
|
|
902
|
+
providers: c = _e,
|
|
875
903
|
onProviderClick: t,
|
|
876
|
-
disabled:
|
|
904
|
+
disabled: i = !1,
|
|
877
905
|
loadingProvider: n,
|
|
878
906
|
direction: r = "vertical",
|
|
879
907
|
separatorText: l = "or continue with",
|
|
@@ -892,14 +920,14 @@ const ge = [
|
|
|
892
920
|
/* @__PURE__ */ e("span", { children: l }),
|
|
893
921
|
/* @__PURE__ */ e("hr", {})
|
|
894
922
|
] }),
|
|
895
|
-
/* @__PURE__ */ e("div", { className: "nice-oauth__buttons", children:
|
|
923
|
+
/* @__PURE__ */ e("div", { className: "nice-oauth__buttons", children: c.map((s) => /* @__PURE__ */ a(
|
|
896
924
|
"button",
|
|
897
925
|
{
|
|
898
926
|
type: "button",
|
|
899
927
|
className: `nice-oauth__btn${n === s.id ? " nice-oauth__btn--loading" : ""}`,
|
|
900
928
|
style: { backgroundColor: s.color, color: s.textColor },
|
|
901
929
|
onClick: () => t == null ? void 0 : t(s.id),
|
|
902
|
-
disabled:
|
|
930
|
+
disabled: i || !!n,
|
|
903
931
|
children: [
|
|
904
932
|
s.icon && /* @__PURE__ */ e("span", { className: "nice-oauth__btn-icon", children: s.icon }),
|
|
905
933
|
/* @__PURE__ */ e("span", { className: "nice-oauth__btn-label", children: n === s.id ? "…" : s.label })
|
|
@@ -911,9 +939,9 @@ const ge = [
|
|
|
911
939
|
}
|
|
912
940
|
)
|
|
913
941
|
);
|
|
914
|
-
|
|
915
|
-
const
|
|
916
|
-
function(t,
|
|
942
|
+
be.displayName = "NiceOAuthButtons";
|
|
943
|
+
const ke = B(
|
|
944
|
+
function(t, i) {
|
|
917
945
|
const {
|
|
918
946
|
tokens: n,
|
|
919
947
|
onCreate: r,
|
|
@@ -923,7 +951,7 @@ const ye = O(
|
|
|
923
951
|
title: d = "API Tokens",
|
|
924
952
|
className: $,
|
|
925
953
|
style: s
|
|
926
|
-
} = t, [C, b] = _(!1), [x, g] = _(""), [F, h] = _([]), [m, f] = _("90"), [T, N] = _(null), [P, S] = _(!1), [E, k] = _(null),
|
|
954
|
+
} = t, [C, b] = _(!1), [x, g] = _(""), [F, h] = _([]), [m, f] = _("90"), [T, N] = _(null), [P, S] = _(!1), [E, k] = _(null), D = w(async () => {
|
|
927
955
|
if (!(!r || !x.trim())) {
|
|
928
956
|
S(!0);
|
|
929
957
|
try {
|
|
@@ -933,7 +961,7 @@ const ye = O(
|
|
|
933
961
|
S(!1);
|
|
934
962
|
}
|
|
935
963
|
}
|
|
936
|
-
}, [r, x, F, m]),
|
|
964
|
+
}, [r, x, F, m]), O = w(
|
|
937
965
|
async (u) => {
|
|
938
966
|
if (l) {
|
|
939
967
|
k(u);
|
|
@@ -949,11 +977,11 @@ const ye = O(
|
|
|
949
977
|
h(
|
|
950
978
|
(v) => v.includes(u) ? v.filter((z) => z !== u) : [...v, u]
|
|
951
979
|
);
|
|
952
|
-
},
|
|
953
|
-
return /* @__PURE__ */ a("div", { ref:
|
|
980
|
+
}, M = n.length < p;
|
|
981
|
+
return /* @__PURE__ */ a("div", { ref: i, className: `nice-token-management ${$ ?? ""}`, style: s, children: [
|
|
954
982
|
/* @__PURE__ */ a("div", { className: "nice-token-management__header", children: [
|
|
955
983
|
/* @__PURE__ */ e("h3", { children: d }),
|
|
956
|
-
|
|
984
|
+
M && /* @__PURE__ */ e(
|
|
957
985
|
"button",
|
|
958
986
|
{
|
|
959
987
|
className: "nice-token-management__new-btn",
|
|
@@ -1013,7 +1041,7 @@ const ye = O(
|
|
|
1013
1041
|
)
|
|
1014
1042
|
] }),
|
|
1015
1043
|
/* @__PURE__ */ a("div", { className: "nice-token-management__create-actions", children: [
|
|
1016
|
-
/* @__PURE__ */ e("button", { onClick:
|
|
1044
|
+
/* @__PURE__ */ e("button", { onClick: D, disabled: P || !x.trim(), children: P ? "Creating…" : "Create Token" }),
|
|
1017
1045
|
/* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
|
|
1018
1046
|
] })
|
|
1019
1047
|
] }),
|
|
@@ -1043,7 +1071,7 @@ const ye = O(
|
|
|
1043
1071
|
"button",
|
|
1044
1072
|
{
|
|
1045
1073
|
className: "nice-token-management__revoke-btn",
|
|
1046
|
-
onClick: () =>
|
|
1074
|
+
onClick: () => O(u.id),
|
|
1047
1075
|
disabled: E === u.id,
|
|
1048
1076
|
children: E === u.id ? "Revoking…" : "Revoke"
|
|
1049
1077
|
}
|
|
@@ -1055,14 +1083,14 @@ const ye = O(
|
|
|
1055
1083
|
}
|
|
1056
1084
|
);
|
|
1057
1085
|
export {
|
|
1058
|
-
|
|
1086
|
+
ge as NiceCaptcha,
|
|
1059
1087
|
oe as NiceChangePassword,
|
|
1060
|
-
|
|
1061
|
-
|
|
1088
|
+
ce as NiceLoginForm,
|
|
1089
|
+
be as NiceOAuthButtons,
|
|
1062
1090
|
Z as NicePasswordStrength,
|
|
1063
1091
|
le as NiceRegistrationForm,
|
|
1064
|
-
|
|
1092
|
+
ke as NiceTokenManagement,
|
|
1065
1093
|
de as NiceTwoFaSetup,
|
|
1066
1094
|
J as calcPasswordStrength,
|
|
1067
|
-
|
|
1095
|
+
ye as useAuth
|
|
1068
1096
|
};
|