@veripass/react-sdk 1.0.12 → 1.0.14

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.
@@ -30,6 +30,9 @@ function _arrayLikeToArray(r, a) {
30
30
  function _arrayWithHoles(r) {
31
31
  if (Array.isArray(r)) return r;
32
32
  }
33
+ function _arrayWithoutHoles(r) {
34
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
35
+ }
33
36
  function _assertThisInitialized$1(e) {
34
37
  if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
35
38
  return e;
@@ -118,6 +121,9 @@ function _isNativeReflectConstruct() {
118
121
  return !!t;
119
122
  })();
120
123
  }
124
+ function _iterableToArray(r) {
125
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
126
+ }
121
127
  function _iterableToArrayLimit(r, l) {
122
128
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
123
129
  if (null != t) {
@@ -148,6 +154,9 @@ function _iterableToArrayLimit(r, l) {
148
154
  function _nonIterableRest() {
149
155
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
150
156
  }
157
+ function _nonIterableSpread() {
158
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
159
+ }
151
160
  function ownKeys(e, r) {
152
161
  var t = Object.keys(e);
153
162
  if (Object.getOwnPropertySymbols) {
@@ -494,6 +503,9 @@ function _taggedTemplateLiteral(e, t) {
494
503
  }
495
504
  }));
496
505
  }
506
+ function _toConsumableArray(r) {
507
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
508
+ }
497
509
  function _toPrimitive(t, r) {
498
510
  if ("object" != typeof t || !t) return t;
499
511
  var e = t[Symbol.toPrimitive];
@@ -551,6 +563,8 @@ var useLocalStorage = function useLocalStorage(keyName, defaultValue) {
551
563
  return [storedValue, setValue];
552
564
  };
553
565
 
566
+ var defaulPublicUrlList = ['/auth/login', '/auth/signup'];
567
+
554
568
  /**
555
569
  * Authentication context used to provide user authentication data and functions.
556
570
  */
@@ -565,14 +579,29 @@ var AuthContext = /*#__PURE__*/React.createContext();
565
579
  * @returns {JSX.Element} The provider component for AuthContext.
566
580
  */
567
581
  var AuthProvider = function AuthProvider(_ref) {
568
- var children = _ref.children;
569
- var whitelistUrls = ['/auth/login', '/auth/signup'];
582
+ var children = _ref.children,
583
+ _ref$publicUrls = _ref.publicUrls,
584
+ publicUrls = _ref$publicUrls === void 0 ? [] : _ref$publicUrls;
585
+ var _useState = React.useState(defaulPublicUrlList),
586
+ _useState2 = _slicedToArray(_useState, 2),
587
+ publicUrlsList = _useState2[0],
588
+ setPublicUrlsList = _useState2[1];
570
589
 
571
590
  // State to manage user data, persisted in local storage
572
591
  var _useLocalStorage = useLocalStorage('veripass-user-data', null),
573
592
  _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
574
593
  user = _useLocalStorage2[0],
575
594
  setUser = _useLocalStorage2[1];
595
+ React.useEffect(function () {
596
+ console.log(children);
597
+ }, [children]);
598
+ React.Children.forEach(children, function (child) {
599
+ // Check if child is a valid React element
600
+ if (/*#__PURE__*/React.isValidElement(child) && child.props.isPublic) {
601
+ debugger;
602
+ publicPaths.add(child.props.path); // Assumes `path` is passed as prop
603
+ }
604
+ });
576
605
 
577
606
  /**
578
607
  * Logs in the user by saving their data to local storage and navigating to the admin page.
@@ -618,14 +647,19 @@ var AuthProvider = function AuthProvider(_ref) {
618
647
  return JSON.parse(value);
619
648
  };
620
649
 
650
+ // Effect to update public URLs whenever publicUrls prop changes
651
+ React.useEffect(function () {
652
+ setPublicUrlsList([].concat(_toConsumableArray(defaultPublicUrlList), _toConsumableArray(publicUrls)));
653
+ }, [publicUrls]);
654
+
621
655
  // Effect to redirect if user is null
622
656
  React.useEffect(function () {
623
657
  var currentPath = window.location.pathname;
624
- var isWhitelisted = whitelistUrls.includes(currentPath);
658
+ var isWhitelisted = publicUrlsList.includes(currentPath);
625
659
  if (user === null && !isWhitelisted) {
626
660
  window.location.replace('/auth/login');
627
661
  }
628
- }, [user]);
662
+ }, [user, publicUrlsList]);
629
663
 
630
664
  /**
631
665
  * Memoized value containing the user data and authentication functions.