@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.
- package/dist/react-sdk.cjs.js +42 -5
- package/dist/react-sdk.cjs.js.map +1 -1
- package/dist/react-sdk.esm.js +42 -5
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/react-sdk.cjs.js
CHANGED
|
@@ -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,15 +580,31 @@ var AuthContext = /*#__PURE__*/React.createContext();
|
|
|
566
580
|
*/
|
|
567
581
|
var AuthProvider = function AuthProvider(_ref) {
|
|
568
582
|
var children = _ref.children;
|
|
583
|
+
_ref.publicUrls;
|
|
584
|
+
var _useState = React.useState(defaulPublicUrlList),
|
|
585
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
586
|
+
publicUrlsList = _useState2[0],
|
|
587
|
+
setPublicUrlsList = _useState2[1];
|
|
588
|
+
|
|
569
589
|
// State to manage user data, persisted in local storage
|
|
570
590
|
var _useLocalStorage = useLocalStorage('veripass-user-data', null),
|
|
571
591
|
_useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
|
|
572
592
|
user = _useLocalStorage2[0],
|
|
573
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
|
+
});
|
|
574
604
|
|
|
575
605
|
/**
|
|
576
606
|
* Logs in the user by saving their data to local storage and navigating to the admin page.
|
|
577
|
-
*
|
|
607
|
+
*
|
|
578
608
|
* @param {object} user - The user data to be stored.
|
|
579
609
|
*/
|
|
580
610
|
var login = /*#__PURE__*/function () {
|
|
@@ -608,7 +638,7 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
608
638
|
|
|
609
639
|
/**
|
|
610
640
|
* Retrieves the stored user data (token) from local storage.
|
|
611
|
-
*
|
|
641
|
+
*
|
|
612
642
|
* @returns {object|null} The user data stored in local storage, or null if not found.
|
|
613
643
|
*/
|
|
614
644
|
var getToken = function getToken() {
|
|
@@ -616,12 +646,19 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
616
646
|
return JSON.parse(value);
|
|
617
647
|
};
|
|
618
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
|
+
|
|
619
654
|
// Effect to redirect if user is null
|
|
620
655
|
React.useEffect(function () {
|
|
621
|
-
|
|
656
|
+
var currentPath = window.location.pathname;
|
|
657
|
+
var isWhitelisted = publicUrlsList.includes(currentPath);
|
|
658
|
+
if (user === null && !isWhitelisted) {
|
|
622
659
|
window.location.replace('/auth/login');
|
|
623
660
|
}
|
|
624
|
-
}, [user]);
|
|
661
|
+
}, [user, publicUrlsList]);
|
|
625
662
|
|
|
626
663
|
/**
|
|
627
664
|
* Memoized value containing the user data and authentication functions.
|
|
@@ -649,7 +686,7 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
649
686
|
|
|
650
687
|
/**
|
|
651
688
|
* Custom hook to access the authentication context.
|
|
652
|
-
*
|
|
689
|
+
*
|
|
653
690
|
* @returns {AuthContextValue} The authentication context value, including user data, login, logout, and getToken functions.
|
|
654
691
|
*/
|
|
655
692
|
var useAuth = function useAuth() {
|