@nice2dev/auth 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/CHANGELOG.md +19 -0
- package/LICENSE +21 -0
- package/README.md +67 -0
- package/dist/NiceCaptcha.d.ts +32 -0
- package/dist/NiceCaptcha.d.ts.map +1 -0
- package/dist/NiceChangePassword.d.ts +28 -0
- package/dist/NiceChangePassword.d.ts.map +1 -0
- package/dist/NiceLoginForm.d.ts +44 -0
- package/dist/NiceLoginForm.d.ts.map +1 -0
- package/dist/NiceOAuthButtons.d.ts +38 -0
- package/dist/NiceOAuthButtons.d.ts.map +1 -0
- package/dist/NicePasswordStrength.d.ts +23 -0
- package/dist/NicePasswordStrength.d.ts.map +1 -0
- package/dist/NiceRegistrationForm.d.ts +42 -0
- package/dist/NiceRegistrationForm.d.ts.map +1 -0
- package/dist/NiceTokenManagement.d.ts +38 -0
- package/dist/NiceTokenManagement.d.ts.map +1 -0
- package/dist/NiceTwoFaSetup.d.ts +34 -0
- package/dist/NiceTwoFaSetup.d.ts.map +1 -0
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +632 -0
- package/dist/index.mjs.map +1 -0
- package/dist/useAuth.d.ts +82 -0
- package/dist/useAuth.d.ts.map +1 -0
- package/package.json +58 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import { useState as _, useCallback as A, forwardRef as T } from "react";
|
|
2
|
+
import { jsxs as t, jsx as e, Fragment as q } from "react/jsx-runtime";
|
|
3
|
+
function W(a = {}) {
|
|
4
|
+
const { onLogin: n, onRefresh: d, onLogout: m, storageKey: h = "nice_auth", persistAuth: f = !1 } = a, [i, p] = _(() => {
|
|
5
|
+
if (f && typeof window < "u")
|
|
6
|
+
try {
|
|
7
|
+
const o = localStorage.getItem(h);
|
|
8
|
+
if (o)
|
|
9
|
+
return { ...JSON.parse(o), loading: !1, error: null };
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
return { isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null };
|
|
13
|
+
}), s = A((o) => {
|
|
14
|
+
p((l) => {
|
|
15
|
+
const u = { ...l, ...o };
|
|
16
|
+
return f && typeof window < "u" && (u.isAuthenticated ? localStorage.setItem(h, JSON.stringify({ isAuthenticated: !0, user: u.user, tokens: u.tokens })) : localStorage.removeItem(h)), u;
|
|
17
|
+
});
|
|
18
|
+
}, [f, h]), w = A(async (o, l) => {
|
|
19
|
+
s({ loading: !0, error: null });
|
|
20
|
+
try {
|
|
21
|
+
if (n) {
|
|
22
|
+
const u = await n(o, l);
|
|
23
|
+
return s({ isAuthenticated: !0, user: u.user, tokens: u.tokens, loading: !1 }), !0;
|
|
24
|
+
}
|
|
25
|
+
return s({ loading: !1, error: "No login handler configured" }), !1;
|
|
26
|
+
} catch (u) {
|
|
27
|
+
return s({ loading: !1, error: (u == null ? void 0 : u.message) ?? "Login failed" }), !1;
|
|
28
|
+
}
|
|
29
|
+
}, [n, s]), c = A(() => {
|
|
30
|
+
m == null || m(), s({ isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null });
|
|
31
|
+
}, [m, s]), k = A(async () => {
|
|
32
|
+
var o;
|
|
33
|
+
if (!((o = i.tokens) != null && o.refreshToken) || !d) return !1;
|
|
34
|
+
try {
|
|
35
|
+
const l = await d(i.tokens.refreshToken);
|
|
36
|
+
return s({ tokens: l }), !0;
|
|
37
|
+
} catch {
|
|
38
|
+
return c(), !1;
|
|
39
|
+
}
|
|
40
|
+
}, [i.tokens, d, s, c]), b = A((o, l) => {
|
|
41
|
+
s({ isAuthenticated: !0, user: o, tokens: l, loading: !1, error: null });
|
|
42
|
+
}, [s]), C = A((...o) => i.user ? o.every((l) => i.user.roles.includes(l)) : !1, [i.user]), y = A((...o) => i.user ? o.every((l) => i.user.permissions.includes(l)) : !1, [i.user]), $ = A(() => {
|
|
43
|
+
s({ error: null });
|
|
44
|
+
}, [s]);
|
|
45
|
+
return {
|
|
46
|
+
...i,
|
|
47
|
+
login: w,
|
|
48
|
+
logout: c,
|
|
49
|
+
refreshToken: k,
|
|
50
|
+
setAuth: b,
|
|
51
|
+
hasRoles: C,
|
|
52
|
+
hasPermissions: y,
|
|
53
|
+
clearError: $
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
const V = T(({
|
|
57
|
+
onSubmit: a,
|
|
58
|
+
loading: n = !1,
|
|
59
|
+
error: d,
|
|
60
|
+
showRememberMe: m = !0,
|
|
61
|
+
showForgotPassword: h = !0,
|
|
62
|
+
onForgotPassword: f,
|
|
63
|
+
showRegisterLink: i = !0,
|
|
64
|
+
onRegisterClick: p,
|
|
65
|
+
title: s = "Sign In",
|
|
66
|
+
submitLabel: w = "Sign In",
|
|
67
|
+
logo: c,
|
|
68
|
+
footer: k,
|
|
69
|
+
className: b,
|
|
70
|
+
style: C,
|
|
71
|
+
emailLabel: y = "Email",
|
|
72
|
+
passwordLabel: $ = "Password"
|
|
73
|
+
}, o) => {
|
|
74
|
+
const [l, u] = _(""), [F, g] = _(""), [P, v] = _(!1), S = A((x) => {
|
|
75
|
+
x.preventDefault(), a == null || a({ email: l, password: F, rememberMe: P });
|
|
76
|
+
}, [l, F, P, a]);
|
|
77
|
+
return /* @__PURE__ */ t(
|
|
78
|
+
"form",
|
|
79
|
+
{
|
|
80
|
+
ref: o,
|
|
81
|
+
className: `nice-login-form${b ? ` ${b}` : ""}`,
|
|
82
|
+
style: C,
|
|
83
|
+
onSubmit: S,
|
|
84
|
+
noValidate: !0,
|
|
85
|
+
children: [
|
|
86
|
+
c && /* @__PURE__ */ e("div", { className: "nice-login-form__logo", children: c }),
|
|
87
|
+
/* @__PURE__ */ e("h2", { className: "nice-login-form__title", children: s }),
|
|
88
|
+
d && /* @__PURE__ */ e("div", { className: "nice-login-form__error", role: "alert", children: d }),
|
|
89
|
+
/* @__PURE__ */ t("div", { className: "nice-login-form__field", children: [
|
|
90
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-login-email", children: y }),
|
|
91
|
+
/* @__PURE__ */ e(
|
|
92
|
+
"input",
|
|
93
|
+
{
|
|
94
|
+
id: "nice-login-email",
|
|
95
|
+
className: "nice-input",
|
|
96
|
+
type: "email",
|
|
97
|
+
value: l,
|
|
98
|
+
onChange: (x) => u(x.target.value),
|
|
99
|
+
autoComplete: "email",
|
|
100
|
+
required: !0,
|
|
101
|
+
disabled: n
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
] }),
|
|
105
|
+
/* @__PURE__ */ t("div", { className: "nice-login-form__field", children: [
|
|
106
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-login-password", children: $ }),
|
|
107
|
+
/* @__PURE__ */ e(
|
|
108
|
+
"input",
|
|
109
|
+
{
|
|
110
|
+
id: "nice-login-password",
|
|
111
|
+
className: "nice-input",
|
|
112
|
+
type: "password",
|
|
113
|
+
value: F,
|
|
114
|
+
onChange: (x) => g(x.target.value),
|
|
115
|
+
autoComplete: "current-password",
|
|
116
|
+
required: !0,
|
|
117
|
+
disabled: n
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
] }),
|
|
121
|
+
/* @__PURE__ */ t("div", { className: "nice-login-form__options", children: [
|
|
122
|
+
m && /* @__PURE__ */ t("label", { className: "nice-login-form__remember", children: [
|
|
123
|
+
/* @__PURE__ */ e("input", { type: "checkbox", checked: P, onChange: (x) => v(x.target.checked), disabled: n }),
|
|
124
|
+
/* @__PURE__ */ e("span", { children: "Remember me" })
|
|
125
|
+
] }),
|
|
126
|
+
h && /* @__PURE__ */ e("button", { type: "button", className: "nice-login-form__forgot", onClick: f, disabled: n, children: "Forgot password?" })
|
|
127
|
+
] }),
|
|
128
|
+
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary nice-login-form__submit", disabled: n || !l || !F, children: n ? "…" : w }),
|
|
129
|
+
i && /* @__PURE__ */ t("div", { className: "nice-login-form__register", children: [
|
|
130
|
+
/* @__PURE__ */ e("span", { children: "Don't have an account? " }),
|
|
131
|
+
/* @__PURE__ */ e("button", { type: "button", onClick: p, disabled: n, children: "Register" })
|
|
132
|
+
] }),
|
|
133
|
+
k && /* @__PURE__ */ e("div", { className: "nice-login-form__footer", children: k })
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
V.displayName = "NiceLoginForm";
|
|
139
|
+
const j = {
|
|
140
|
+
0: "Very weak",
|
|
141
|
+
1: "Weak",
|
|
142
|
+
2: "Fair",
|
|
143
|
+
3: "Strong",
|
|
144
|
+
4: "Very strong"
|
|
145
|
+
}, B = {
|
|
146
|
+
0: "#d9534f",
|
|
147
|
+
1: "#f0ad4e",
|
|
148
|
+
2: "#5bc0de",
|
|
149
|
+
3: "#5cb85c",
|
|
150
|
+
4: "#2e7d32"
|
|
151
|
+
};
|
|
152
|
+
function I(a) {
|
|
153
|
+
if (!a) return 0;
|
|
154
|
+
let n = 0;
|
|
155
|
+
return a.length >= 8 && n++, a.length >= 12 && n++, /[a-z]/.test(a) && /[A-Z]/.test(a) && n++, /\d/.test(a) && n++, /[^a-zA-Z0-9]/.test(a) && n++, Math.min(4, n);
|
|
156
|
+
}
|
|
157
|
+
const M = T(({
|
|
158
|
+
password: a,
|
|
159
|
+
strength: n,
|
|
160
|
+
showLabel: d = !0,
|
|
161
|
+
labels: m = j,
|
|
162
|
+
className: h
|
|
163
|
+
}, f) => {
|
|
164
|
+
const i = n ?? I(a), p = B[i], s = (i + 1) / 5 * 100;
|
|
165
|
+
return /* @__PURE__ */ t("div", { ref: f, className: `nice-password-strength${h ? ` ${h}` : ""}`, children: [
|
|
166
|
+
/* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e("div", { className: "nice-password-strength__fill", style: { width: `${s}%`, backgroundColor: p } }) }),
|
|
167
|
+
d && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: p }, children: m[i] })
|
|
168
|
+
] });
|
|
169
|
+
});
|
|
170
|
+
M.displayName = "NicePasswordStrength";
|
|
171
|
+
const G = T(({
|
|
172
|
+
onSubmit: a,
|
|
173
|
+
loading: n = !1,
|
|
174
|
+
error: d,
|
|
175
|
+
onLoginClick: m,
|
|
176
|
+
showPasswordStrength: h = !0,
|
|
177
|
+
minPasswordStrength: f = 2,
|
|
178
|
+
termsUrl: i,
|
|
179
|
+
privacyUrl: p,
|
|
180
|
+
title: s = "Create Account",
|
|
181
|
+
logo: w,
|
|
182
|
+
footer: c,
|
|
183
|
+
className: k,
|
|
184
|
+
style: b
|
|
185
|
+
}, C) => {
|
|
186
|
+
const [y, $] = _(""), [o, l] = _(""), [u, F] = _(""), [g, P] = _(""), [v, S] = _(""), [x, D] = _(!1), L = I(g), E = g === v, R = y && u && g && E && x && L >= f && !n, r = A((N) => {
|
|
187
|
+
N.preventDefault(), R && (a == null || a({ firstName: y, lastName: o, email: u, password: g, acceptTerms: x }));
|
|
188
|
+
}, [R, y, o, u, g, x, a]);
|
|
189
|
+
return /* @__PURE__ */ t(
|
|
190
|
+
"form",
|
|
191
|
+
{
|
|
192
|
+
ref: C,
|
|
193
|
+
className: `nice-register-form${k ? ` ${k}` : ""}`,
|
|
194
|
+
style: b,
|
|
195
|
+
onSubmit: r,
|
|
196
|
+
noValidate: !0,
|
|
197
|
+
children: [
|
|
198
|
+
w && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: w }),
|
|
199
|
+
/* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: s }),
|
|
200
|
+
d && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: d }),
|
|
201
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__row", children: [
|
|
202
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
203
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
|
|
204
|
+
/* @__PURE__ */ e("input", { id: "nice-reg-first", className: "nice-input", type: "text", value: y, onChange: (N) => $(N.target.value), required: !0, disabled: n, autoComplete: "given-name" })
|
|
205
|
+
] }),
|
|
206
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
207
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-last", children: "Last name" }),
|
|
208
|
+
/* @__PURE__ */ e("input", { id: "nice-reg-last", className: "nice-input", type: "text", value: o, onChange: (N) => l(N.target.value), disabled: n, autoComplete: "family-name" })
|
|
209
|
+
] })
|
|
210
|
+
] }),
|
|
211
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
212
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-email", children: "Email *" }),
|
|
213
|
+
/* @__PURE__ */ e("input", { id: "nice-reg-email", className: "nice-input", type: "email", value: u, onChange: (N) => F(N.target.value), required: !0, disabled: n, autoComplete: "email" })
|
|
214
|
+
] }),
|
|
215
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
216
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-pass", children: "Password *" }),
|
|
217
|
+
/* @__PURE__ */ e("input", { id: "nice-reg-pass", className: "nice-input", type: "password", value: g, onChange: (N) => P(N.target.value), required: !0, disabled: n, autoComplete: "new-password" }),
|
|
218
|
+
h && g.length > 0 && /* @__PURE__ */ e(M, { password: g })
|
|
219
|
+
] }),
|
|
220
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
221
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-confirm", children: "Confirm password *" }),
|
|
222
|
+
/* @__PURE__ */ e("input", { id: "nice-reg-confirm", className: "nice-input", type: "password", value: v, onChange: (N) => S(N.target.value), required: !0, disabled: n, autoComplete: "new-password" }),
|
|
223
|
+
v && !E && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
|
|
224
|
+
] }),
|
|
225
|
+
/* @__PURE__ */ t("label", { className: "nice-register-form__terms", children: [
|
|
226
|
+
/* @__PURE__ */ e("input", { type: "checkbox", checked: x, onChange: (N) => D(N.target.checked), disabled: n }),
|
|
227
|
+
/* @__PURE__ */ t("span", { children: [
|
|
228
|
+
"I accept the",
|
|
229
|
+
" ",
|
|
230
|
+
i ? /* @__PURE__ */ e("a", { href: i, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
|
|
231
|
+
p && /* @__PURE__ */ t(q, { children: [
|
|
232
|
+
" and ",
|
|
233
|
+
/* @__PURE__ */ e("a", { href: p, target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" })
|
|
234
|
+
] }),
|
|
235
|
+
" *"
|
|
236
|
+
] })
|
|
237
|
+
] }),
|
|
238
|
+
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary nice-register-form__submit", disabled: !R, children: n ? "…" : "Register" }),
|
|
239
|
+
m && /* @__PURE__ */ t("div", { className: "nice-register-form__login", children: [
|
|
240
|
+
/* @__PURE__ */ e("span", { children: "Already have an account? " }),
|
|
241
|
+
/* @__PURE__ */ e("button", { type: "button", onClick: m, children: "Sign in" })
|
|
242
|
+
] }),
|
|
243
|
+
c && /* @__PURE__ */ e("div", { className: "nice-register-form__footer", children: c })
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
G.displayName = "NiceRegistrationForm";
|
|
249
|
+
const Q = T(({
|
|
250
|
+
requireCurrentPassword: a = !0,
|
|
251
|
+
onSubmit: n,
|
|
252
|
+
loading: d = !1,
|
|
253
|
+
error: m,
|
|
254
|
+
success: h,
|
|
255
|
+
minPasswordStrength: f = 2,
|
|
256
|
+
title: i = "Change Password",
|
|
257
|
+
className: p,
|
|
258
|
+
style: s
|
|
259
|
+
}, w) => {
|
|
260
|
+
const [c, k] = _(""), [b, C] = _(""), [y, $] = _(""), o = I(b), l = b === y, u = (!a || c.length > 0) && b.length > 0 && l && o >= f && !d, F = A((g) => {
|
|
261
|
+
g.preventDefault(), u && (n == null || n({
|
|
262
|
+
currentPassword: a ? c : void 0,
|
|
263
|
+
newPassword: b
|
|
264
|
+
}));
|
|
265
|
+
}, [u, c, b, a, n]);
|
|
266
|
+
return /* @__PURE__ */ t(
|
|
267
|
+
"form",
|
|
268
|
+
{
|
|
269
|
+
ref: w,
|
|
270
|
+
className: `nice-change-password${p ? ` ${p}` : ""}`,
|
|
271
|
+
style: s,
|
|
272
|
+
onSubmit: F,
|
|
273
|
+
noValidate: !0,
|
|
274
|
+
children: [
|
|
275
|
+
/* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: i }),
|
|
276
|
+
m && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: m }),
|
|
277
|
+
h && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: h }),
|
|
278
|
+
a && /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
279
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
|
|
280
|
+
/* @__PURE__ */ e(
|
|
281
|
+
"input",
|
|
282
|
+
{
|
|
283
|
+
id: "nice-cp-current",
|
|
284
|
+
className: "nice-input",
|
|
285
|
+
type: "password",
|
|
286
|
+
value: c,
|
|
287
|
+
onChange: (g) => k(g.target.value),
|
|
288
|
+
autoComplete: "current-password",
|
|
289
|
+
disabled: d,
|
|
290
|
+
required: !0
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
] }),
|
|
294
|
+
/* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
295
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
|
|
296
|
+
/* @__PURE__ */ e(
|
|
297
|
+
"input",
|
|
298
|
+
{
|
|
299
|
+
id: "nice-cp-new",
|
|
300
|
+
className: "nice-input",
|
|
301
|
+
type: "password",
|
|
302
|
+
value: b,
|
|
303
|
+
onChange: (g) => C(g.target.value),
|
|
304
|
+
autoComplete: "new-password",
|
|
305
|
+
disabled: d,
|
|
306
|
+
required: !0
|
|
307
|
+
}
|
|
308
|
+
),
|
|
309
|
+
b.length > 0 && /* @__PURE__ */ e(M, { password: b })
|
|
310
|
+
] }),
|
|
311
|
+
/* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
312
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
|
|
313
|
+
/* @__PURE__ */ e(
|
|
314
|
+
"input",
|
|
315
|
+
{
|
|
316
|
+
id: "nice-cp-confirm",
|
|
317
|
+
className: "nice-input",
|
|
318
|
+
type: "password",
|
|
319
|
+
value: y,
|
|
320
|
+
onChange: (g) => $(g.target.value),
|
|
321
|
+
autoComplete: "new-password",
|
|
322
|
+
disabled: d,
|
|
323
|
+
required: !0
|
|
324
|
+
}
|
|
325
|
+
),
|
|
326
|
+
y && !l && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
|
|
327
|
+
] }),
|
|
328
|
+
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !u, children: d ? "…" : "Change Password" })
|
|
329
|
+
]
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
});
|
|
333
|
+
Q.displayName = "NiceChangePassword";
|
|
334
|
+
const z = T(({
|
|
335
|
+
secret: a,
|
|
336
|
+
qrCodeUrl: n,
|
|
337
|
+
issuer: d,
|
|
338
|
+
accountName: m,
|
|
339
|
+
onVerify: h,
|
|
340
|
+
loading: f = !1,
|
|
341
|
+
error: i,
|
|
342
|
+
onCancel: p,
|
|
343
|
+
recoveryCodes: s,
|
|
344
|
+
step: w = "setup",
|
|
345
|
+
onStepChange: c,
|
|
346
|
+
className: k,
|
|
347
|
+
style: b
|
|
348
|
+
}, C) => {
|
|
349
|
+
const [y, $] = _(""), [o, l] = _(!1), [u, F] = _(!1), g = A((v) => {
|
|
350
|
+
v.preventDefault(), y.length >= 6 && (h == null || h(y));
|
|
351
|
+
}, [y, h]), P = `otpauth://totp/${d ? `${d}:` : ""}${m ?? "user"}?secret=${a}${d ? `&issuer=${d}` : ""}&digits=6&period=30`;
|
|
352
|
+
return /* @__PURE__ */ t("div", { ref: C, className: `nice-2fa-setup${k ? ` ${k}` : ""}`, style: b, children: [
|
|
353
|
+
/* @__PURE__ */ e("h3", { className: "nice-2fa-setup__title", children: "Two-Factor Authentication" }),
|
|
354
|
+
w === "setup" && /* @__PURE__ */ t("div", { className: "nice-2fa-setup__step", children: [
|
|
355
|
+
/* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Scan this QR code with your authenticator app (Google Authenticator, Authy, etc.):" }),
|
|
356
|
+
n ? /* @__PURE__ */ e("img", { src: n, alt: "2FA QR Code", className: "nice-2fa-setup__qr" }) : /* @__PURE__ */ t("div", { className: "nice-2fa-setup__qr-placeholder", children: [
|
|
357
|
+
/* @__PURE__ */ e("span", { children: "QR Code" }),
|
|
358
|
+
/* @__PURE__ */ e("code", { className: "nice-2fa-setup__uri", children: P })
|
|
359
|
+
] }),
|
|
360
|
+
/* @__PURE__ */ t("div", { className: "nice-2fa-setup__secret", children: [
|
|
361
|
+
/* @__PURE__ */ e("span", { children: "Or enter manually: " }),
|
|
362
|
+
o ? /* @__PURE__ */ e("code", { className: "nice-2fa-setup__secret-key", children: a }) : /* @__PURE__ */ e("button", { type: "button", onClick: () => l(!0), children: "Show secret key" })
|
|
363
|
+
] }),
|
|
364
|
+
/* @__PURE__ */ e("button", { type: "button", className: "nice-btn nice-btn--primary", onClick: () => c == null ? void 0 : c("verify"), children: "Next — Verify" })
|
|
365
|
+
] }),
|
|
366
|
+
w === "verify" && /* @__PURE__ */ t("form", { className: "nice-2fa-setup__step", onSubmit: g, children: [
|
|
367
|
+
/* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Enter the 6-digit code from your authenticator app:" }),
|
|
368
|
+
i && /* @__PURE__ */ e("div", { className: "nice-2fa-setup__error", role: "alert", children: i }),
|
|
369
|
+
/* @__PURE__ */ e(
|
|
370
|
+
"input",
|
|
371
|
+
{
|
|
372
|
+
className: "nice-input nice-2fa-setup__code-input",
|
|
373
|
+
type: "text",
|
|
374
|
+
inputMode: "numeric",
|
|
375
|
+
maxLength: 6,
|
|
376
|
+
value: y,
|
|
377
|
+
onChange: (v) => $(v.target.value.replace(/\D/g, "").slice(0, 6)),
|
|
378
|
+
placeholder: "000000",
|
|
379
|
+
autoFocus: !0,
|
|
380
|
+
disabled: f,
|
|
381
|
+
autoComplete: "one-time-code"
|
|
382
|
+
}
|
|
383
|
+
),
|
|
384
|
+
/* @__PURE__ */ t("div", { className: "nice-2fa-setup__actions", children: [
|
|
385
|
+
/* @__PURE__ */ e("button", { type: "button", className: "nice-btn", onClick: () => c == null ? void 0 : c("setup"), children: "Back" }),
|
|
386
|
+
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: f || y.length < 6, children: f ? "…" : "Verify" })
|
|
387
|
+
] })
|
|
388
|
+
] }),
|
|
389
|
+
w === "recovery" && s && /* @__PURE__ */ t("div", { className: "nice-2fa-setup__step", children: [
|
|
390
|
+
/* @__PURE__ */ e("p", { className: "nice-2fa-setup__instruction", children: "Save these recovery codes in a safe place. Each code can only be used once:" }),
|
|
391
|
+
/* @__PURE__ */ e("div", { className: "nice-2fa-setup__recovery-codes", children: s.map((v, S) => /* @__PURE__ */ e("code", { className: "nice-2fa-setup__recovery-code", children: v }, S)) }),
|
|
392
|
+
/* @__PURE__ */ e(
|
|
393
|
+
"button",
|
|
394
|
+
{
|
|
395
|
+
type: "button",
|
|
396
|
+
className: "nice-btn",
|
|
397
|
+
onClick: () => {
|
|
398
|
+
var v;
|
|
399
|
+
(v = navigator.clipboard) == null || v.writeText(s.join(`
|
|
400
|
+
`)), F(!0);
|
|
401
|
+
},
|
|
402
|
+
children: u ? "Copied!" : "Copy all codes"
|
|
403
|
+
}
|
|
404
|
+
),
|
|
405
|
+
p && /* @__PURE__ */ e("button", { type: "button", className: "nice-btn nice-btn--primary", onClick: p, children: "Done" })
|
|
406
|
+
] }),
|
|
407
|
+
p && w !== "recovery" && /* @__PURE__ */ e("button", { type: "button", className: "nice-2fa-setup__cancel", onClick: p, children: "Cancel" })
|
|
408
|
+
] });
|
|
409
|
+
});
|
|
410
|
+
z.displayName = "NiceTwoFaSetup";
|
|
411
|
+
const J = T(({
|
|
412
|
+
provider: a = "custom",
|
|
413
|
+
siteKey: n,
|
|
414
|
+
onVerify: d,
|
|
415
|
+
onExpire: m,
|
|
416
|
+
onError: h,
|
|
417
|
+
theme: f = "light",
|
|
418
|
+
size: i = "normal",
|
|
419
|
+
customRender: p,
|
|
420
|
+
className: s,
|
|
421
|
+
style: w
|
|
422
|
+
}, c) => a === "custom" && p ? /* @__PURE__ */ e("div", { ref: c, className: `nice-captcha nice-captcha--custom${s ? ` ${s}` : ""}`, style: w, children: p }) : /* @__PURE__ */ e(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
ref: c,
|
|
426
|
+
className: `nice-captcha nice-captcha--${a} nice-captcha--${f}${i === "compact" ? " nice-captcha--compact" : ""}${s ? ` ${s}` : ""}`,
|
|
427
|
+
style: w,
|
|
428
|
+
"data-sitekey": n,
|
|
429
|
+
"data-theme": f,
|
|
430
|
+
"data-size": i,
|
|
431
|
+
children: /* @__PURE__ */ t("div", { className: "nice-captcha__placeholder", children: [
|
|
432
|
+
/* @__PURE__ */ t("span", { children: [
|
|
433
|
+
"🔒 Captcha (",
|
|
434
|
+
a,
|
|
435
|
+
")"
|
|
436
|
+
] }),
|
|
437
|
+
/* @__PURE__ */ t("p", { children: [
|
|
438
|
+
"Load the ",
|
|
439
|
+
a,
|
|
440
|
+
" SDK to activate verification."
|
|
441
|
+
] })
|
|
442
|
+
] })
|
|
443
|
+
}
|
|
444
|
+
));
|
|
445
|
+
J.displayName = "NiceCaptcha";
|
|
446
|
+
const K = [
|
|
447
|
+
{ id: "google", label: "Google", icon: "🔵", color: "#4285f4", textColor: "#fff" },
|
|
448
|
+
{ id: "microsoft", label: "Microsoft", icon: "🟦", color: "#00a4ef", textColor: "#fff" },
|
|
449
|
+
{ id: "discord", label: "Discord", icon: "💬", color: "#5865f2", textColor: "#fff" },
|
|
450
|
+
{ id: "spotify", label: "Spotify", icon: "🎵", color: "#1db954", textColor: "#fff" },
|
|
451
|
+
{ id: "github", label: "GitHub", icon: "🐙", color: "#24292e", textColor: "#fff" }
|
|
452
|
+
], U = T(({
|
|
453
|
+
providers: a = K,
|
|
454
|
+
onProviderClick: n,
|
|
455
|
+
disabled: d = !1,
|
|
456
|
+
loadingProvider: m,
|
|
457
|
+
direction: h = "vertical",
|
|
458
|
+
separatorText: f = "or continue with",
|
|
459
|
+
showSeparator: i = !0,
|
|
460
|
+
className: p,
|
|
461
|
+
style: s
|
|
462
|
+
}, w) => /* @__PURE__ */ t(
|
|
463
|
+
"div",
|
|
464
|
+
{
|
|
465
|
+
ref: w,
|
|
466
|
+
className: `nice-oauth nice-oauth--${h}${p ? ` ${p}` : ""}`,
|
|
467
|
+
style: s,
|
|
468
|
+
children: [
|
|
469
|
+
i && /* @__PURE__ */ t("div", { className: "nice-oauth__separator", children: [
|
|
470
|
+
/* @__PURE__ */ e("hr", {}),
|
|
471
|
+
/* @__PURE__ */ e("span", { children: f }),
|
|
472
|
+
/* @__PURE__ */ e("hr", {})
|
|
473
|
+
] }),
|
|
474
|
+
/* @__PURE__ */ e("div", { className: "nice-oauth__buttons", children: a.map((c) => /* @__PURE__ */ t(
|
|
475
|
+
"button",
|
|
476
|
+
{
|
|
477
|
+
type: "button",
|
|
478
|
+
className: `nice-oauth__btn${m === c.id ? " nice-oauth__btn--loading" : ""}`,
|
|
479
|
+
style: { backgroundColor: c.color, color: c.textColor },
|
|
480
|
+
onClick: () => n == null ? void 0 : n(c.id),
|
|
481
|
+
disabled: d || !!m,
|
|
482
|
+
children: [
|
|
483
|
+
c.icon && /* @__PURE__ */ e("span", { className: "nice-oauth__btn-icon", children: c.icon }),
|
|
484
|
+
/* @__PURE__ */ e("span", { className: "nice-oauth__btn-label", children: m === c.id ? "…" : c.label })
|
|
485
|
+
]
|
|
486
|
+
},
|
|
487
|
+
c.id
|
|
488
|
+
)) })
|
|
489
|
+
]
|
|
490
|
+
}
|
|
491
|
+
));
|
|
492
|
+
U.displayName = "NiceOAuthButtons";
|
|
493
|
+
const X = T(function(n, d) {
|
|
494
|
+
const {
|
|
495
|
+
tokens: m,
|
|
496
|
+
onCreate: h,
|
|
497
|
+
onRevoke: f,
|
|
498
|
+
availableScopes: i = [],
|
|
499
|
+
maxTokens: p = 10,
|
|
500
|
+
title: s = "API Tokens",
|
|
501
|
+
className: w,
|
|
502
|
+
style: c
|
|
503
|
+
} = n, [k, b] = _(!1), [C, y] = _(""), [$, o] = _([]), [l, u] = _("90"), [F, g] = _(null), [P, v] = _(!1), [S, x] = _(null), D = A(async () => {
|
|
504
|
+
if (!(!h || !C.trim())) {
|
|
505
|
+
v(!0);
|
|
506
|
+
try {
|
|
507
|
+
const r = l ? parseInt(l, 10) : void 0, N = await h(C.trim(), $, r);
|
|
508
|
+
g(N), y(""), o([]), b(!1);
|
|
509
|
+
} finally {
|
|
510
|
+
v(!1);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}, [h, C, $, l]), L = A(async (r) => {
|
|
514
|
+
if (f) {
|
|
515
|
+
x(r);
|
|
516
|
+
try {
|
|
517
|
+
await f(r);
|
|
518
|
+
} finally {
|
|
519
|
+
x(null);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
}, [f]), E = (r) => {
|
|
523
|
+
o((N) => N.includes(r) ? N.filter((O) => O !== r) : [...N, r]);
|
|
524
|
+
}, R = m.length < p;
|
|
525
|
+
return /* @__PURE__ */ t("div", { ref: d, className: `nice-token-management ${w ?? ""}`, style: c, children: [
|
|
526
|
+
/* @__PURE__ */ t("div", { className: "nice-token-management__header", children: [
|
|
527
|
+
/* @__PURE__ */ e("h3", { children: s }),
|
|
528
|
+
R && /* @__PURE__ */ e("button", { className: "nice-token-management__new-btn", onClick: () => b(!0), disabled: k, children: "+ New Token" })
|
|
529
|
+
] }),
|
|
530
|
+
F && /* @__PURE__ */ t("div", { className: "nice-token-management__reveal", children: [
|
|
531
|
+
/* @__PURE__ */ t("p", { children: [
|
|
532
|
+
/* @__PURE__ */ e("strong", { children: "New token created!" }),
|
|
533
|
+
" Copy it now — it won't be shown again."
|
|
534
|
+
] }),
|
|
535
|
+
/* @__PURE__ */ e("code", { className: "nice-token-management__token-value", children: F }),
|
|
536
|
+
/* @__PURE__ */ e("button", { onClick: () => g(null), children: "Dismiss" })
|
|
537
|
+
] }),
|
|
538
|
+
k && /* @__PURE__ */ t("div", { className: "nice-token-management__create-form", children: [
|
|
539
|
+
/* @__PURE__ */ t("label", { children: [
|
|
540
|
+
"Name",
|
|
541
|
+
/* @__PURE__ */ e(
|
|
542
|
+
"input",
|
|
543
|
+
{
|
|
544
|
+
type: "text",
|
|
545
|
+
value: C,
|
|
546
|
+
onChange: (r) => y(r.target.value),
|
|
547
|
+
placeholder: "My API token",
|
|
548
|
+
maxLength: 64
|
|
549
|
+
}
|
|
550
|
+
)
|
|
551
|
+
] }),
|
|
552
|
+
i.length > 0 && /* @__PURE__ */ t("fieldset", { children: [
|
|
553
|
+
/* @__PURE__ */ e("legend", { children: "Scopes" }),
|
|
554
|
+
i.map((r) => /* @__PURE__ */ t("label", { className: "nice-token-management__scope", children: [
|
|
555
|
+
/* @__PURE__ */ e(
|
|
556
|
+
"input",
|
|
557
|
+
{
|
|
558
|
+
type: "checkbox",
|
|
559
|
+
checked: $.includes(r),
|
|
560
|
+
onChange: () => E(r)
|
|
561
|
+
}
|
|
562
|
+
),
|
|
563
|
+
r
|
|
564
|
+
] }, r))
|
|
565
|
+
] }),
|
|
566
|
+
/* @__PURE__ */ t("label", { children: [
|
|
567
|
+
"Expires in (days)",
|
|
568
|
+
/* @__PURE__ */ e(
|
|
569
|
+
"input",
|
|
570
|
+
{
|
|
571
|
+
type: "number",
|
|
572
|
+
value: l,
|
|
573
|
+
onChange: (r) => u(r.target.value),
|
|
574
|
+
min: 1,
|
|
575
|
+
max: 365
|
|
576
|
+
}
|
|
577
|
+
)
|
|
578
|
+
] }),
|
|
579
|
+
/* @__PURE__ */ t("div", { className: "nice-token-management__create-actions", children: [
|
|
580
|
+
/* @__PURE__ */ e("button", { onClick: D, disabled: P || !C.trim(), children: P ? "Creating…" : "Create Token" }),
|
|
581
|
+
/* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
|
|
582
|
+
] })
|
|
583
|
+
] }),
|
|
584
|
+
m.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ t("table", { className: "nice-token-management__table", children: [
|
|
585
|
+
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ t("tr", { children: [
|
|
586
|
+
/* @__PURE__ */ e("th", { children: "Name" }),
|
|
587
|
+
/* @__PURE__ */ e("th", { children: "Prefix" }),
|
|
588
|
+
/* @__PURE__ */ e("th", { children: "Created" }),
|
|
589
|
+
/* @__PURE__ */ e("th", { children: "Expires" }),
|
|
590
|
+
/* @__PURE__ */ e("th", { children: "Last Used" }),
|
|
591
|
+
/* @__PURE__ */ e("th", { children: "Scopes" }),
|
|
592
|
+
/* @__PURE__ */ e("th", {})
|
|
593
|
+
] }) }),
|
|
594
|
+
/* @__PURE__ */ e("tbody", { children: m.map((r) => {
|
|
595
|
+
var N;
|
|
596
|
+
return /* @__PURE__ */ t("tr", { children: [
|
|
597
|
+
/* @__PURE__ */ e("td", { children: r.name }),
|
|
598
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ t("code", { children: [
|
|
599
|
+
r.prefix,
|
|
600
|
+
"…"
|
|
601
|
+
] }) }),
|
|
602
|
+
/* @__PURE__ */ e("td", { children: r.createdAt }),
|
|
603
|
+
/* @__PURE__ */ e("td", { children: r.expiresAt ?? "—" }),
|
|
604
|
+
/* @__PURE__ */ e("td", { children: r.lastUsedAt ?? "Never" }),
|
|
605
|
+
/* @__PURE__ */ e("td", { children: ((N = r.scopes) == null ? void 0 : N.join(", ")) || "—" }),
|
|
606
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
|
|
607
|
+
"button",
|
|
608
|
+
{
|
|
609
|
+
className: "nice-token-management__revoke-btn",
|
|
610
|
+
onClick: () => L(r.id),
|
|
611
|
+
disabled: S === r.id,
|
|
612
|
+
children: S === r.id ? "Revoking…" : "Revoke"
|
|
613
|
+
}
|
|
614
|
+
) })
|
|
615
|
+
] }, r.id);
|
|
616
|
+
}) })
|
|
617
|
+
] })
|
|
618
|
+
] });
|
|
619
|
+
});
|
|
620
|
+
export {
|
|
621
|
+
J as NiceCaptcha,
|
|
622
|
+
Q as NiceChangePassword,
|
|
623
|
+
V as NiceLoginForm,
|
|
624
|
+
U as NiceOAuthButtons,
|
|
625
|
+
M as NicePasswordStrength,
|
|
626
|
+
G as NiceRegistrationForm,
|
|
627
|
+
X as NiceTokenManagement,
|
|
628
|
+
z as NiceTwoFaSetup,
|
|
629
|
+
I as calcPasswordStrength,
|
|
630
|
+
W as useAuth
|
|
631
|
+
};
|
|
632
|
+
//# sourceMappingURL=index.mjs.map
|