@veripass/react-sdk 1.0.3 → 1.0.4
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 +124 -125
- package/dist/react-sdk.cjs.js.map +1 -1
- package/dist/react-sdk.esm.js +124 -125
- package/dist/react-sdk.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/react-sdk.esm.js
CHANGED
|
@@ -505,6 +505,130 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
507
|
|
|
508
|
+
var useLocalStorage = function useLocalStorage(keyName, defaultValue) {
|
|
509
|
+
var _useState = useState(function () {
|
|
510
|
+
try {
|
|
511
|
+
var value = window.localStorage.getItem(keyName);
|
|
512
|
+
if (value) {
|
|
513
|
+
return JSON.parse(value);
|
|
514
|
+
} else {
|
|
515
|
+
window.localStorage.setItem(keyName, JSON.stringify(defaultValue));
|
|
516
|
+
return defaultValue;
|
|
517
|
+
}
|
|
518
|
+
} catch (err) {
|
|
519
|
+
return defaultValue;
|
|
520
|
+
}
|
|
521
|
+
}),
|
|
522
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
523
|
+
storedValue = _useState2[0],
|
|
524
|
+
setStoredValue = _useState2[1];
|
|
525
|
+
var setValue = function setValue(newValue) {
|
|
526
|
+
try {
|
|
527
|
+
window.localStorage.setItem(keyName, JSON.stringify(newValue));
|
|
528
|
+
} catch (err) {}
|
|
529
|
+
setStoredValue(newValue);
|
|
530
|
+
};
|
|
531
|
+
return [storedValue, setValue];
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Authentication context used to provide user authentication data and functions.
|
|
536
|
+
*/
|
|
537
|
+
var AuthContext = /*#__PURE__*/createContext();
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* AuthProvider component that wraps around the application or part of it to provide authentication context.
|
|
541
|
+
* It uses local storage to persist user data and provides login, logout, and token retrieval functions.
|
|
542
|
+
*
|
|
543
|
+
* @param {object} props - The component props.
|
|
544
|
+
* @param {React.ReactNode} props.children - The children components that require access to the authentication context.
|
|
545
|
+
* @returns {JSX.Element} The provider component for AuthContext.
|
|
546
|
+
*/
|
|
547
|
+
var AuthProvider = function AuthProvider(_ref) {
|
|
548
|
+
var children = _ref.children;
|
|
549
|
+
// State to manage user data, persisted in local storage
|
|
550
|
+
var _useLocalStorage = useLocalStorage('veripass-user-data', null),
|
|
551
|
+
_useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
|
|
552
|
+
user = _useLocalStorage2[0],
|
|
553
|
+
setUser = _useLocalStorage2[1];
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Logs in the user by saving their data to local storage and navigating to the admin page.
|
|
557
|
+
*
|
|
558
|
+
* @param {object} user - The user data to be stored.
|
|
559
|
+
*/
|
|
560
|
+
var login = /*#__PURE__*/function () {
|
|
561
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
562
|
+
var user, _ref2$redirectUrl, redirectUrl;
|
|
563
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
564
|
+
while (1) switch (_context.prev = _context.next) {
|
|
565
|
+
case 0:
|
|
566
|
+
user = _ref2.user, _ref2$redirectUrl = _ref2.redirectUrl, redirectUrl = _ref2$redirectUrl === void 0 ? '' : _ref2$redirectUrl;
|
|
567
|
+
setUser(user);
|
|
568
|
+
if (redirectUrl) {
|
|
569
|
+
window.location.replace(redirectUrl);
|
|
570
|
+
}
|
|
571
|
+
case 3:
|
|
572
|
+
case "end":
|
|
573
|
+
return _context.stop();
|
|
574
|
+
}
|
|
575
|
+
}, _callee);
|
|
576
|
+
}));
|
|
577
|
+
return function login(_x) {
|
|
578
|
+
return _ref3.apply(this, arguments);
|
|
579
|
+
};
|
|
580
|
+
}();
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* Logs out the current user by clearing their data from local storage.
|
|
584
|
+
*/
|
|
585
|
+
var logout = function logout() {
|
|
586
|
+
setUser(null);
|
|
587
|
+
};
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Retrieves the stored user data (token) from local storage.
|
|
591
|
+
*
|
|
592
|
+
* @returns {object|null} The user data stored in local storage, or null if not found.
|
|
593
|
+
*/
|
|
594
|
+
var getToken = function getToken() {
|
|
595
|
+
var value = window.localStorage.getItem('veripass-user-data');
|
|
596
|
+
return JSON.parse(value);
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Memoized value containing the user data and authentication functions.
|
|
601
|
+
*
|
|
602
|
+
* @typedef {object} AuthContextValue
|
|
603
|
+
* @property {object|null} user - The currently authenticated user or null if not authenticated.
|
|
604
|
+
* @property {function(object): Promise<void>} login - Function to log in the user.
|
|
605
|
+
* @property {function(): void} logout - Function to log out the user.
|
|
606
|
+
* @property {function(): object|null} getToken - Function to get the current user's token.
|
|
607
|
+
*
|
|
608
|
+
* @returns {AuthContextValue} The context value with user data and authentication functions.
|
|
609
|
+
*/
|
|
610
|
+
var value = useMemo(function () {
|
|
611
|
+
return {
|
|
612
|
+
user: user,
|
|
613
|
+
login: login,
|
|
614
|
+
logout: logout,
|
|
615
|
+
getToken: getToken
|
|
616
|
+
};
|
|
617
|
+
}, [user]);
|
|
618
|
+
return /*#__PURE__*/React__default.createElement(AuthContext.Provider, {
|
|
619
|
+
value: value
|
|
620
|
+
}, children);
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Custom hook to access the authentication context.
|
|
625
|
+
*
|
|
626
|
+
* @returns {AuthContextValue} The authentication context value, including user data, login, logout, and getToken functions.
|
|
627
|
+
*/
|
|
628
|
+
var useAuth = function useAuth() {
|
|
629
|
+
return useContext(AuthContext);
|
|
630
|
+
};
|
|
631
|
+
|
|
508
632
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
509
633
|
|
|
510
634
|
function getDefaultExportFromCjs (x) {
|
|
@@ -32706,131 +32830,6 @@ function useViewTransitionState(to, opts) {
|
|
|
32706
32830
|
return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
|
|
32707
32831
|
}
|
|
32708
32832
|
|
|
32709
|
-
var useLocalStorage = function useLocalStorage(keyName, defaultValue) {
|
|
32710
|
-
var _useState = useState(function () {
|
|
32711
|
-
try {
|
|
32712
|
-
var value = window.localStorage.getItem(keyName);
|
|
32713
|
-
if (value) {
|
|
32714
|
-
return JSON.parse(value);
|
|
32715
|
-
} else {
|
|
32716
|
-
window.localStorage.setItem(keyName, JSON.stringify(defaultValue));
|
|
32717
|
-
return defaultValue;
|
|
32718
|
-
}
|
|
32719
|
-
} catch (err) {
|
|
32720
|
-
return defaultValue;
|
|
32721
|
-
}
|
|
32722
|
-
}),
|
|
32723
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
32724
|
-
storedValue = _useState2[0],
|
|
32725
|
-
setStoredValue = _useState2[1];
|
|
32726
|
-
var setValue = function setValue(newValue) {
|
|
32727
|
-
try {
|
|
32728
|
-
window.localStorage.setItem(keyName, JSON.stringify(newValue));
|
|
32729
|
-
} catch (err) {}
|
|
32730
|
-
setStoredValue(newValue);
|
|
32731
|
-
};
|
|
32732
|
-
return [storedValue, setValue];
|
|
32733
|
-
};
|
|
32734
|
-
|
|
32735
|
-
/**
|
|
32736
|
-
* Authentication context used to provide user authentication data and functions.
|
|
32737
|
-
*/
|
|
32738
|
-
var AuthContext = /*#__PURE__*/createContext();
|
|
32739
|
-
|
|
32740
|
-
/**
|
|
32741
|
-
* AuthProvider component that wraps around the application or part of it to provide authentication context.
|
|
32742
|
-
* It uses local storage to persist user data and provides login, logout, and token retrieval functions.
|
|
32743
|
-
*
|
|
32744
|
-
* @param {object} props - The component props.
|
|
32745
|
-
* @param {React.ReactNode} props.children - The children components that require access to the authentication context.
|
|
32746
|
-
* @returns {JSX.Element} The provider component for AuthContext.
|
|
32747
|
-
*/
|
|
32748
|
-
var AuthProvider = function AuthProvider(_ref) {
|
|
32749
|
-
var children = _ref.children;
|
|
32750
|
-
// State to manage user data, persisted in local storage
|
|
32751
|
-
var _useLocalStorage = useLocalStorage('veripass-user-data', null),
|
|
32752
|
-
_useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
|
|
32753
|
-
user = _useLocalStorage2[0],
|
|
32754
|
-
setUser = _useLocalStorage2[1];
|
|
32755
|
-
var navigate = useNavigate();
|
|
32756
|
-
|
|
32757
|
-
/**
|
|
32758
|
-
* Logs in the user by saving their data to local storage and navigating to the admin page.
|
|
32759
|
-
*
|
|
32760
|
-
* @param {object} user - The user data to be stored.
|
|
32761
|
-
*/
|
|
32762
|
-
var login = /*#__PURE__*/function () {
|
|
32763
|
-
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
|
|
32764
|
-
var user, _ref2$redirectUrl, redirectUrl;
|
|
32765
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
32766
|
-
while (1) switch (_context.prev = _context.next) {
|
|
32767
|
-
case 0:
|
|
32768
|
-
user = _ref2.user, _ref2$redirectUrl = _ref2.redirectUrl, redirectUrl = _ref2$redirectUrl === void 0 ? '' : _ref2$redirectUrl;
|
|
32769
|
-
setUser(user);
|
|
32770
|
-
navigate(redirectUrl, {
|
|
32771
|
-
replace: true
|
|
32772
|
-
});
|
|
32773
|
-
case 3:
|
|
32774
|
-
case "end":
|
|
32775
|
-
return _context.stop();
|
|
32776
|
-
}
|
|
32777
|
-
}, _callee);
|
|
32778
|
-
}));
|
|
32779
|
-
return function login(_x) {
|
|
32780
|
-
return _ref3.apply(this, arguments);
|
|
32781
|
-
};
|
|
32782
|
-
}();
|
|
32783
|
-
|
|
32784
|
-
/**
|
|
32785
|
-
* Logs out the current user by clearing their data from local storage.
|
|
32786
|
-
*/
|
|
32787
|
-
var logout = function logout() {
|
|
32788
|
-
setUser(null);
|
|
32789
|
-
};
|
|
32790
|
-
|
|
32791
|
-
/**
|
|
32792
|
-
* Retrieves the stored user data (token) from local storage.
|
|
32793
|
-
*
|
|
32794
|
-
* @returns {object|null} The user data stored in local storage, or null if not found.
|
|
32795
|
-
*/
|
|
32796
|
-
var getToken = function getToken() {
|
|
32797
|
-
var value = window.localStorage.getItem('veripass-user-data');
|
|
32798
|
-
return JSON.parse(value);
|
|
32799
|
-
};
|
|
32800
|
-
|
|
32801
|
-
/**
|
|
32802
|
-
* Memoized value containing the user data and authentication functions.
|
|
32803
|
-
*
|
|
32804
|
-
* @typedef {object} AuthContextValue
|
|
32805
|
-
* @property {object|null} user - The currently authenticated user or null if not authenticated.
|
|
32806
|
-
* @property {function(object): Promise<void>} login - Function to log in the user.
|
|
32807
|
-
* @property {function(): void} logout - Function to log out the user.
|
|
32808
|
-
* @property {function(): object|null} getToken - Function to get the current user's token.
|
|
32809
|
-
*
|
|
32810
|
-
* @returns {AuthContextValue} The context value with user data and authentication functions.
|
|
32811
|
-
*/
|
|
32812
|
-
var value = useMemo(function () {
|
|
32813
|
-
return {
|
|
32814
|
-
user: user,
|
|
32815
|
-
login: login,
|
|
32816
|
-
logout: logout,
|
|
32817
|
-
getToken: getToken
|
|
32818
|
-
};
|
|
32819
|
-
}, [user]);
|
|
32820
|
-
return /*#__PURE__*/React__default.createElement(AuthContext.Provider, {
|
|
32821
|
-
value: value
|
|
32822
|
-
}, children);
|
|
32823
|
-
};
|
|
32824
|
-
|
|
32825
|
-
/**
|
|
32826
|
-
* Custom hook to access the authentication context.
|
|
32827
|
-
*
|
|
32828
|
-
* @returns {AuthContextValue} The authentication context value, including user data, login, logout, and getToken functions.
|
|
32829
|
-
*/
|
|
32830
|
-
var useAuth = function useAuth() {
|
|
32831
|
-
return useContext(AuthContext);
|
|
32832
|
-
};
|
|
32833
|
-
|
|
32834
32833
|
var sweetalert2_all = {exports: {}};
|
|
32835
32834
|
|
|
32836
32835
|
/*!
|