@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.
@@ -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,13 +560,27 @@ var AuthContext = /*#__PURE__*/createContext();
546
560
  */
547
561
  var AuthProvider = function AuthProvider(_ref) {
548
562
  var children = _ref.children;
549
- var whitelistUrls = ['/auth/login', '/auth/signup'];
563
+ _ref.publicUrls;
564
+ var _useState = useState(defaulPublicUrlList),
565
+ _useState2 = _slicedToArray(_useState, 2),
566
+ publicUrlsList = _useState2[0],
567
+ setPublicUrlsList = _useState2[1];
550
568
 
551
569
  // State to manage user data, persisted in local storage
552
570
  var _useLocalStorage = useLocalStorage('veripass-user-data', null),
553
571
  _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
554
572
  user = _useLocalStorage2[0],
555
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
+ });
556
584
 
557
585
  /**
558
586
  * Logs in the user by saving their data to local storage and navigating to the admin page.
@@ -598,14 +626,19 @@ var AuthProvider = function AuthProvider(_ref) {
598
626
  return JSON.parse(value);
599
627
  };
600
628
 
629
+ // Effect to update public URLs whenever additionalPublicUrls prop changes
630
+ useEffect(function () {
631
+ setPublicUrlsList([].concat(_toConsumableArray(defaultPublicUrlList), _toConsumableArray(additionalPublicUrls)));
632
+ }, [additionalPublicUrls]);
633
+
601
634
  // Effect to redirect if user is null
602
635
  useEffect(function () {
603
636
  var currentPath = window.location.pathname;
604
- var isWhitelisted = whitelistUrls.includes(currentPath);
637
+ var isWhitelisted = publicUrlsList.includes(currentPath);
605
638
  if (user === null && !isWhitelisted) {
606
639
  window.location.replace('/auth/login');
607
640
  }
608
- }, [user]);
641
+ }, [user, publicUrlsList]);
609
642
 
610
643
  /**
611
644
  * Memoized value containing the user data and authentication functions.