@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.cjs.js
CHANGED
|
@@ -16718,45 +16718,39 @@ function useCAMSMSALAuth(options) {
|
|
|
16718
16718
|
var _c = React__default.useState(null), token = _c[0], setToken = _c[1];
|
|
16719
16719
|
var _d = React__default.useState(null), idToken = _d[0], setIdToken = _d[1];
|
|
16720
16720
|
var _e = React__default.useState(null), accessToken = _e[0], setAccessToken = _e[1];
|
|
16721
|
-
var _f = React__default.useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
|
|
16722
|
-
var _g = React__default.useState(false), hasRedirected = _g[0], setHasRedirected = _g[1];
|
|
16723
16721
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
16724
|
-
var isAuthenticated = !!account && !!token
|
|
16722
|
+
var isAuthenticated = !!account && !!token;
|
|
16725
16723
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16726
|
-
|
|
16727
|
-
|
|
16728
|
-
|
|
16729
|
-
|
|
16730
|
-
|
|
16731
|
-
|
|
16732
|
-
|
|
16733
|
-
|
|
16734
|
-
|
|
16735
|
-
|
|
16736
|
-
|
|
16737
|
-
|
|
16738
|
-
|
|
16739
|
-
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
|
|
16752
|
-
|
|
16753
|
-
|
|
16754
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16755
|
-
});
|
|
16756
|
-
}
|
|
16757
|
-
}, [account, instance, isMFAPending, hasRedirected]);
|
|
16724
|
+
// useEffect(() => {
|
|
16725
|
+
// const handleRedirect = async () => {
|
|
16726
|
+
// try {
|
|
16727
|
+
// const response = await instance.handleRedirectPromise();
|
|
16728
|
+
// if (response) {
|
|
16729
|
+
// const account = response.account;
|
|
16730
|
+
// instance.setActiveAccount(account);
|
|
16731
|
+
// const tokenResponse = await instance.acquireTokenSilent({
|
|
16732
|
+
// scopes,
|
|
16733
|
+
// account,
|
|
16734
|
+
// });
|
|
16735
|
+
// setToken(tokenResponse.accessToken);
|
|
16736
|
+
// setAccessToken(tokenResponse.accessToken);
|
|
16737
|
+
// setIdToken(tokenResponse.idToken);
|
|
16738
|
+
// options.onAuthSuccess?.(tokenResponse.accessToken);
|
|
16739
|
+
// if (
|
|
16740
|
+
// typeof window !== "undefined" &&
|
|
16741
|
+
// process.env.NODE_ENV !== "test"
|
|
16742
|
+
// ) {
|
|
16743
|
+
// window.location.href = options.mfaUrl!;
|
|
16744
|
+
// }
|
|
16745
|
+
// }
|
|
16746
|
+
// } catch (err) {
|
|
16747
|
+
// console.error("Redirect handling failed:", err);
|
|
16748
|
+
// }
|
|
16749
|
+
// };
|
|
16750
|
+
// handleRedirect();
|
|
16751
|
+
// }, []);
|
|
16758
16752
|
var login = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16759
|
-
var err_1,
|
|
16753
|
+
var err_1, camsError_1, camsError;
|
|
16760
16754
|
var _a, _b, _c;
|
|
16761
16755
|
return __generator(this, function (_d) {
|
|
16762
16756
|
switch (_d.label) {
|
|
@@ -16764,40 +16758,49 @@ function useCAMSMSALAuth(options) {
|
|
|
16764
16758
|
setError(null);
|
|
16765
16759
|
_d.label = 1;
|
|
16766
16760
|
case 1:
|
|
16767
|
-
_d.trys.push([1, 3, ,
|
|
16768
|
-
|
|
16761
|
+
_d.trys.push([1, 3, , 4]);
|
|
16762
|
+
// await instance.loginRedirect({
|
|
16763
|
+
// scopes,
|
|
16764
|
+
// prompt: options.prompt || "login",
|
|
16765
|
+
// });
|
|
16766
|
+
return [4 /*yield*/, instance
|
|
16767
|
+
.loginPopup({
|
|
16769
16768
|
scopes: scopes,
|
|
16770
16769
|
prompt: options.prompt || "login",
|
|
16770
|
+
})
|
|
16771
|
+
.then(function (response) {
|
|
16772
|
+
var _a;
|
|
16773
|
+
setToken(response.accessToken);
|
|
16774
|
+
setAccessToken(response.accessToken);
|
|
16775
|
+
setIdToken(response.idToken);
|
|
16776
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16777
|
+
if (typeof window !== "undefined" &&
|
|
16778
|
+
process.env.NODE_ENV !== "test") {
|
|
16779
|
+
window.location.href = options.mfaUrl;
|
|
16780
|
+
}
|
|
16771
16781
|
})];
|
|
16772
16782
|
case 2:
|
|
16783
|
+
// await instance.loginRedirect({
|
|
16784
|
+
// scopes,
|
|
16785
|
+
// prompt: options.prompt || "login",
|
|
16786
|
+
// });
|
|
16773
16787
|
_d.sent();
|
|
16774
|
-
return [3 /*break*/,
|
|
16788
|
+
return [3 /*break*/, 4];
|
|
16775
16789
|
case 3:
|
|
16776
16790
|
err_1 = _d.sent();
|
|
16777
|
-
|
|
16778
|
-
|
|
16779
|
-
|
|
16780
|
-
|
|
16781
|
-
|
|
16782
|
-
|
|
16783
|
-
|
|
16784
|
-
|
|
16785
|
-
})];
|
|
16786
|
-
case 5:
|
|
16787
|
-
_d.sent();
|
|
16788
|
-
return [2 /*return*/];
|
|
16789
|
-
case 6:
|
|
16790
|
-
redirectErr_1 = _d.sent();
|
|
16791
|
-
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + redirectErr_1);
|
|
16792
|
-
setError(camsError_1);
|
|
16793
|
-
(_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
|
|
16794
|
-
return [2 /*return*/];
|
|
16795
|
-
case 7:
|
|
16791
|
+
// If popup is blocked
|
|
16792
|
+
if (err_1.errorCode === "popup_window_error" ||
|
|
16793
|
+
((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.includes("popup"))) {
|
|
16794
|
+
camsError_1 = new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Both popup and redirect failed: " + err_1);
|
|
16795
|
+
setError(camsError_1);
|
|
16796
|
+
(_b = options.onAuthError) === null || _b === void 0 ? void 0 : _b.call(options, camsError_1);
|
|
16797
|
+
return [2 /*return*/];
|
|
16798
|
+
}
|
|
16796
16799
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16797
16800
|
setError(camsError);
|
|
16798
16801
|
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16799
|
-
return [3 /*break*/,
|
|
16800
|
-
case
|
|
16802
|
+
return [3 /*break*/, 4];
|
|
16803
|
+
case 4: return [2 /*return*/];
|
|
16801
16804
|
}
|
|
16802
16805
|
});
|
|
16803
16806
|
}); }, [instance, scopes, options]);
|
|
@@ -16812,8 +16815,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16812
16815
|
_a.sent();
|
|
16813
16816
|
setToken(null);
|
|
16814
16817
|
setError(null);
|
|
16815
|
-
setIsMFAPending(false);
|
|
16816
|
-
setHasRedirected(false);
|
|
16817
16818
|
return [3 /*break*/, 3];
|
|
16818
16819
|
case 2:
|
|
16819
16820
|
err_2 = _a.sent();
|
|
@@ -16829,7 +16830,6 @@ function useCAMSMSALAuth(options) {
|
|
|
16829
16830
|
logout: logout,
|
|
16830
16831
|
isAuthenticated: isAuthenticated,
|
|
16831
16832
|
isLoading: isLoading,
|
|
16832
|
-
isMFAPending: isMFAPending,
|
|
16833
16833
|
error: error,
|
|
16834
16834
|
token: token,
|
|
16835
16835
|
idToken: idToken,
|