@nice2dev/auth 1.0.8 → 1.0.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/dist/NiceChangePassword.d.ts.map +1 -1
- package/dist/NiceLoginForm.d.ts.map +1 -1
- package/dist/NicePasswordStrength.d.ts.map +1 -1
- package/dist/NiceRegistrationForm.d.ts.map +1 -1
- package/dist/NiceTokenManagement.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +437 -305
- package/dist/index.mjs.map +1 -1
- package/dist/useAuth.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -10,36 +10,63 @@ function X(a = {}) {
|
|
|
10
10
|
} catch {
|
|
11
11
|
}
|
|
12
12
|
return { isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null };
|
|
13
|
-
}), c = x(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
}), c = x(
|
|
14
|
+
(s) => {
|
|
15
|
+
m((h) => {
|
|
16
|
+
const p = { ...h, ...s };
|
|
17
|
+
return f && typeof window < "u" && (p.isAuthenticated ? localStorage.setItem(
|
|
18
|
+
u,
|
|
19
|
+
JSON.stringify({ isAuthenticated: !0, user: p.user })
|
|
20
|
+
) : localStorage.removeItem(u)), p;
|
|
21
|
+
});
|
|
22
|
+
},
|
|
23
|
+
[f, u]
|
|
24
|
+
), v = x(
|
|
25
|
+
async (s, h) => {
|
|
26
|
+
c({ loading: !0, error: null });
|
|
27
|
+
try {
|
|
28
|
+
if (n) {
|
|
29
|
+
const p = await n(s, h);
|
|
30
|
+
return c({
|
|
31
|
+
isAuthenticated: !0,
|
|
32
|
+
user: p.user,
|
|
33
|
+
tokens: p.tokens,
|
|
34
|
+
loading: !1
|
|
35
|
+
}), !0;
|
|
36
|
+
}
|
|
37
|
+
return c({ loading: !1, error: "No login handler configured" }), !1;
|
|
38
|
+
} catch (p) {
|
|
39
|
+
return c({
|
|
40
|
+
loading: !1,
|
|
41
|
+
error: (p == null ? void 0 : p.message) ?? "Login failed"
|
|
42
|
+
}), !1;
|
|
24
43
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}, [n, c]), i = x(() => {
|
|
44
|
+
},
|
|
45
|
+
[n, c]
|
|
46
|
+
), i = x(() => {
|
|
30
47
|
d == null || d(), c({ isAuthenticated: !1, user: null, tokens: null, loading: !1, error: null });
|
|
31
48
|
}, [d, c]), k = x(async () => {
|
|
32
49
|
var s;
|
|
33
|
-
if (!((s = r.tokens) != null && s.refreshToken) || !o)
|
|
50
|
+
if (!((s = r.tokens) != null && s.refreshToken) || !o)
|
|
51
|
+
return !1;
|
|
34
52
|
try {
|
|
35
53
|
const h = await o(r.tokens.refreshToken);
|
|
36
54
|
return c({ tokens: h }), !0;
|
|
37
55
|
} catch {
|
|
38
56
|
return i(), !1;
|
|
39
57
|
}
|
|
40
|
-
}, [r.tokens, o, c, i]), b = x(
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
}, [r.tokens, o, c, i]), b = x(
|
|
59
|
+
(s, h) => {
|
|
60
|
+
c({ isAuthenticated: !0, user: s, tokens: h, loading: !1, error: null });
|
|
61
|
+
},
|
|
62
|
+
[c]
|
|
63
|
+
), C = x(
|
|
64
|
+
(...s) => r.user ? s.every((h) => r.user.roles.includes(h)) : !1,
|
|
65
|
+
[r.user]
|
|
66
|
+
), w = x(
|
|
67
|
+
(...s) => r.user ? s.every((h) => r.user.permissions.includes(h)) : !1,
|
|
68
|
+
[r.user]
|
|
69
|
+
), A = x(() => {
|
|
43
70
|
c({ error: null });
|
|
44
71
|
}, [c]);
|
|
45
72
|
return {
|
|
@@ -185,186 +212,276 @@ const B = {
|
|
|
185
212
|
4: "#2e7d32"
|
|
186
213
|
};
|
|
187
214
|
function I(a) {
|
|
188
|
-
if (!a)
|
|
215
|
+
if (!a)
|
|
216
|
+
return 0;
|
|
189
217
|
let n = 0;
|
|
190
218
|
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);
|
|
191
219
|
}
|
|
192
|
-
const M = E(
|
|
193
|
-
password: a,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
220
|
+
const M = E(
|
|
221
|
+
({ password: a, strength: n, showLabel: o = !0, labels: d = B, className: u }, f) => {
|
|
222
|
+
const r = n ?? I(a), m = G[r], c = (r + 1) / 5 * 100;
|
|
223
|
+
return /* @__PURE__ */ t("div", { ref: f, className: `nice-password-strength${u ? ` ${u}` : ""}`, children: [
|
|
224
|
+
/* @__PURE__ */ e("div", { className: "nice-password-strength__bar", children: /* @__PURE__ */ e(
|
|
225
|
+
"div",
|
|
226
|
+
{
|
|
227
|
+
className: "nice-password-strength__fill",
|
|
228
|
+
style: { width: `${c}%`, backgroundColor: m }
|
|
229
|
+
}
|
|
230
|
+
) }),
|
|
231
|
+
o && /* @__PURE__ */ e("span", { className: "nice-password-strength__label", style: { color: m }, children: d[r] })
|
|
232
|
+
] });
|
|
233
|
+
}
|
|
234
|
+
);
|
|
205
235
|
M.displayName = "NicePasswordStrength";
|
|
206
|
-
const Q = E(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
const Q = E(
|
|
237
|
+
({
|
|
238
|
+
onSubmit: a,
|
|
239
|
+
loading: n = !1,
|
|
240
|
+
error: o,
|
|
241
|
+
onLoginClick: d,
|
|
242
|
+
showPasswordStrength: u = !0,
|
|
243
|
+
minPasswordStrength: f = 2,
|
|
244
|
+
termsUrl: r,
|
|
245
|
+
privacyUrl: m,
|
|
246
|
+
title: c = "Create Account",
|
|
247
|
+
logo: v,
|
|
248
|
+
footer: i,
|
|
249
|
+
className: k,
|
|
250
|
+
style: b
|
|
251
|
+
}, C) => {
|
|
252
|
+
const [w, A] = _(""), [s, h] = _(""), [p, $] = _(""), [g, S] = _(""), [y, T] = _(""), [R, L] = _(!1), P = I(g), F = g === y, D = w && p && g && F && R && P >= f && !n, l = x(
|
|
253
|
+
(N) => {
|
|
254
|
+
N.preventDefault(), D && (a == null || a({ firstName: w, lastName: s, email: p, password: g, acceptTerms: R }));
|
|
255
|
+
},
|
|
256
|
+
[D, w, s, p, g, R, a]
|
|
257
|
+
);
|
|
258
|
+
return /* @__PURE__ */ t(
|
|
259
|
+
"form",
|
|
260
|
+
{
|
|
261
|
+
ref: C,
|
|
262
|
+
className: `nice-register-form${k ? ` ${k}` : ""}`,
|
|
263
|
+
style: b,
|
|
264
|
+
onSubmit: l,
|
|
265
|
+
noValidate: !0,
|
|
266
|
+
children: [
|
|
267
|
+
v && /* @__PURE__ */ e("div", { className: "nice-register-form__logo", children: v }),
|
|
268
|
+
/* @__PURE__ */ e("h2", { className: "nice-register-form__title", children: c }),
|
|
269
|
+
o && /* @__PURE__ */ e("div", { className: "nice-register-form__error", role: "alert", children: o }),
|
|
270
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__row", children: [
|
|
271
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
272
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-first", children: "First name *" }),
|
|
273
|
+
/* @__PURE__ */ e(
|
|
274
|
+
"input",
|
|
275
|
+
{
|
|
276
|
+
id: "nice-reg-first",
|
|
277
|
+
className: "nice-input",
|
|
278
|
+
type: "text",
|
|
279
|
+
value: w,
|
|
280
|
+
onChange: (N) => A(N.target.value),
|
|
281
|
+
required: !0,
|
|
282
|
+
disabled: n,
|
|
283
|
+
autoComplete: "given-name"
|
|
284
|
+
}
|
|
285
|
+
)
|
|
286
|
+
] }),
|
|
287
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
288
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-last", children: "Last name" }),
|
|
289
|
+
/* @__PURE__ */ e(
|
|
290
|
+
"input",
|
|
291
|
+
{
|
|
292
|
+
id: "nice-reg-last",
|
|
293
|
+
className: "nice-input",
|
|
294
|
+
type: "text",
|
|
295
|
+
value: s,
|
|
296
|
+
onChange: (N) => h(N.target.value),
|
|
297
|
+
disabled: n,
|
|
298
|
+
autoComplete: "family-name"
|
|
299
|
+
}
|
|
300
|
+
)
|
|
301
|
+
] })
|
|
302
|
+
] }),
|
|
237
303
|
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
238
|
-
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-
|
|
239
|
-
/* @__PURE__ */ e(
|
|
304
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-email", children: "Email *" }),
|
|
305
|
+
/* @__PURE__ */ e(
|
|
306
|
+
"input",
|
|
307
|
+
{
|
|
308
|
+
id: "nice-reg-email",
|
|
309
|
+
className: "nice-input",
|
|
310
|
+
type: "email",
|
|
311
|
+
value: p,
|
|
312
|
+
onChange: (N) => $(N.target.value),
|
|
313
|
+
required: !0,
|
|
314
|
+
disabled: n,
|
|
315
|
+
autoComplete: "email"
|
|
316
|
+
}
|
|
317
|
+
)
|
|
240
318
|
] }),
|
|
241
319
|
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
242
|
-
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-
|
|
243
|
-
/* @__PURE__ */ e(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
/* @__PURE__ */
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
},
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
newPassword: b
|
|
299
|
-
}));
|
|
300
|
-
}, [p, i, b, a, n]);
|
|
301
|
-
return /* @__PURE__ */ t(
|
|
302
|
-
"form",
|
|
303
|
-
{
|
|
304
|
-
ref: v,
|
|
305
|
-
className: `nice-change-password${m ? ` ${m}` : ""}`,
|
|
306
|
-
style: c,
|
|
307
|
-
onSubmit: $,
|
|
308
|
-
noValidate: !0,
|
|
309
|
-
children: [
|
|
310
|
-
/* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: r }),
|
|
311
|
-
d && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: d }),
|
|
312
|
-
u && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: u }),
|
|
313
|
-
a && /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
314
|
-
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
|
|
315
|
-
/* @__PURE__ */ e(
|
|
316
|
-
"input",
|
|
317
|
-
{
|
|
318
|
-
id: "nice-cp-current",
|
|
319
|
-
className: "nice-input",
|
|
320
|
-
type: "password",
|
|
321
|
-
value: i,
|
|
322
|
-
onChange: (g) => k(g.target.value),
|
|
323
|
-
autoComplete: "current-password",
|
|
324
|
-
disabled: o,
|
|
325
|
-
required: !0
|
|
326
|
-
}
|
|
327
|
-
)
|
|
328
|
-
] }),
|
|
329
|
-
/* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
330
|
-
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
|
|
331
|
-
/* @__PURE__ */ e(
|
|
332
|
-
"input",
|
|
333
|
-
{
|
|
334
|
-
id: "nice-cp-new",
|
|
335
|
-
className: "nice-input",
|
|
336
|
-
type: "password",
|
|
337
|
-
value: b,
|
|
338
|
-
onChange: (g) => C(g.target.value),
|
|
339
|
-
autoComplete: "new-password",
|
|
340
|
-
disabled: o,
|
|
341
|
-
required: !0
|
|
342
|
-
}
|
|
343
|
-
),
|
|
344
|
-
b.length > 0 && /* @__PURE__ */ e(M, { password: b })
|
|
345
|
-
] }),
|
|
346
|
-
/* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
347
|
-
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
|
|
320
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-pass", children: "Password *" }),
|
|
321
|
+
/* @__PURE__ */ e(
|
|
322
|
+
"input",
|
|
323
|
+
{
|
|
324
|
+
id: "nice-reg-pass",
|
|
325
|
+
className: "nice-input",
|
|
326
|
+
type: "password",
|
|
327
|
+
value: g,
|
|
328
|
+
onChange: (N) => S(N.target.value),
|
|
329
|
+
required: !0,
|
|
330
|
+
disabled: n,
|
|
331
|
+
autoComplete: "new-password"
|
|
332
|
+
}
|
|
333
|
+
),
|
|
334
|
+
u && g.length > 0 && /* @__PURE__ */ e(M, { password: g })
|
|
335
|
+
] }),
|
|
336
|
+
/* @__PURE__ */ t("div", { className: "nice-register-form__field", children: [
|
|
337
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-reg-confirm", children: "Confirm password *" }),
|
|
338
|
+
/* @__PURE__ */ e(
|
|
339
|
+
"input",
|
|
340
|
+
{
|
|
341
|
+
id: "nice-reg-confirm",
|
|
342
|
+
className: "nice-input",
|
|
343
|
+
type: "password",
|
|
344
|
+
value: y,
|
|
345
|
+
onChange: (N) => T(N.target.value),
|
|
346
|
+
required: !0,
|
|
347
|
+
disabled: n,
|
|
348
|
+
autoComplete: "new-password"
|
|
349
|
+
}
|
|
350
|
+
),
|
|
351
|
+
y && !F && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
|
|
352
|
+
] }),
|
|
353
|
+
/* @__PURE__ */ t("label", { className: "nice-register-form__terms", children: [
|
|
354
|
+
/* @__PURE__ */ e(
|
|
355
|
+
"input",
|
|
356
|
+
{
|
|
357
|
+
type: "checkbox",
|
|
358
|
+
checked: R,
|
|
359
|
+
onChange: (N) => L(N.target.checked),
|
|
360
|
+
disabled: n
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
/* @__PURE__ */ t("span", { children: [
|
|
364
|
+
"I accept the",
|
|
365
|
+
" ",
|
|
366
|
+
r ? /* @__PURE__ */ e("a", { href: r, target: "_blank", rel: "noopener noreferrer", children: "Terms" }) : "Terms",
|
|
367
|
+
m && /* @__PURE__ */ t(V, { children: [
|
|
368
|
+
" ",
|
|
369
|
+
"and",
|
|
370
|
+
" ",
|
|
371
|
+
/* @__PURE__ */ e("a", { href: m, target: "_blank", rel: "noopener noreferrer", children: "Privacy Policy" })
|
|
372
|
+
] }),
|
|
373
|
+
" *"
|
|
374
|
+
] })
|
|
375
|
+
] }),
|
|
348
376
|
/* @__PURE__ */ e(
|
|
349
|
-
"
|
|
377
|
+
"button",
|
|
350
378
|
{
|
|
351
|
-
|
|
352
|
-
className: "nice-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
onChange: (g) => A(g.target.value),
|
|
356
|
-
autoComplete: "new-password",
|
|
357
|
-
disabled: o,
|
|
358
|
-
required: !0
|
|
379
|
+
type: "submit",
|
|
380
|
+
className: "nice-btn nice-btn--primary nice-register-form__submit",
|
|
381
|
+
disabled: !D,
|
|
382
|
+
children: n ? "…" : "Register"
|
|
359
383
|
}
|
|
360
384
|
),
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
}
|
|
385
|
+
d && /* @__PURE__ */ t("div", { className: "nice-register-form__login", children: [
|
|
386
|
+
/* @__PURE__ */ e("span", { children: "Already have an account? " }),
|
|
387
|
+
/* @__PURE__ */ e("button", { type: "button", onClick: d, children: "Sign in" })
|
|
388
|
+
] }),
|
|
389
|
+
i && /* @__PURE__ */ e("div", { className: "nice-register-form__footer", children: i })
|
|
390
|
+
]
|
|
391
|
+
}
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
Q.displayName = "NiceRegistrationForm";
|
|
396
|
+
const z = E(
|
|
397
|
+
({
|
|
398
|
+
requireCurrentPassword: a = !0,
|
|
399
|
+
onSubmit: n,
|
|
400
|
+
loading: o = !1,
|
|
401
|
+
error: d,
|
|
402
|
+
success: u,
|
|
403
|
+
minPasswordStrength: f = 2,
|
|
404
|
+
title: r = "Change Password",
|
|
405
|
+
className: m,
|
|
406
|
+
style: c
|
|
407
|
+
}, v) => {
|
|
408
|
+
const [i, k] = _(""), [b, C] = _(""), [w, A] = _(""), s = I(b), h = b === w, p = (!a || i.length > 0) && b.length > 0 && h && s >= f && !o, $ = x(
|
|
409
|
+
(g) => {
|
|
410
|
+
g.preventDefault(), p && (n == null || n({
|
|
411
|
+
currentPassword: a ? i : void 0,
|
|
412
|
+
newPassword: b
|
|
413
|
+
}));
|
|
414
|
+
},
|
|
415
|
+
[p, i, b, a, n]
|
|
416
|
+
);
|
|
417
|
+
return /* @__PURE__ */ t(
|
|
418
|
+
"form",
|
|
419
|
+
{
|
|
420
|
+
ref: v,
|
|
421
|
+
className: `nice-change-password${m ? ` ${m}` : ""}`,
|
|
422
|
+
style: c,
|
|
423
|
+
onSubmit: $,
|
|
424
|
+
noValidate: !0,
|
|
425
|
+
children: [
|
|
426
|
+
/* @__PURE__ */ e("h3", { className: "nice-change-password__title", children: r }),
|
|
427
|
+
d && /* @__PURE__ */ e("div", { className: "nice-change-password__error", role: "alert", children: d }),
|
|
428
|
+
u && /* @__PURE__ */ e("div", { className: "nice-change-password__success", role: "status", children: u }),
|
|
429
|
+
a && /* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
430
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-current", children: "Current password" }),
|
|
431
|
+
/* @__PURE__ */ e(
|
|
432
|
+
"input",
|
|
433
|
+
{
|
|
434
|
+
id: "nice-cp-current",
|
|
435
|
+
className: "nice-input",
|
|
436
|
+
type: "password",
|
|
437
|
+
value: i,
|
|
438
|
+
onChange: (g) => k(g.target.value),
|
|
439
|
+
autoComplete: "current-password",
|
|
440
|
+
disabled: o,
|
|
441
|
+
required: !0
|
|
442
|
+
}
|
|
443
|
+
)
|
|
444
|
+
] }),
|
|
445
|
+
/* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
446
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-new", children: "New password" }),
|
|
447
|
+
/* @__PURE__ */ e(
|
|
448
|
+
"input",
|
|
449
|
+
{
|
|
450
|
+
id: "nice-cp-new",
|
|
451
|
+
className: "nice-input",
|
|
452
|
+
type: "password",
|
|
453
|
+
value: b,
|
|
454
|
+
onChange: (g) => C(g.target.value),
|
|
455
|
+
autoComplete: "new-password",
|
|
456
|
+
disabled: o,
|
|
457
|
+
required: !0
|
|
458
|
+
}
|
|
459
|
+
),
|
|
460
|
+
b.length > 0 && /* @__PURE__ */ e(M, { password: b })
|
|
461
|
+
] }),
|
|
462
|
+
/* @__PURE__ */ t("div", { className: "nice-change-password__field", children: [
|
|
463
|
+
/* @__PURE__ */ e("label", { htmlFor: "nice-cp-confirm", children: "Confirm new password" }),
|
|
464
|
+
/* @__PURE__ */ e(
|
|
465
|
+
"input",
|
|
466
|
+
{
|
|
467
|
+
id: "nice-cp-confirm",
|
|
468
|
+
className: "nice-input",
|
|
469
|
+
type: "password",
|
|
470
|
+
value: w,
|
|
471
|
+
onChange: (g) => A(g.target.value),
|
|
472
|
+
autoComplete: "new-password",
|
|
473
|
+
disabled: o,
|
|
474
|
+
required: !0
|
|
475
|
+
}
|
|
476
|
+
),
|
|
477
|
+
w && !h && /* @__PURE__ */ e("span", { className: "nice-error-text", children: "Passwords do not match" })
|
|
478
|
+
] }),
|
|
479
|
+
/* @__PURE__ */ e("button", { type: "submit", className: "nice-btn nice-btn--primary", disabled: !p, children: o ? "…" : "Change Password" })
|
|
480
|
+
]
|
|
481
|
+
}
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
);
|
|
368
485
|
z.displayName = "NiceChangePassword";
|
|
369
486
|
const J = E(({
|
|
370
487
|
secret: a,
|
|
@@ -525,133 +642,148 @@ const U = [
|
|
|
525
642
|
}
|
|
526
643
|
));
|
|
527
644
|
Z.displayName = "NiceOAuthButtons";
|
|
528
|
-
const Y = E(
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}, [u, C, A, h]), P = x(async (l) => {
|
|
549
|
-
if (f) {
|
|
550
|
-
R(l);
|
|
551
|
-
try {
|
|
552
|
-
await f(l);
|
|
553
|
-
} finally {
|
|
554
|
-
R(null);
|
|
645
|
+
const Y = E(
|
|
646
|
+
function(n, o) {
|
|
647
|
+
const {
|
|
648
|
+
tokens: d,
|
|
649
|
+
onCreate: u,
|
|
650
|
+
onRevoke: f,
|
|
651
|
+
availableScopes: r = [],
|
|
652
|
+
maxTokens: m = 10,
|
|
653
|
+
title: c = "API Tokens",
|
|
654
|
+
className: v,
|
|
655
|
+
style: i
|
|
656
|
+
} = n, [k, b] = _(!1), [C, w] = _(""), [A, s] = _([]), [h, p] = _("90"), [$, g] = _(null), [S, y] = _(!1), [T, R] = _(null), L = x(async () => {
|
|
657
|
+
if (!(!u || !C.trim())) {
|
|
658
|
+
y(!0);
|
|
659
|
+
try {
|
|
660
|
+
const l = h ? parseInt(h, 10) : void 0, N = await u(C.trim(), A, l);
|
|
661
|
+
g(N), w(""), s([]), b(!1);
|
|
662
|
+
} finally {
|
|
663
|
+
y(!1);
|
|
664
|
+
}
|
|
555
665
|
}
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
/* @__PURE__ */ t("
|
|
575
|
-
"
|
|
576
|
-
/* @__PURE__ */ e(
|
|
577
|
-
"
|
|
666
|
+
}, [u, C, A, h]), P = x(
|
|
667
|
+
async (l) => {
|
|
668
|
+
if (f) {
|
|
669
|
+
R(l);
|
|
670
|
+
try {
|
|
671
|
+
await f(l);
|
|
672
|
+
} finally {
|
|
673
|
+
R(null);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
[f]
|
|
678
|
+
), F = (l) => {
|
|
679
|
+
s(
|
|
680
|
+
(N) => N.includes(l) ? N.filter((O) => O !== l) : [...N, l]
|
|
681
|
+
);
|
|
682
|
+
}, D = d.length < m;
|
|
683
|
+
return /* @__PURE__ */ t("div", { ref: o, className: `nice-token-management ${v ?? ""}`, style: i, children: [
|
|
684
|
+
/* @__PURE__ */ t("div", { className: "nice-token-management__header", children: [
|
|
685
|
+
/* @__PURE__ */ e("h3", { children: c }),
|
|
686
|
+
D && /* @__PURE__ */ e(
|
|
687
|
+
"button",
|
|
578
688
|
{
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
maxLength: 64
|
|
689
|
+
className: "nice-token-management__new-btn",
|
|
690
|
+
onClick: () => b(!0),
|
|
691
|
+
disabled: k,
|
|
692
|
+
children: "+ New Token"
|
|
584
693
|
}
|
|
585
694
|
)
|
|
586
695
|
] }),
|
|
587
|
-
|
|
588
|
-
/* @__PURE__ */
|
|
589
|
-
|
|
696
|
+
$ && /* @__PURE__ */ t("div", { className: "nice-token-management__reveal", children: [
|
|
697
|
+
/* @__PURE__ */ t("p", { children: [
|
|
698
|
+
/* @__PURE__ */ e("strong", { children: "New token created!" }),
|
|
699
|
+
" Copy it now — it won't be shown again."
|
|
700
|
+
] }),
|
|
701
|
+
/* @__PURE__ */ e("code", { className: "nice-token-management__token-value", children: $ }),
|
|
702
|
+
/* @__PURE__ */ e("button", { onClick: () => g(null), children: "Dismiss" })
|
|
703
|
+
] }),
|
|
704
|
+
k && /* @__PURE__ */ t("div", { className: "nice-token-management__create-form", children: [
|
|
705
|
+
/* @__PURE__ */ t("label", { children: [
|
|
706
|
+
"Name",
|
|
590
707
|
/* @__PURE__ */ e(
|
|
591
708
|
"input",
|
|
592
709
|
{
|
|
593
|
-
type: "
|
|
594
|
-
|
|
595
|
-
onChange: () =>
|
|
710
|
+
type: "text",
|
|
711
|
+
value: C,
|
|
712
|
+
onChange: (l) => w(l.target.value),
|
|
713
|
+
placeholder: "My API token",
|
|
714
|
+
maxLength: 64
|
|
596
715
|
}
|
|
597
|
-
)
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
}
|
|
612
|
-
)
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
] })
|
|
618
|
-
] }),
|
|
619
|
-
d.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ t("table", { className: "nice-token-management__table", children: [
|
|
620
|
-
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ t("tr", { children: [
|
|
621
|
-
/* @__PURE__ */ e("th", { children: "Name" }),
|
|
622
|
-
/* @__PURE__ */ e("th", { children: "Prefix" }),
|
|
623
|
-
/* @__PURE__ */ e("th", { children: "Created" }),
|
|
624
|
-
/* @__PURE__ */ e("th", { children: "Expires" }),
|
|
625
|
-
/* @__PURE__ */ e("th", { children: "Last Used" }),
|
|
626
|
-
/* @__PURE__ */ e("th", { children: "Scopes" }),
|
|
627
|
-
/* @__PURE__ */ e("th", {})
|
|
628
|
-
] }) }),
|
|
629
|
-
/* @__PURE__ */ e("tbody", { children: d.map((l) => {
|
|
630
|
-
var N;
|
|
631
|
-
return /* @__PURE__ */ t("tr", { children: [
|
|
632
|
-
/* @__PURE__ */ e("td", { children: l.name }),
|
|
633
|
-
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ t("code", { children: [
|
|
634
|
-
l.prefix,
|
|
635
|
-
"…"
|
|
636
|
-
] }) }),
|
|
637
|
-
/* @__PURE__ */ e("td", { children: l.createdAt }),
|
|
638
|
-
/* @__PURE__ */ e("td", { children: l.expiresAt ?? "—" }),
|
|
639
|
-
/* @__PURE__ */ e("td", { children: l.lastUsedAt ?? "Never" }),
|
|
640
|
-
/* @__PURE__ */ e("td", { children: ((N = l.scopes) == null ? void 0 : N.join(", ")) || "—" }),
|
|
641
|
-
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
|
|
642
|
-
"button",
|
|
716
|
+
)
|
|
717
|
+
] }),
|
|
718
|
+
r.length > 0 && /* @__PURE__ */ t("fieldset", { children: [
|
|
719
|
+
/* @__PURE__ */ e("legend", { children: "Scopes" }),
|
|
720
|
+
r.map((l) => /* @__PURE__ */ t("label", { className: "nice-token-management__scope", children: [
|
|
721
|
+
/* @__PURE__ */ e(
|
|
722
|
+
"input",
|
|
723
|
+
{
|
|
724
|
+
type: "checkbox",
|
|
725
|
+
checked: A.includes(l),
|
|
726
|
+
onChange: () => F(l)
|
|
727
|
+
}
|
|
728
|
+
),
|
|
729
|
+
l
|
|
730
|
+
] }, l))
|
|
731
|
+
] }),
|
|
732
|
+
/* @__PURE__ */ t("label", { children: [
|
|
733
|
+
"Expires in (days)",
|
|
734
|
+
/* @__PURE__ */ e(
|
|
735
|
+
"input",
|
|
643
736
|
{
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
737
|
+
type: "number",
|
|
738
|
+
value: h,
|
|
739
|
+
onChange: (l) => p(l.target.value),
|
|
740
|
+
min: 1,
|
|
741
|
+
max: 365
|
|
648
742
|
}
|
|
649
|
-
)
|
|
650
|
-
] },
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
})
|
|
743
|
+
)
|
|
744
|
+
] }),
|
|
745
|
+
/* @__PURE__ */ t("div", { className: "nice-token-management__create-actions", children: [
|
|
746
|
+
/* @__PURE__ */ e("button", { onClick: L, disabled: S || !C.trim(), children: S ? "Creating…" : "Create Token" }),
|
|
747
|
+
/* @__PURE__ */ e("button", { onClick: () => b(!1), children: "Cancel" })
|
|
748
|
+
] })
|
|
749
|
+
] }),
|
|
750
|
+
d.length === 0 ? /* @__PURE__ */ e("p", { className: "nice-token-management__empty", children: "No API tokens yet." }) : /* @__PURE__ */ t("table", { className: "nice-token-management__table", children: [
|
|
751
|
+
/* @__PURE__ */ e("thead", { children: /* @__PURE__ */ t("tr", { children: [
|
|
752
|
+
/* @__PURE__ */ e("th", { children: "Name" }),
|
|
753
|
+
/* @__PURE__ */ e("th", { children: "Prefix" }),
|
|
754
|
+
/* @__PURE__ */ e("th", { children: "Created" }),
|
|
755
|
+
/* @__PURE__ */ e("th", { children: "Expires" }),
|
|
756
|
+
/* @__PURE__ */ e("th", { children: "Last Used" }),
|
|
757
|
+
/* @__PURE__ */ e("th", { children: "Scopes" }),
|
|
758
|
+
/* @__PURE__ */ e("th", {})
|
|
759
|
+
] }) }),
|
|
760
|
+
/* @__PURE__ */ e("tbody", { children: d.map((l) => {
|
|
761
|
+
var N;
|
|
762
|
+
return /* @__PURE__ */ t("tr", { children: [
|
|
763
|
+
/* @__PURE__ */ e("td", { children: l.name }),
|
|
764
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ t("code", { children: [
|
|
765
|
+
l.prefix,
|
|
766
|
+
"…"
|
|
767
|
+
] }) }),
|
|
768
|
+
/* @__PURE__ */ e("td", { children: l.createdAt }),
|
|
769
|
+
/* @__PURE__ */ e("td", { children: l.expiresAt ?? "—" }),
|
|
770
|
+
/* @__PURE__ */ e("td", { children: l.lastUsedAt ?? "Never" }),
|
|
771
|
+
/* @__PURE__ */ e("td", { children: ((N = l.scopes) == null ? void 0 : N.join(", ")) || "—" }),
|
|
772
|
+
/* @__PURE__ */ e("td", { children: /* @__PURE__ */ e(
|
|
773
|
+
"button",
|
|
774
|
+
{
|
|
775
|
+
className: "nice-token-management__revoke-btn",
|
|
776
|
+
onClick: () => P(l.id),
|
|
777
|
+
disabled: T === l.id,
|
|
778
|
+
children: T === l.id ? "Revoking…" : "Revoke"
|
|
779
|
+
}
|
|
780
|
+
) })
|
|
781
|
+
] }, l.id);
|
|
782
|
+
}) })
|
|
783
|
+
] })
|
|
784
|
+
] });
|
|
785
|
+
}
|
|
786
|
+
);
|
|
655
787
|
export {
|
|
656
788
|
K as NiceCaptcha,
|
|
657
789
|
z as NiceChangePassword,
|