@nibssplc/cams-sdk-react 0.0.1-beta.32 → 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/hooks/useCAMSMSALAuth.d.ts +0 -1
- package/dist/index.cjs.js +63 -63
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +63 -63
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16699,45 +16699,39 @@ function useCAMSMSALAuth(options) {
|
|
|
16699
16699
|
var _c = useState(null), token = _c[0], setToken = _c[1];
|
|
16700
16700
|
var _d = useState(null), idToken = _d[0], setIdToken = _d[1];
|
|
16701
16701
|
var _e = useState(null), accessToken = _e[0], setAccessToken = _e[1];
|
|
16702
|
-
var _f = useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
|
|
16703
|
-
var _g = useState(false), hasRedirected = _g[0], setHasRedirected = _g[1];
|
|
16704
16702
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
16705
|
-
var isAuthenticated = !!account && !!token
|
|
16703
|
+
var isAuthenticated = !!account && !!token;
|
|
16706
16704
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16707
|
-
useEffect(
|
|
16708
|
-
|
|
16709
|
-
|
|
16710
|
-
|
|
16711
|
-
|
|
16712
|
-
|
|
16713
|
-
|
|
16714
|
-
|
|
16715
|
-
|
|
16716
|
-
|
|
16717
|
-
|
|
16718
|
-
|
|
16719
|
-
|
|
16720
|
-
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
|
|
16724
|
-
|
|
16725
|
-
|
|
16726
|
-
|
|
16727
|
-
|
|
16728
|
-
|
|
16729
|
-
|
|
16730
|
-
|
|
16731
|
-
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16736
|
-
});
|
|
16737
|
-
}
|
|
16738
|
-
}, [account, instance, isMFAPending, hasRedirected]);
|
|
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
|
+
// }, []);
|
|
16739
16733
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16740
|
-
var err_1,
|
|
16734
|
+
var err_1, camsError_1, camsError;
|
|
16741
16735
|
var _a, _b, _c;
|
|
16742
16736
|
return __generator(this, function (_d) {
|
|
16743
16737
|
switch (_d.label) {
|
|
@@ -16745,40 +16739,49 @@ function useCAMSMSALAuth(options) {
|
|
|
16745
16739
|
setError(null);
|
|
16746
16740
|
_d.label = 1;
|
|
16747
16741
|
case 1:
|
|
16748
|
-
_d.trys.push([1, 3, ,
|
|
16749
|
-
|
|
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({
|
|
16750
16749
|
scopes: scopes,
|
|
16751
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
|
+
}
|
|
16752
16762
|
})];
|
|
16753
16763
|
case 2:
|
|
16764
|
+
// await instance.loginRedirect({
|
|
16765
|
+
// scopes,
|
|
16766
|
+
// prompt: options.prompt || "login",
|
|
16767
|
+
// });
|
|
16754
16768
|
_d.sent();
|
|
16755
|
-
return [3 /*break*/,
|
|
16769
|
+
return [3 /*break*/, 4];
|
|
16756
16770
|
case 3:
|
|
16757
16771
|
err_1 = _d.sent();
|
|
16758
|
-
|
|
16759
|
-
|
|
16760
|
-
|
|
16761
|
-
|
|
16762
|
-
|
|
16763
|
-
|
|
16764
|
-
|
|
16765
|
-
|
|
16766
|
-
})];
|
|
16767
|
-
case 5:
|
|
16768
|
-
_d.sent();
|
|
16769
|
-
return [2 /*return*/];
|
|
16770
|
-
case 6:
|
|
16771
|
-
redirectErr_1 = _d.sent();
|
|
16772
|
-
camsError_1 = new CAMSError(CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16773
|
-
setError(camsError_1);
|
|
16774
|
-
(_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
|
|
16775
|
-
return [2 /*return*/];
|
|
16776
|
-
case 7:
|
|
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*/];
|
|
16779
|
+
}
|
|
16777
16780
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16778
16781
|
setError(camsError);
|
|
16779
16782
|
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16780
|
-
return [3 /*break*/,
|
|
16781
|
-
case
|
|
16783
|
+
return [3 /*break*/, 4];
|
|
16784
|
+
case 4: return [2 /*return*/];
|
|
16782
16785
|
}
|
|
16783
16786
|
});
|
|
16784
16787
|
}); }, [instance, scopes, options]);
|
|
@@ -16793,8 +16796,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16793
16796
|
_a.sent();
|
|
16794
16797
|
setToken(null);
|
|
16795
16798
|
setError(null);
|
|
16796
|
-
setIsMFAPending(false);
|
|
16797
|
-
setHasRedirected(false);
|
|
16798
16799
|
return [3 /*break*/, 3];
|
|
16799
16800
|
case 2:
|
|
16800
16801
|
err_2 = _a.sent();
|
|
@@ -16810,7 +16811,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16810
16811
|
logout: logout,
|
|
16811
16812
|
isAuthenticated: isAuthenticated,
|
|
16812
16813
|
isLoading: isLoading,
|
|
16813
|
-
isMFAPending: isMFAPending,
|
|
16814
16814
|
error: error,
|
|
16815
16815
|
token: token,
|
|
16816
16816
|
idToken: idToken,
|