@veripass/react-sdk 1.0.11 → 1.0.13

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.
@@ -10,6 +10,9 @@ function _arrayLikeToArray(r, a) {
10
10
  function _arrayWithHoles(r) {
11
11
  if (Array.isArray(r)) return r;
12
12
  }
13
+ function _arrayWithoutHoles(r) {
14
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
15
+ }
13
16
  function _assertThisInitialized$1(e) {
14
17
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
15
18
  return e;
@@ -98,6 +101,9 @@ function _isNativeReflectConstruct() {
98
101
  return !!t;
99
102
  })();
100
103
  }
104
+ function _iterableToArray(r) {
105
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
106
+ }
101
107
  function _iterableToArrayLimit(r, l) {
102
108
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
103
109
  if (null != t) {
@@ -128,6 +134,9 @@ function _iterableToArrayLimit(r, l) {
128
134
  function _nonIterableRest() {
129
135
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
130
136
  }
137
+ function _nonIterableSpread() {
138
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
139
+ }
131
140
  function ownKeys(e, r) {
132
141
  var t = Object.keys(e);
133
142
  if (Object.getOwnPropertySymbols) {
@@ -474,6 +483,9 @@ function _taggedTemplateLiteral(e, t) {
474
483
  }
475
484
  }));
476
485
  }
486
+ function _toConsumableArray(r) {
487
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
488
+ }
477
489
  function _toPrimitive(t, r) {
478
490
  if ("object" != typeof t || !t) return t;
479
491
  var e = t[Symbol.toPrimitive];
@@ -531,6 +543,8 @@ var useLocalStorage = function useLocalStorage(keyName, defaultValue) {
531
543
  return [storedValue, setValue];
532
544
  };
533
545
 
546
+ var defaulPublicUrlList = ['/auth/login', '/auth/signup'];
547
+
534
548
  /**
535
549
  * Authentication context used to provide user authentication data and functions.
536
550
  */
@@ -546,15 +560,31 @@ var AuthContext = /*#__PURE__*/createContext();
546
560
  */
547
561
  var AuthProvider = function AuthProvider(_ref) {
548
562
  var children = _ref.children;
563
+ _ref.publicUrls;
564
+ var _useState = useState(defaulPublicUrlList),
565
+ _useState2 = _slicedToArray(_useState, 2),
566
+ publicUrlsList = _useState2[0],
567
+ setPublicUrlsList = _useState2[1];
568
+
549
569
  // State to manage user data, persisted in local storage
550
570
  var _useLocalStorage = useLocalStorage('veripass-user-data', null),
551
571
  _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
552
572
  user = _useLocalStorage2[0],
553
573
  setUser = _useLocalStorage2[1];
574
+ useEffect(function () {
575
+ console.log(children);
576
+ }, [children]);
577
+ React__default.Children.forEach(children, function (child) {
578
+ // Check if child is a valid React element
579
+ if (/*#__PURE__*/React__default.isValidElement(child) && child.props.isPublic) {
580
+ debugger;
581
+ publicPaths.add(child.props.path); // Assumes `path` is passed as prop
582
+ }
583
+ });
554
584
 
555
585
  /**
556
586
  * Logs in the user by saving their data to local storage and navigating to the admin page.
557
- *
587
+ *
558
588
  * @param {object} user - The user data to be stored.
559
589
  */
560
590
  var login = /*#__PURE__*/function () {
@@ -588,7 +618,7 @@ var AuthProvider = function AuthProvider(_ref) {
588
618
 
589
619
  /**
590
620
  * Retrieves the stored user data (token) from local storage.
591
- *
621
+ *
592
622
  * @returns {object|null} The user data stored in local storage, or null if not found.
593
623
  */
594
624
  var getToken = function getToken() {
@@ -596,12 +626,19 @@ var AuthProvider = function AuthProvider(_ref) {
596
626
  return JSON.parse(value);
597
627
  };
598
628
 
629
+ // Effect to update public URLs whenever additionalPublicUrls prop changes
630
+ useEffect(function () {
631
+ setPublicUrlsList([].concat(_toConsumableArray(defaultPublicUrlList), _toConsumableArray(additionalPublicUrls)));
632
+ }, [additionalPublicUrls]);
633
+
599
634
  // Effect to redirect if user is null
600
635
  useEffect(function () {
601
- if (user === null) {
636
+ var currentPath = window.location.pathname;
637
+ var isWhitelisted = publicUrlsList.includes(currentPath);
638
+ if (user === null && !isWhitelisted) {
602
639
  window.location.replace('/auth/login');
603
640
  }
604
- }, [user]);
641
+ }, [user, publicUrlsList]);
605
642
 
606
643
  /**
607
644
  * Memoized value containing the user data and authentication functions.
@@ -629,7 +666,7 @@ var AuthProvider = function AuthProvider(_ref) {
629
666
 
630
667
  /**
631
668
  * Custom hook to access the authentication context.
632
- *
669
+ *
633
670
  * @returns {AuthContextValue} The authentication context value, including user data, login, logout, and getToken functions.
634
671
  */
635
672
  var useAuth = function useAuth() {