@nibssplc/cams-sdk-react 0.0.1-beta.33 → 0.0.1-beta.34
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 +68 -45
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +68 -45
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16702,63 +16702,86 @@ function useCAMSMSALAuth(options) {
|
|
|
16702
16702
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
16703
16703
|
var isAuthenticated = !!account && !!token;
|
|
16704
16704
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16705
|
+
// useEffect(() => {
|
|
16706
|
+
// const handleRedirect = async () => {
|
|
16707
|
+
// try {
|
|
16708
|
+
// const response = await instance.handleRedirectPromise();
|
|
16709
|
+
// if (response) {
|
|
16710
|
+
// const account = response.account;
|
|
16711
|
+
// instance.setActiveAccount(account);
|
|
16712
|
+
// const tokenResponse = await instance.acquireTokenSilent({
|
|
16713
|
+
// scopes,
|
|
16714
|
+
// account,
|
|
16715
|
+
// });
|
|
16716
|
+
// setToken(tokenResponse.accessToken);
|
|
16717
|
+
// setAccessToken(tokenResponse.accessToken);
|
|
16718
|
+
// setIdToken(tokenResponse.idToken);
|
|
16719
|
+
// options.onAuthSuccess?.(tokenResponse.accessToken);
|
|
16720
|
+
// if (
|
|
16721
|
+
// typeof window !== "undefined" &&
|
|
16722
|
+
// process.env.NODE_ENV !== "test"
|
|
16723
|
+
// ) {
|
|
16724
|
+
// window.location.href = options.mfaUrl!;
|
|
16725
|
+
// }
|
|
16726
|
+
// }
|
|
16727
|
+
// } catch (err) {
|
|
16728
|
+
// console.error("Redirect handling failed:", err);
|
|
16729
|
+
// }
|
|
16730
|
+
// };
|
|
16731
|
+
// handleRedirect();
|
|
16732
|
+
// }, []);
|
|
16705
16733
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16706
|
-
var
|
|
16707
|
-
var _a, _b, _c
|
|
16708
|
-
return __generator(this, function (
|
|
16709
|
-
switch (
|
|
16734
|
+
var err_1, camsError_1, camsError;
|
|
16735
|
+
var _a, _b, _c;
|
|
16736
|
+
return __generator(this, function (_d) {
|
|
16737
|
+
switch (_d.label) {
|
|
16710
16738
|
case 0:
|
|
16711
16739
|
setError(null);
|
|
16712
|
-
|
|
16740
|
+
_d.label = 1;
|
|
16713
16741
|
case 1:
|
|
16714
|
-
|
|
16715
|
-
|
|
16742
|
+
_d.trys.push([1, 3, , 4]);
|
|
16743
|
+
// await instance.loginRedirect({
|
|
16744
|
+
// scopes,
|
|
16745
|
+
// prompt: options.prompt || "login",
|
|
16746
|
+
// });
|
|
16747
|
+
return [4 /*yield*/, instance
|
|
16748
|
+
.loginPopup({
|
|
16716
16749
|
scopes: scopes,
|
|
16717
16750
|
prompt: options.prompt || "login",
|
|
16751
|
+
})
|
|
16752
|
+
.then(function (response) {
|
|
16753
|
+
var _a;
|
|
16754
|
+
setToken(response.accessToken);
|
|
16755
|
+
setAccessToken(response.accessToken);
|
|
16756
|
+
setIdToken(response.idToken);
|
|
16757
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16758
|
+
if (typeof window !== "undefined" &&
|
|
16759
|
+
process.env.NODE_ENV !== "test") {
|
|
16760
|
+
window.location.href = options.mfaUrl;
|
|
16761
|
+
}
|
|
16718
16762
|
})];
|
|
16719
16763
|
case 2:
|
|
16720
|
-
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
|
|
16724
|
-
|
|
16725
|
-
|
|
16764
|
+
// await instance.loginRedirect({
|
|
16765
|
+
// scopes,
|
|
16766
|
+
// prompt: options.prompt || "login",
|
|
16767
|
+
// });
|
|
16768
|
+
_d.sent();
|
|
16769
|
+
return [3 /*break*/, 4];
|
|
16726
16770
|
case 3:
|
|
16727
|
-
|
|
16728
|
-
|
|
16729
|
-
|
|
16730
|
-
|
|
16731
|
-
|
|
16732
|
-
|
|
16771
|
+
err_1 = _d.sent();
|
|
16772
|
+
// If popup is blocked
|
|
16773
|
+
if (err_1.errorCode === "popup_window_error" ||
|
|
16774
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
16775
|
+
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + err_1);
|
|
16776
|
+
setError(camsError_1);
|
|
16777
|
+
(_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
|
|
16778
|
+
return [2 /*return*/];
|
|
16733
16779
|
}
|
|
16734
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken);
|
|
16735
|
-
return [3 /*break*/, 9];
|
|
16736
|
-
case 4:
|
|
16737
|
-
err_1 = _e.sent();
|
|
16738
|
-
if (!(err_1.errorCode === "popup_window_error" ||
|
|
16739
|
-
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.includes("popup")))) return [3 /*break*/, 8];
|
|
16740
|
-
_e.label = 5;
|
|
16741
|
-
case 5:
|
|
16742
|
-
_e.trys.push([5, 7, , 8]);
|
|
16743
|
-
return [4 /*yield*/, instance.loginRedirect({
|
|
16744
|
-
scopes: scopes,
|
|
16745
|
-
prompt: options.prompt || "login",
|
|
16746
|
-
})];
|
|
16747
|
-
case 6:
|
|
16748
|
-
_e.sent();
|
|
16749
|
-
return [2 /*return*/];
|
|
16750
|
-
case 7:
|
|
16751
|
-
redirectErr_1 = _e.sent();
|
|
16752
|
-
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16753
|
-
setError(camsError_1);
|
|
16754
|
-
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError_1);
|
|
16755
|
-
return [2 /*return*/];
|
|
16756
|
-
case 8:
|
|
16757
16780
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16758
16781
|
setError(camsError);
|
|
16759
|
-
(
|
|
16760
|
-
return [3 /*break*/,
|
|
16761
|
-
case
|
|
16782
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16783
|
+
return [3 /*break*/, 4];
|
|
16784
|
+
case 4: return [2 /*return*/];
|
|
16762
16785
|
}
|
|
16763
16786
|
});
|
|
16764
16787
|
}); }, [instance, scopes, options]);
|