@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.
@@ -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
  */
@@ -545,14 +559,29 @@ var AuthContext = /*#__PURE__*/createContext();
545
559
  * @returns {JSX.Element} The provider component for AuthContext.
546
560
  */
547
561
  var AuthProvider = function AuthProvider(_ref) {
548
- var children = _ref.children;
549
- var whitelistUrls = ['/auth/login', '/auth/signup'];
562
+ var children = _ref.children,
563
+ _ref$publicUrls = _ref.publicUrls,
564
+ publicUrls = _ref$publicUrls === void 0 ? [] : _ref$publicUrls;
565
+ var _useState = useState(defaulPublicUrlList),
566
+ _useState2 = _slicedToArray(_useState, 2),
567
+ publicUrlsList = _useState2[0],
568
+ setPublicUrlsList = _useState2[1];
550
569
 
551
570
  // State to manage user data, persisted in local storage
552
571
  var _useLocalStorage = useLocalStorage('veripass-user-data', null),
553
572
  _useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
554
573
  user = _useLocalStorage2[0],
555
574
  setUser = _useLocalStorage2[1];
575
+ useEffect(function () {
576
+ console.log(children);
577
+ }, [children]);
578
+ React__default.Children.forEach(children, function (child) {
579
+ // Check if child is a valid React element
580
+ if (/*#__PURE__*/React__default.isValidElement(child) && child.props.isPublic) {
581
+ debugger;
582
+ publicPaths.add(child.props.path); // Assumes `path` is passed as prop
583
+ }
584
+ });
556
585
 
557
586
  /**
558
587
  * Logs in the user by saving their data to local storage and navigating to the admin page.
@@ -598,14 +627,19 @@ var AuthProvider = function AuthProvider(_ref) {
598
627
  return JSON.parse(value);
599
628
  };
600
629
 
630
+ // Effect to update public URLs whenever publicUrls prop changes
631
+ useEffect(function () {
632
+ setPublicUrlsList([].concat(_toConsumableArray(defaultPublicUrlList), _toConsumableArray(publicUrls)));
633
+ }, [publicUrls]);
634
+
601
635
  // Effect to redirect if user is null
602
636
  useEffect(function () {
603
637
  var currentPath = window.location.pathname;
604
- var isWhitelisted = whitelistUrls.includes(currentPath);
638
+ var isWhitelisted = publicUrlsList.includes(currentPath);
605
639
  if (user === null && !isWhitelisted) {
606
640
  window.location.replace('/auth/login');
607
641
  }
608
- }, [user]);
642
+ }, [user, publicUrlsList]);
609
643
 
610
644
  /**
611
645
  * Memoized value containing the user data and authentication functions.