@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.cjs.js
CHANGED
|
@@ -16720,75 +16720,71 @@ function useCAMSMSALAuth(options) {
|
|
|
16720
16720
|
var isAuthenticated = !!account && !!token && !isMFAPending;
|
|
16721
16721
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
16722
16722
|
React__default.useEffect(function () {
|
|
16723
|
-
if (account && !isMFAPending) {
|
|
16724
|
-
|
|
16725
|
-
|
|
16726
|
-
.
|
|
16727
|
-
scopes: scopes,
|
|
16728
|
-
account: account,
|
|
16729
|
-
prompt: options.prompt || "select_account",
|
|
16730
|
-
})
|
|
16731
|
-
.then(function (response) {
|
|
16732
|
-
var _a, _b;
|
|
16733
|
-
if (options.mfaUrl) {
|
|
16734
|
-
setIsMFAPending(true);
|
|
16735
|
-
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
|
|
16736
|
-
}
|
|
16737
|
-
else {
|
|
16738
|
-
setToken(response.accessToken);
|
|
16739
|
-
setProfile({
|
|
16740
|
-
type: "AUTH_SUCCESS",
|
|
16741
|
-
userProfile: {
|
|
16742
|
-
name: account.name || "",
|
|
16743
|
-
email: account.username || "",
|
|
16744
|
-
isAuthenticated: true,
|
|
16745
|
-
mfaIsEnabled: true,
|
|
16746
|
-
message: "Authentication successful",
|
|
16747
|
-
userType: "USER",
|
|
16748
|
-
tokens: {
|
|
16749
|
-
Nonce: "",
|
|
16750
|
-
Bearer: response.accessToken,
|
|
16751
|
-
},
|
|
16752
|
-
},
|
|
16753
|
-
});
|
|
16754
|
-
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
|
|
16755
|
-
}
|
|
16756
|
-
})
|
|
16757
|
-
.catch(function (err) {
|
|
16758
|
-
var _a;
|
|
16759
|
-
var camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Failed to acquire token: " + err);
|
|
16760
|
-
setError(camsError);
|
|
16761
|
-
(_a = options.onAuthError) === null || _a === void 0 ? void 0 : _a.call(options, camsError);
|
|
16723
|
+
if (account && !token && !isMFAPending) {
|
|
16724
|
+
login().catch(function (err) {
|
|
16725
|
+
// Error is already handled in login function
|
|
16726
|
+
console.error("Failed to automatically log in on mount:", err);
|
|
16762
16727
|
});
|
|
16763
16728
|
}
|
|
16764
16729
|
}, [account, instance, isMFAPending]);
|
|
16765
16730
|
var login = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16766
|
-
var err_1, camsError;
|
|
16767
|
-
var _a;
|
|
16768
|
-
return __generator(this, function (
|
|
16769
|
-
switch (
|
|
16731
|
+
var loginResponse, tokenResponse, err_1, camsError;
|
|
16732
|
+
var _a, _b, _c;
|
|
16733
|
+
return __generator(this, function (_d) {
|
|
16734
|
+
switch (_d.label) {
|
|
16770
16735
|
case 0:
|
|
16771
16736
|
setError(null);
|
|
16772
|
-
|
|
16737
|
+
_d.label = 1;
|
|
16773
16738
|
case 1:
|
|
16774
|
-
|
|
16739
|
+
_d.trys.push([1, 5, , 6]);
|
|
16775
16740
|
return [4 /*yield*/, instance.loginPopup({
|
|
16776
16741
|
scopes: scopes,
|
|
16777
16742
|
prompt: options.prompt || "select_account",
|
|
16778
16743
|
})];
|
|
16779
16744
|
case 2:
|
|
16780
|
-
|
|
16781
|
-
return [3 /*break*/, 4];
|
|
16745
|
+
loginResponse = _d.sent();
|
|
16746
|
+
if (!loginResponse.account) return [3 /*break*/, 4];
|
|
16747
|
+
return [4 /*yield*/, instance.acquireTokenPopup({
|
|
16748
|
+
scopes: scopes,
|
|
16749
|
+
account: loginResponse.account,
|
|
16750
|
+
})];
|
|
16782
16751
|
case 3:
|
|
16783
|
-
|
|
16752
|
+
tokenResponse = _d.sent();
|
|
16753
|
+
if (options.mfaUrl) {
|
|
16754
|
+
setIsMFAPending(true);
|
|
16755
|
+
(_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, tokenResponse.accessToken, loginResponse.account);
|
|
16756
|
+
}
|
|
16757
|
+
else {
|
|
16758
|
+
setToken(tokenResponse.accessToken);
|
|
16759
|
+
setProfile({
|
|
16760
|
+
type: "AUTH_SUCCESS",
|
|
16761
|
+
userProfile: {
|
|
16762
|
+
name: loginResponse.account.name || "",
|
|
16763
|
+
email: loginResponse.account.username || "",
|
|
16764
|
+
isAuthenticated: true,
|
|
16765
|
+
mfaIsEnabled: true,
|
|
16766
|
+
message: "Authentication successful",
|
|
16767
|
+
userType: "USER",
|
|
16768
|
+
tokens: {
|
|
16769
|
+
Nonce: "",
|
|
16770
|
+
Bearer: tokenResponse.accessToken,
|
|
16771
|
+
},
|
|
16772
|
+
},
|
|
16773
|
+
});
|
|
16774
|
+
(_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, tokenResponse.accessToken);
|
|
16775
|
+
}
|
|
16776
|
+
_d.label = 4;
|
|
16777
|
+
case 4: return [3 /*break*/, 6];
|
|
16778
|
+
case 5:
|
|
16779
|
+
err_1 = _d.sent();
|
|
16784
16780
|
camsError = new camsSdk.CAMSError(camsSdk.CAMSErrorType.API_VALIDATION_ERROR, "Login failed: " + err_1);
|
|
16785
16781
|
setError(camsError);
|
|
16786
|
-
(
|
|
16787
|
-
return [3 /*break*/,
|
|
16788
|
-
case
|
|
16782
|
+
(_c = options.onAuthError) === null || _c === void 0 ? void 0 : _c.call(options, camsError);
|
|
16783
|
+
return [3 /*break*/, 6];
|
|
16784
|
+
case 6: return [2 /*return*/];
|
|
16789
16785
|
}
|
|
16790
16786
|
});
|
|
16791
|
-
}); }, [instance, scopes]);
|
|
16787
|
+
}); }, [instance, scopes, options]);
|
|
16792
16788
|
var logout = React__default.useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
16793
16789
|
var err_2, camsError;
|
|
16794
16790
|
return __generator(this, function (_a) {
|