@kendevelops/auth-flow-kit 1.4.9 → 1.5.5

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/index.cjs CHANGED
@@ -34,9 +34,7 @@ var import_react = require("react");
34
34
 
35
35
  // src/http.ts
36
36
  function makeURL(baseURL, path) {
37
- const base = baseURL.replace(/\/$/, "");
38
- const suffix = path.startsWith("/") ? path : `/${path}`;
39
- return `${base}${suffix}`;
37
+ return `${baseURL.replace(/\/$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
40
38
  }
41
39
  function getStoredAccessToken() {
42
40
  try {
@@ -47,11 +45,8 @@ function getStoredAccessToken() {
47
45
  }
48
46
  function setStoredAccessToken(token) {
49
47
  try {
50
- if (token) {
51
- localStorage.setItem("afk_access_token", token);
52
- return;
53
- }
54
- localStorage.removeItem("afk_access_token");
48
+ if (token) localStorage.setItem("afk_access_token", token);
49
+ else localStorage.removeItem("afk_access_token");
55
50
  } catch {
56
51
  }
57
52
  }
@@ -60,27 +55,20 @@ async function httpJSON(url, opts = {}, withAuth = false) {
60
55
  "Content-Type": "application/json"
61
56
  };
62
57
  if (withAuth) {
63
- const storedToken = getStoredAccessToken();
64
- if (storedToken) {
65
- headers["Authorization"] = `Bearer ${storedToken}`;
66
- }
58
+ const tok = getStoredAccessToken();
59
+ if (tok) headers["Authorization"] = `Bearer ${tok}`;
67
60
  }
68
61
  const res = await fetch(url, {
69
62
  ...opts,
70
- headers: {
71
- ...headers,
72
- ...opts.headers || {}
73
- }
63
+ headers: { ...headers, ...opts.headers || {} }
74
64
  });
75
65
  if (!res.ok) {
76
66
  let message = `Request failed (${res.status})`;
77
67
  const contentType = res.headers.get("content-type") || "";
78
68
  if (contentType.includes("application/json")) {
79
69
  try {
80
- const body = await res.json();
81
- if (body?.message) {
82
- message = body.message;
83
- }
70
+ const data = await res.json();
71
+ if (data?.message) message = data.message;
84
72
  } catch {
85
73
  }
86
74
  }
@@ -200,29 +188,18 @@ function PasswordResetScreen() {
200
188
  const [email, setEmail] = (0, import_react3.useState)("");
201
189
  const [sent, setSent] = (0, import_react3.useState)(false);
202
190
  const [error, setError] = (0, import_react3.useState)(null);
203
- const isValidEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
204
191
  const requestReset = async (e) => {
205
192
  e.preventDefault();
206
193
  setError(null);
207
- const trimmedEmail = email.trim();
208
- if (!trimmedEmail) {
209
- setError("Email is required.");
210
- return;
211
- }
212
- if (!isValidEmail(trimmedEmail)) {
213
- setError("Enter a valid email address.");
214
- return;
215
- }
216
194
  try {
217
195
  const url = makeURL(config.baseURL, config.endpoints.forgot);
218
196
  await httpJSON(url, {
219
197
  method: "POST",
220
- body: JSON.stringify({ email: trimmedEmail })
198
+ body: JSON.stringify({ email })
221
199
  });
222
200
  setSent(true);
223
201
  } catch (err) {
224
- const message = err instanceof Error ? err.message : "Failed to request reset";
225
- setError(message);
202
+ setError(err?.message || "Failed to request reset");
226
203
  }
227
204
  };
228
205
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
@@ -262,7 +239,6 @@ function PasswordResetScreen() {
262
239
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
263
240
  "label",
264
241
  {
265
- htmlFor: "afk-reset-email",
266
242
  style: {
267
243
  position: "absolute",
268
244
  top: sent ? "-18px" : "-10px",
@@ -279,7 +255,6 @@ function PasswordResetScreen() {
279
255
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
280
256
  "input",
281
257
  {
282
- id: "afk-reset-email",
283
258
  value: email,
284
259
  onChange: (e) => setEmail(e.target.value),
285
260
  type: "email",
@@ -342,8 +317,6 @@ function PasswordResetScreen() {
342
317
  error && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
343
318
  "p",
344
319
  {
345
- role: "alert",
346
- "aria-live": "polite",
347
320
  style: {
348
321
  marginTop: 20,
349
322
  color: "crimson",
@@ -394,26 +367,15 @@ function LoginScreen() {
394
367
  setError(null);
395
368
  const trimmedEmail = email.trim();
396
369
  const trimmedPassword = password.trim();
397
- if (!trimmedEmail) {
398
- setError("Email is required.");
399
- setSubmitting(false);
400
- return;
401
- }
402
- if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedEmail)) {
403
- setError("Enter a valid email address.");
404
- setSubmitting(false);
405
- return;
406
- }
407
- if (!trimmedPassword) {
408
- setError("Password is required.");
370
+ if (!trimmedEmail || !trimmedPassword) {
371
+ setError("Email and password cannot be empty.");
409
372
  setSubmitting(false);
410
373
  return;
411
374
  }
412
375
  try {
413
376
  await login(trimmedEmail, trimmedPassword);
414
377
  } catch (err) {
415
- const message = err instanceof Error ? err.message : "Login failed";
416
- setError(message);
378
+ setError(err?.message || "Login failed");
417
379
  } finally {
418
380
  setSubmitting(false);
419
381
  }
@@ -454,7 +416,6 @@ function LoginScreen() {
454
416
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
455
417
  "label",
456
418
  {
457
- htmlFor: "afk-login-email",
458
419
  style: {
459
420
  position: "absolute",
460
421
  top: "-10px",
@@ -471,7 +432,6 @@ function LoginScreen() {
471
432
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
472
433
  "input",
473
434
  {
474
- id: "afk-login-email",
475
435
  value: email,
476
436
  onChange: (e) => setEmail(e.target.value),
477
437
  type: "email",
@@ -501,7 +461,6 @@ function LoginScreen() {
501
461
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
502
462
  "label",
503
463
  {
504
- htmlFor: "afk-login-password",
505
464
  style: {
506
465
  position: "absolute",
507
466
  top: "-10px",
@@ -518,7 +477,6 @@ function LoginScreen() {
518
477
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
519
478
  "input",
520
479
  {
521
- id: "afk-login-password",
522
480
  value: password,
523
481
  onChange: (e) => setPassword(e.target.value),
524
482
  type: "password",
@@ -545,28 +503,17 @@ function LoginScreen() {
545
503
  )
546
504
  ] }),
547
505
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
548
- "div",
506
+ "p",
549
507
  {
508
+ onClick: () => setShowReset(true),
550
509
  style: {
551
- textAlign: "right"
510
+ textAlign: "right",
511
+ fontSize: 13,
512
+ color: "#4b4bff",
513
+ cursor: "pointer",
514
+ marginBottom: 24
552
515
  },
553
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
554
- "button",
555
- {
556
- onClick: () => setShowReset(true),
557
- style: {
558
- textAlign: "right",
559
- fontSize: 13,
560
- color: "#4b4bff",
561
- cursor: "pointer",
562
- marginBottom: 24,
563
- width: "fit-content",
564
- border: "none",
565
- background: "none"
566
- },
567
- children: "Forgot password?"
568
- }
569
- )
516
+ children: "Forgot password?"
570
517
  }
571
518
  ),
572
519
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -594,8 +541,6 @@ function LoginScreen() {
594
541
  error && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
595
542
  "p",
596
543
  {
597
- role: "alert",
598
- "aria-live": "polite",
599
544
  style: {
600
545
  marginTop: 18,
601
546
  color: "crimson",
@@ -619,21 +564,8 @@ function SignupScreen() {
619
564
  const [name, setName] = (0, import_react5.useState)("");
620
565
  const [email, setEmail] = (0, import_react5.useState)("");
621
566
  const [password, setPassword] = (0, import_react5.useState)("");
622
- const [confirmPassword, setConfirmPassword] = (0, import_react5.useState)("");
623
567
  const [submitting, setSubmitting] = (0, import_react5.useState)(false);
624
568
  const [error, setError] = (0, import_react5.useState)(null);
625
- const isValidEmail = (value) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
626
- const getPasswordStrength = (value) => {
627
- let score = 0;
628
- if (value.length >= 8) score++;
629
- if (/[A-Z]/.test(value)) score++;
630
- if (/[0-9]/.test(value)) score++;
631
- if (/[^A-Za-z0-9]/.test(value)) score++;
632
- if (!value) return { label: "", color: "" };
633
- if (score <= 1) return { label: "Weak", color: "crimson" };
634
- if (score === 2) return { label: "Medium", color: "#f39c12" };
635
- return { label: "Strong", color: "#2ecc71" };
636
- };
637
569
  const onSubmit = async (e) => {
638
570
  e.preventDefault();
639
571
  setSubmitting(true);
@@ -641,47 +573,15 @@ function SignupScreen() {
641
573
  const trimmedEmail = email.trim();
642
574
  const trimmedPassword = password.trim();
643
575
  const trimmedName = name.trim();
644
- const trimmedConfirm = confirmPassword.trim();
645
- if (!trimmedName) {
646
- setError("Name is required.");
647
- setSubmitting(false);
648
- return;
649
- }
650
- if (!trimmedEmail) {
651
- setError("Email is required.");
652
- setSubmitting(false);
653
- return;
654
- }
655
- if (!isValidEmail(trimmedEmail)) {
656
- setError("Enter a valid email address.");
657
- setSubmitting(false);
658
- return;
659
- }
660
- if (!trimmedPassword) {
661
- setError("Password is required.");
662
- setSubmitting(false);
663
- return;
664
- }
665
- if (trimmedPassword.length < 8) {
666
- setError("Password must be at least 8 characters long.");
667
- setSubmitting(false);
668
- return;
669
- }
670
- if (!trimmedConfirm) {
671
- setError("Please confirm your password.");
672
- setSubmitting(false);
673
- return;
674
- }
675
- if (trimmedPassword !== trimmedConfirm) {
676
- setError("Passwords do not match.");
576
+ if (!trimmedEmail || !trimmedPassword || !trimmedName) {
577
+ setError("Email and password cannot be empty.");
677
578
  setSubmitting(false);
678
579
  return;
679
580
  }
680
581
  try {
681
- await signup({ name: trimmedName, email: trimmedEmail, password: trimmedPassword });
582
+ await signup({ name, email, password });
682
583
  } catch (err) {
683
- const message = err instanceof Error ? err.message : "Signup failed";
684
- setError(message);
584
+ setError(err?.message || "Signup failed");
685
585
  } finally {
686
586
  setSubmitting(false);
687
587
  }
@@ -723,7 +623,6 @@ function SignupScreen() {
723
623
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
724
624
  "label",
725
625
  {
726
- htmlFor: "afk-signup-name",
727
626
  style: {
728
627
  position: "absolute",
729
628
  top: "-10px",
@@ -740,7 +639,6 @@ function SignupScreen() {
740
639
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
741
640
  "input",
742
641
  {
743
- id: "afk-signup-name",
744
642
  value: name,
745
643
  onChange: (e) => setName(e.target.value),
746
644
  placeholder: "Your name",
@@ -769,7 +667,6 @@ function SignupScreen() {
769
667
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
770
668
  "label",
771
669
  {
772
- htmlFor: "afk-signup-email",
773
670
  style: {
774
671
  position: "absolute",
775
672
  top: "-10px",
@@ -786,7 +683,6 @@ function SignupScreen() {
786
683
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
787
684
  "input",
788
685
  {
789
- id: "afk-signup-email",
790
686
  value: email,
791
687
  onChange: (e) => setEmail(e.target.value),
792
688
  type: "email",
@@ -816,7 +712,6 @@ function SignupScreen() {
816
712
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
817
713
  "label",
818
714
  {
819
- htmlFor: "afk-signup-password",
820
715
  style: {
821
716
  position: "absolute",
822
717
  top: "-10px",
@@ -833,7 +728,6 @@ function SignupScreen() {
833
728
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
834
729
  "input",
835
730
  {
836
- id: "afk-signup-password",
837
731
  value: password,
838
732
  onChange: (e) => setPassword(e.target.value),
839
733
  type: "password",
@@ -859,95 +753,6 @@ function SignupScreen() {
859
753
  }
860
754
  )
861
755
  ] }),
862
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { position: "relative", marginBottom: 18 }, children: [
863
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
864
- "label",
865
- {
866
- htmlFor: "afk-signup-confirm-password",
867
- style: {
868
- position: "absolute",
869
- top: "-10px",
870
- left: "14px",
871
- background: "rgba(255,255,255,0.85)",
872
- padding: "0 6px",
873
- fontSize: 13,
874
- color: "#444",
875
- borderRadius: 6
876
- },
877
- children: "Confirm password"
878
- }
879
- ),
880
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
881
- "input",
882
- {
883
- id: "afk-signup-confirm-password",
884
- value: confirmPassword,
885
- onChange: (e) => setConfirmPassword(e.target.value),
886
- type: "password",
887
- placeholder: "Repeat your password",
888
- style: {
889
- width: "80%",
890
- padding: "14px 16px",
891
- borderRadius: 12,
892
- border: "1px solid #d2d2d2",
893
- fontSize: 15,
894
- outline: "none",
895
- transition: "0.25s",
896
- background: "rgba(255,255,255,0.85)"
897
- },
898
- onFocus: (e) => {
899
- e.currentTarget.style.border = "1px solid #4b4bff";
900
- e.currentTarget.style.boxShadow = "0 0 0 3px rgba(75,75,255,0.25)";
901
- },
902
- onBlur: (e) => {
903
- e.currentTarget.style.border = "1px solid #d2d2d2";
904
- e.currentTarget.style.boxShadow = "0 0 0 transparent";
905
- }
906
- }
907
- )
908
- ] }),
909
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
910
- "div",
911
- {
912
- style: {
913
- marginBottom: 20,
914
- fontSize: 12,
915
- color: "#555"
916
- },
917
- children: [
918
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { style: { marginBottom: 6 }, children: "Use at least 8 characters, including letters, numbers, and symbols." }),
919
- password && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
920
- "p",
921
- {
922
- style: {
923
- fontWeight: 600,
924
- color: getPasswordStrength(password).color
925
- },
926
- children: [
927
- "Password strength: ",
928
- getPasswordStrength(password).label
929
- ]
930
- }
931
- )
932
- ]
933
- }
934
- ),
935
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
936
- "p",
937
- {
938
- style: {
939
- textAlign: "center",
940
- fontSize: 13,
941
- color: "#4b4bff",
942
- cursor: "pointer",
943
- marginBottom: 24
944
- },
945
- onClick: () => {
946
- window.dispatchEvent(new CustomEvent("auth-flow-kit:navigate-to-login"));
947
- },
948
- children: "Already have an account? Sign in"
949
- }
950
- ),
951
756
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
952
757
  "button",
953
758
  {
@@ -973,8 +778,6 @@ function SignupScreen() {
973
778
  error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
974
779
  "p",
975
780
  {
976
- role: "alert",
977
- "aria-live": "polite",
978
781
  style: {
979
782
  marginTop: 18,
980
783
  color: "crimson",