@nibssplc/cams-sdk-react 0.0.1-beta.20 → 0.0.1-beta.21
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 +48 -52
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +48 -52
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -16701,75 +16701,71 @@ function useCAMSMSALAuth(options) {
|
|
|
16701
16701
|
var isAuthenticated = !!account && !!token && !isMFAPending;
|
|
16702
16702
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16703
16703
|
useEffect(function () {
|
|
16704
|
-
if (account && !isMFAPending) {
|
|
16705
|
-
|
|
16706
|
-
|
|
16707
|
-
.
|
|
16708
|
-
scopes: scopes,
|
|
16709
|
-
account: account,
|
|
16710
|
-
prompt: options.prompt || "select_account",
|
|
16711
|
-
})
|
|
16712
|
-
.then(function (response) {
|
|
16713
|
-
var _a, _b;
|
|
16714
|
-
if (options.mfaUrl) {
|
|
16715
|
-
setIsMFAPending(true);
|
|
16716
|
-
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
|
|
16717
|
-
}
|
|
16718
|
-
else {
|
|
16719
|
-
setToken(response.accessToken);
|
|
16720
|
-
setProfile({
|
|
16721
|
-
type: "AUTH_SUCCESS",
|
|
16722
|
-
userProfile: {
|
|
16723
|
-
name: account.name || "",
|
|
16724
|
-
email: account.username || "",
|
|
16725
|
-
isAuthenticated: true,
|
|
16726
|
-
mfaIsEnabled: true,
|
|
16727
|
-
message: "Authentication successful",
|
|
16728
|
-
userType: "USER",
|
|
16729
|
-
tokens: {
|
|
16730
|
-
Nonce: "",
|
|
16731
|
-
Bearer: response.accessToken,
|
|
16732
|
-
},
|
|
16733
|
-
},
|
|
16734
|
-
});
|
|
16735
|
-
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
|
|
16736
|
-
}
|
|
16737
|
-
})
|
|
16738
|
-
.catch(function (err) {
|
|
16739
|
-
var _a;
|
|
16740
|
-
var camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
|
|
16741
|
-
setError(camsError);
|
|
16742
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16704
|
+
if (account && !token && !isMFAPending) {
|
|
16705
|
+
login().catch(function (err) {
|
|
16706
|
+
// Error is already handled in login function
|
|
16707
|
+
console.error("Failed to automatically log in on mount:", err);
|
|
16743
16708
|
});
|
|
16744
16709
|
}
|
|
16745
16710
|
}, [account, instance, isMFAPending]);
|
|
16746
16711
|
var login = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16747
|
-
var err_1, camsError;
|
|
16748
|
-
var _a;
|
|
16749
|
-
return __generator(this, function (
|
|
16750
|
-
switch (
|
|
16712
|
+
var loginResponse, tokenResponse, err_1, camsError;
|
|
16713
|
+
var _a, _b, _c;
|
|
16714
|
+
return __generator(this, function (_d) {
|
|
16715
|
+
switch (_d.label) {
|
|
16751
16716
|
case 0:
|
|
16752
16717
|
setError(null);
|
|
16753
|
-
|
|
16718
|
+
_d.label = 1;
|
|
16754
16719
|
case 1:
|
|
16755
|
-
|
|
16720
|
+
_d.trys.push([1, 5, , 6]);
|
|
16756
16721
|
return [4 /*yield*/, instance.loginPopup({
|
|
16757
16722
|
scopes: scopes,
|
|
16758
16723
|
prompt: options.prompt || "select_account",
|
|
16759
16724
|
})];
|
|
16760
16725
|
case 2:
|
|
16761
|
-
|
|
16762
|
-
return [3 /*break*/, 4];
|
|
16726
|
+
loginResponse = _d.sent();
|
|
16727
|
+
if (!loginResponse.account) return [3 /*break*/, 4];
|
|
16728
|
+
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16729
|
+
scopes: scopes,
|
|
16730
|
+
account: loginResponse.account,
|
|
16731
|
+
})];
|
|
16763
16732
|
case 3:
|
|
16764
|
-
|
|
16733
|
+
tokenResponse = _d.sent();
|
|
16734
|
+
if (options.mfaUrl) {
|
|
16735
|
+
setIsMFAPending(true);
|
|
16736
|
+
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken, loginResponse.account);
|
|
16737
|
+
}
|
|
16738
|
+
else {
|
|
16739
|
+
setToken(tokenResponse.accessToken);
|
|
16740
|
+
setProfile({
|
|
16741
|
+
type: "AUTH_SUCCESS",
|
|
16742
|
+
userProfile: {
|
|
16743
|
+
name: loginResponse.account.name || "",
|
|
16744
|
+
email: loginResponse.account.username || "",
|
|
16745
|
+
isAuthenticated: true,
|
|
16746
|
+
mfaIsEnabled: true,
|
|
16747
|
+
message: "Authentication successful",
|
|
16748
|
+
userType: "USER",
|
|
16749
|
+
tokens: {
|
|
16750
|
+
Nonce: "",
|
|
16751
|
+
Bearer: tokenResponse.accessToken,
|
|
16752
|
+
},
|
|
16753
|
+
},
|
|
16754
|
+
});
|
|
16755
|
+
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, tokenResponse.accessToken);
|
|
16756
|
+
}
|
|
16757
|
+
_d.label = 4;
|
|
16758
|
+
case 4: return [3 /*break*/, 6];
|
|
16759
|
+
case 5:
|
|
16760
|
+
err_1 = _d.sent();
|
|
16765
16761
|
camsError = new CAMSError(CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16766
16762
|
setError(camsError);
|
|
16767
|
-
(
|
|
16768
|
-
return [3 /*break*/,
|
|
16769
|
-
case
|
|
16763
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16764
|
+
return [3 /*break*/, 6];
|
|
16765
|
+
case 6: return [2 /*return*/];
|
|
16770
16766
|
}
|
|
16771
16767
|
});
|
|
16772
|
-
}); }, [instance, scopes]);
|
|
16768
|
+
}); }, [instance, scopes, options]);
|
|
16773
16769
|
var logout = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16774
16770
|
var err_2, camsError;
|
|
16775
16771
|
return __generator(this, function (_a) {
|