@veripass/react-sdk 1.0.12 → 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.
@@ -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
  */
@@ -566,13 +580,27 @@ var AuthContext = /*#__PURE__*/React.createContext();
566
580
  */
567
581
  var AuthProvider = function AuthProvider(_ref) {
568
582
  var children = _ref.children;
569
- var whitelistUrls = ['/auth/login', '/auth/signup'];
583
+ _ref.publicUrls;
584
+ var _useState = React.useState(defaulPublicUrlList),
585
+ _useState2 = _slicedToArray(_useState, 2),
586
+ publicUrlsList = _useState2[0],
587
+ setPublicUrlsList = _useState2[1];
570
588
 
571
589
  // State to manage user data, persisted in local storage
572
590
  var _useLocalStorage = useLocalStorage('veripass-user-data', null),
573
591
  _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
574
592
  user = _useLocalStorage2[0],
575
593
  setUser = _useLocalStorage2[1];
594
+ React.useEffect(function () {
595
+ console.log(children);
596
+ }, [children]);
597
+ React.Children.forEach(children, function (child) {
598
+ // Check if child is a valid React element
599
+ if (/*#__PURE__*/React.isValidElement(child) && child.props.isPublic) {
600
+ debugger;
601
+ publicPaths.add(child.props.path); // Assumes `path` is passed as prop
602
+ }
603
+ });
576
604
 
577
605
  /**
578
606
  * Logs in the user by saving their data to local storage and navigating to the admin page.
@@ -618,14 +646,19 @@ var AuthProvider = function AuthProvider(_ref) {
618
646
  return JSON.parse(value);
619
647
  };
620
648
 
649
+ // Effect to update public URLs whenever additionalPublicUrls prop changes
650
+ React.useEffect(function () {
651
+ setPublicUrlsList([].concat(_toConsumableArray(defaultPublicUrlList), _toConsumableArray(additionalPublicUrls)));
652
+ }, [additionalPublicUrls]);
653
+
621
654
  // Effect to redirect if user is null
622
655
  React.useEffect(function () {
623
656
  var currentPath = window.location.pathname;
624
- var isWhitelisted = whitelistUrls.includes(currentPath);
657
+ var isWhitelisted = publicUrlsList.includes(currentPath);
625
658
  if (user === null && !isWhitelisted) {
626
659
  window.location.replace('/auth/login');
627
660
  }
628
- }, [user]);
661
+ }, [user, publicUrlsList]);
629
662
 
630
663
  /**
631
664
  * Memoized value containing the user data and authentication functions.