@nibssplc/cams-sdk-react 0.0.1-beta.41 → 0.0.1-beta.43
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/index.cjs.js +20 -9
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +20 -9
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16695,7 +16695,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16695
16695
|
}; }
|
|
16696
16696
|
var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
|
|
16697
16697
|
var account = useAccount(accounts[0] || {});
|
|
16698
|
-
var storageKey =
|
|
16698
|
+
var storageKey = "CAMS-MSAL-AUTH-SDK";
|
|
16699
16699
|
var _b = useState(null), error = _b[0], setError = _b[1];
|
|
16700
16700
|
var _c = useState(null), token = _c[0], setToken = _c[1];
|
|
16701
16701
|
var _d = useState(null), idToken = _d[0], setIdToken = _d[1];
|
|
@@ -16705,7 +16705,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16705
16705
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16706
16706
|
var isTokenValid = function (token) {
|
|
16707
16707
|
try {
|
|
16708
|
-
var payload = JSON.parse(atob(token.split(
|
|
16708
|
+
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
16709
16709
|
return payload.exp * 1000 > Date.now();
|
|
16710
16710
|
}
|
|
16711
16711
|
catch (_a) {
|
|
@@ -16713,7 +16713,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16713
16713
|
}
|
|
16714
16714
|
};
|
|
16715
16715
|
useEffect(function () {
|
|
16716
|
-
if (typeof window !==
|
|
16716
|
+
if (typeof window !== "undefined" && !token) {
|
|
16717
16717
|
var stored = localStorage.getItem(storageKey);
|
|
16718
16718
|
if (stored) {
|
|
16719
16719
|
try {
|
|
@@ -16782,23 +16782,34 @@ function useCAMSMSALAuth(options) {
|
|
|
16782
16782
|
var _a;
|
|
16783
16783
|
Logger$1.debug("Login Token response:", {
|
|
16784
16784
|
accessToken: accessToken,
|
|
16785
|
-
idToken: idToken
|
|
16785
|
+
idToken: idToken,
|
|
16786
16786
|
});
|
|
16787
16787
|
setToken(response.accessToken);
|
|
16788
16788
|
setAccessToken(response.accessToken);
|
|
16789
16789
|
setIdToken(response.idToken);
|
|
16790
16790
|
// Persist tokens to localStorage
|
|
16791
|
-
if (typeof window !==
|
|
16791
|
+
if (typeof window !== "undefined") {
|
|
16792
16792
|
localStorage.setItem(storageKey, JSON.stringify({
|
|
16793
16793
|
isAuthenticated: true,
|
|
16794
16794
|
accessToken: response.accessToken,
|
|
16795
|
-
idToken: response.idToken
|
|
16795
|
+
idToken: response.idToken,
|
|
16796
16796
|
}));
|
|
16797
16797
|
}
|
|
16798
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16799
16798
|
if (typeof window !== "undefined" &&
|
|
16800
16799
|
process.env.NODE_ENV !== "test") {
|
|
16801
|
-
|
|
16800
|
+
// Center the popup window
|
|
16801
|
+
var left = (window.screen.width - 500) / 2;
|
|
16802
|
+
var top_1 = (window.screen.height - 600) / 2;
|
|
16803
|
+
var authWindow = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
|
|
16804
|
+
if (!authWindow) {
|
|
16805
|
+
Logger$1.error("Popup window blocked");
|
|
16806
|
+
throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16807
|
+
}
|
|
16808
|
+
if (authWindow.closed) {
|
|
16809
|
+
Logger$1.error("Popup immediately closed by blocker");
|
|
16810
|
+
throw new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16811
|
+
}
|
|
16812
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16802
16813
|
}
|
|
16803
16814
|
})];
|
|
16804
16815
|
case 2:
|
|
@@ -16839,7 +16850,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16839
16850
|
setAccessToken(null);
|
|
16840
16851
|
setIdToken(null);
|
|
16841
16852
|
setError(null);
|
|
16842
|
-
if (typeof window !==
|
|
16853
|
+
if (typeof window !== "undefined") {
|
|
16843
16854
|
localStorage.removeItem(storageKey);
|
|
16844
16855
|
}
|
|
16845
16856
|
return [3 /*break*/, 3];
|