@veripass/react-sdk 1.0.11 → 1.0.12
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.esm.js
CHANGED
|
@@ -546,6 +546,8 @@ var AuthContext = /*#__PURE__*/createContext();
|
|
|
546
546
|
*/
|
|
547
547
|
var AuthProvider = function AuthProvider(_ref) {
|
|
548
548
|
var children = _ref.children;
|
|
549
|
+
var whitelistUrls = ['/auth/login', '/auth/signup'];
|
|
550
|
+
|
|
549
551
|
// State to manage user data, persisted in local storage
|
|
550
552
|
var _useLocalStorage = useLocalStorage('veripass-user-data', null),
|
|
551
553
|
_useLocalStorage2 = _slicedToArray(_useLocalStorage, 2),
|
|
@@ -554,7 +556,7 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
554
556
|
|
|
555
557
|
/**
|
|
556
558
|
* Logs in the user by saving their data to local storage and navigating to the admin page.
|
|
557
|
-
*
|
|
559
|
+
*
|
|
558
560
|
* @param {object} user - The user data to be stored.
|
|
559
561
|
*/
|
|
560
562
|
var login = /*#__PURE__*/function () {
|
|
@@ -588,7 +590,7 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
588
590
|
|
|
589
591
|
/**
|
|
590
592
|
* Retrieves the stored user data (token) from local storage.
|
|
591
|
-
*
|
|
593
|
+
*
|
|
592
594
|
* @returns {object|null} The user data stored in local storage, or null if not found.
|
|
593
595
|
*/
|
|
594
596
|
var getToken = function getToken() {
|
|
@@ -598,7 +600,9 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
598
600
|
|
|
599
601
|
// Effect to redirect if user is null
|
|
600
602
|
useEffect(function () {
|
|
601
|
-
|
|
603
|
+
var currentPath = window.location.pathname;
|
|
604
|
+
var isWhitelisted = whitelistUrls.includes(currentPath);
|
|
605
|
+
if (user === null && !isWhitelisted) {
|
|
602
606
|
window.location.replace('/auth/login');
|
|
603
607
|
}
|
|
604
608
|
}, [user]);
|
|
@@ -629,7 +633,7 @@ var AuthProvider = function AuthProvider(_ref) {
|
|
|
629
633
|
|
|
630
634
|
/**
|
|
631
635
|
* Custom hook to access the authentication context.
|
|
632
|
-
*
|
|
636
|
+
*
|
|
633
637
|
* @returns {AuthContextValue} The authentication context value, including user data, login, logout, and getToken functions.
|
|
634
638
|
*/
|
|
635
639
|
var useAuth = function useAuth() {
|