@nibssplc/cams-sdk-react 0.0.1-beta.46 → 0.0.1-beta.47
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 +52 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +53 -4
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -16821,15 +16821,63 @@ function useCAMSMSALAuth(options) {
|
|
|
16821
16821
|
// Center the popup window
|
|
16822
16822
|
var left = (window.screen.width - 500) / 2;
|
|
16823
16823
|
var top_1 = (window.screen.height - 600) / 2;
|
|
16824
|
-
var
|
|
16825
|
-
if (!
|
|
16824
|
+
var authWindow_1 = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
|
|
16825
|
+
if (!authWindow_1) {
|
|
16826
16826
|
camsSdk.Logger.error("Popup window blocked");
|
|
16827
16827
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16828
16828
|
}
|
|
16829
|
-
if (
|
|
16829
|
+
if (authWindow_1.closed) {
|
|
16830
16830
|
camsSdk.Logger.error("Popup immediately closed by blocker");
|
|
16831
16831
|
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16832
16832
|
}
|
|
16833
|
+
var cleanup_1 = function () {
|
|
16834
|
+
window.removeEventListener('message', listener_1);
|
|
16835
|
+
clearInterval(checkClosed_1);
|
|
16836
|
+
};
|
|
16837
|
+
var cleanupAndClose_1 = function (error) {
|
|
16838
|
+
var _a;
|
|
16839
|
+
cleanup_1();
|
|
16840
|
+
try {
|
|
16841
|
+
if (authWindow_1 && !authWindow_1.closed) {
|
|
16842
|
+
authWindow_1.close();
|
|
16843
|
+
}
|
|
16844
|
+
}
|
|
16845
|
+
catch (_b) { }
|
|
16846
|
+
if (error) {
|
|
16847
|
+
setError(error);
|
|
16848
|
+
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, error);
|
|
16849
|
+
}
|
|
16850
|
+
};
|
|
16851
|
+
var listener_1 = function (event) {
|
|
16852
|
+
if (event.source !== authWindow_1)
|
|
16853
|
+
return;
|
|
16854
|
+
var tokenMsg = camsSdk.ProfileSchema.safeParse(event.data);
|
|
16855
|
+
if (tokenMsg.success) {
|
|
16856
|
+
localStorage.setItem(storageKey, JSON.stringify({
|
|
16857
|
+
isAuthenticated: true,
|
|
16858
|
+
accessToken: response.accessToken,
|
|
16859
|
+
idToken: response.idToken,
|
|
16860
|
+
appCode: ''
|
|
16861
|
+
}));
|
|
16862
|
+
cleanupAndClose_1();
|
|
16863
|
+
return;
|
|
16864
|
+
}
|
|
16865
|
+
var authFailureMsg = camsSdk.AuthFailureMessageSchema.safeParse(event.data);
|
|
16866
|
+
if (authFailureMsg.success) {
|
|
16867
|
+
cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, authFailureMsg.data.error));
|
|
16868
|
+
return;
|
|
16869
|
+
}
|
|
16870
|
+
var errorMsg = camsSdk.ErrorMessageSchema.safeParse(event.data);
|
|
16871
|
+
if (errorMsg.success) {
|
|
16872
|
+
cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, errorMsg.data.error));
|
|
16873
|
+
}
|
|
16874
|
+
};
|
|
16875
|
+
window.addEventListener('message', listener_1);
|
|
16876
|
+
var checkClosed_1 = setInterval(function () {
|
|
16877
|
+
if (authWindow_1.closed) {
|
|
16878
|
+
cleanupAndClose_1(new camsSdk.CAMSError(camsSdk.CAMSErrorType.USER_CANCELLED, 'Authentication cancelled'));
|
|
16879
|
+
}
|
|
16880
|
+
}, 1000);
|
|
16833
16881
|
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16834
16882
|
}
|
|
16835
16883
|
})];
|
|
@@ -16870,6 +16918,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16870
16918
|
setToken("");
|
|
16871
16919
|
setAccessToken("");
|
|
16872
16920
|
setIdToken("");
|
|
16921
|
+
setAppCode("");
|
|
16873
16922
|
setError(null);
|
|
16874
16923
|
if (typeof window !== "undefined") {
|
|
16875
16924
|
localStorage.removeItem(storageKey);
|