@nibssplc/cams-sdk-react 1.0.0-rc.97 → 1.0.0-rc.99
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/components/MFAOptions.d.ts +1 -1
- package/dist/hooks/useOTPHandler.d.ts +1 -1
- package/dist/index.cjs.js +73 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +73 -62
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ export declare const useOTPHandler: ({ email, appCode, instCode, MFAEndpoint, on
|
|
|
4
4
|
appCode: string;
|
|
5
5
|
instCode?: string;
|
|
6
6
|
MFAEndpoint?: string;
|
|
7
|
-
onAuthComplete: (state: boolean, data: MFAAuthenticatedResponse | null) => void
|
|
7
|
+
onAuthComplete: (state: boolean, data: MFAAuthenticatedResponse | null) => Promise<void>;
|
|
8
8
|
}) => {
|
|
9
9
|
handleSubmitOTP: (authenticationValue: string) => Promise<boolean>;
|
|
10
10
|
loading: boolean;
|
package/dist/index.cjs.js
CHANGED
|
@@ -1432,15 +1432,15 @@ var useOTPHandler = function (_a) {
|
|
|
1432
1432
|
return __generator$1(this, function (_a) {
|
|
1433
1433
|
switch (_a.label) {
|
|
1434
1434
|
case 0:
|
|
1435
|
-
if (isMaxAttemptsReached)
|
|
1436
|
-
|
|
1435
|
+
if (!isMaxAttemptsReached) return [3 /*break*/, 2];
|
|
1436
|
+
return [4 /*yield*/, onAuthComplete(false, {
|
|
1437
1437
|
message: "Maximum attempts reached",
|
|
1438
|
-
});
|
|
1439
|
-
return [2 /*return*/, false];
|
|
1440
|
-
}
|
|
1441
|
-
_a.label = 1;
|
|
1438
|
+
})];
|
|
1442
1439
|
case 1:
|
|
1443
|
-
_a.
|
|
1440
|
+
_a.sent();
|
|
1441
|
+
return [2 /*return*/, false];
|
|
1442
|
+
case 2:
|
|
1443
|
+
_a.trys.push([2, 11, 13, 14]);
|
|
1444
1444
|
setLoading(true);
|
|
1445
1445
|
currentAttempt = attemptCount + 1;
|
|
1446
1446
|
setAttemptCount(currentAttempt);
|
|
@@ -1451,41 +1451,43 @@ var useOTPHandler = function (_a) {
|
|
|
1451
1451
|
email: email,
|
|
1452
1452
|
MFACode: authenticationValue,
|
|
1453
1453
|
}, MFAEndpoint || "")];
|
|
1454
|
-
case 2:
|
|
1455
|
-
response = _a.sent();
|
|
1456
|
-
if (response) {
|
|
1457
|
-
onAuthComplete(true, response);
|
|
1458
|
-
return [2 /*return*/, true];
|
|
1459
|
-
}
|
|
1460
|
-
else {
|
|
1461
|
-
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1462
|
-
setIsMaxAttemptsReached(true);
|
|
1463
|
-
onAuthComplete(false, {
|
|
1464
|
-
message: "Maximum Attempts Reached",
|
|
1465
|
-
});
|
|
1466
|
-
}
|
|
1467
|
-
else {
|
|
1468
|
-
onAuthComplete(false, response);
|
|
1469
|
-
}
|
|
1470
|
-
return [2 /*return*/, false];
|
|
1471
|
-
}
|
|
1472
1454
|
case 3:
|
|
1455
|
+
response = _a.sent();
|
|
1456
|
+
if (!response) return [3 /*break*/, 5];
|
|
1457
|
+
return [4 /*yield*/, onAuthComplete(true, response)];
|
|
1458
|
+
case 4:
|
|
1459
|
+
_a.sent();
|
|
1460
|
+
return [2 /*return*/, true];
|
|
1461
|
+
case 5:
|
|
1462
|
+
if (!(currentAttempt >= MAX_ATTEMPTS)) return [3 /*break*/, 7];
|
|
1463
|
+
setIsMaxAttemptsReached(true);
|
|
1464
|
+
return [4 /*yield*/, onAuthComplete(false, {
|
|
1465
|
+
message: "Maximum Attempts Reached",
|
|
1466
|
+
})];
|
|
1467
|
+
case 6:
|
|
1468
|
+
_a.sent();
|
|
1469
|
+
return [3 /*break*/, 9];
|
|
1470
|
+
case 7: return [4 /*yield*/, onAuthComplete(false, response)];
|
|
1471
|
+
case 8:
|
|
1472
|
+
_a.sent();
|
|
1473
|
+
_a.label = 9;
|
|
1474
|
+
case 9: return [2 /*return*/, false];
|
|
1475
|
+
case 10: return [3 /*break*/, 14];
|
|
1476
|
+
case 11:
|
|
1473
1477
|
error_1 = _a.sent();
|
|
1474
1478
|
console.error(error_1);
|
|
1475
1479
|
currentAttempt = attemptCount + 1;
|
|
1476
1480
|
if (currentAttempt >= MAX_ATTEMPTS) {
|
|
1477
1481
|
setIsMaxAttemptsReached(true);
|
|
1478
|
-
onAuthComplete(false, error_1);
|
|
1479
|
-
}
|
|
1480
|
-
else {
|
|
1481
|
-
onAuthComplete(false, error_1);
|
|
1482
1482
|
}
|
|
1483
|
-
onAuthComplete(false, error_1);
|
|
1483
|
+
return [4 /*yield*/, onAuthComplete(false, error_1)];
|
|
1484
|
+
case 12:
|
|
1485
|
+
_a.sent();
|
|
1484
1486
|
return [2 /*return*/, false];
|
|
1485
|
-
case
|
|
1487
|
+
case 13:
|
|
1486
1488
|
setLoading(false);
|
|
1487
1489
|
return [7 /*endfinally*/];
|
|
1488
|
-
case
|
|
1490
|
+
case 14: return [2 /*return*/];
|
|
1489
1491
|
}
|
|
1490
1492
|
});
|
|
1491
1493
|
}); }; }, [onAuthComplete, MFAEndpoint, attemptCount, isMaxAttemptsReached]);
|
|
@@ -1582,31 +1584,40 @@ var MFAOptions = function (_a) {
|
|
|
1582
1584
|
email: ((_c = (_b = context.user) === null || _b === void 0 ? void 0 : _b.profile) === null || _c === void 0 ? void 0 : _c.email) || context.email,
|
|
1583
1585
|
appCode: context.appCode || "",
|
|
1584
1586
|
MFAEndpoint: MFAEndpoints.ValidateUserMFA,
|
|
1585
|
-
onAuthComplete: function (state, data) {
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1587
|
+
onAuthComplete: function (state, data) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
1588
|
+
return __generator$1(this, function (_a) {
|
|
1589
|
+
switch (_a.label) {
|
|
1590
|
+
case 0:
|
|
1591
|
+
console.log("Completed Auth. Handling MFA", state, data);
|
|
1592
|
+
if (!(state && (data === null || data === void 0 ? void 0 : data.isValid))) return [3 /*break*/, 2];
|
|
1593
|
+
// Call completeMFA to update context state
|
|
1594
|
+
console.log("IN Complete MFA Block. Handling MFA", data);
|
|
1595
|
+
return [4 /*yield*/, (completeMFA === null || completeMFA === void 0 ? void 0 : completeMFA(data).catch(function (error) {
|
|
1596
|
+
console.error("Failed to complete MFA:", error);
|
|
1597
|
+
}))];
|
|
1598
|
+
case 1:
|
|
1599
|
+
_a.sent();
|
|
1600
|
+
sonner.toast.success(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-green-600 bg-green-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldCheck, { className: "w-4 h-4" }), jsxRuntime.jsxs("span", { children: ["Multi-Factor Authentication Successful. ", data === null || data === void 0 ? void 0 : data.message] })] }));
|
|
1601
|
+
setShowSuccessAnimation(true);
|
|
1602
|
+
return [3 /*break*/, 3];
|
|
1603
|
+
case 2:
|
|
1604
|
+
sonner.toast.error(jsxRuntime.jsxs("div", { className: "flex items-center gap-2 text-sm text-red-600 bg-red-50 p-3 rounded-lg", children: [jsxRuntime.jsx(lucideReact.ShieldClose, { className: "w-4 h-4" }), jsxRuntime.jsx("span", { children: (data === null || data === void 0 ? void 0 : data.message) || "Unable to Validate User. Please try again." })] }));
|
|
1605
|
+
if (isMaxAttemptsReached) {
|
|
1606
|
+
setTimeout(function () {
|
|
1607
|
+
logout().then(function () {
|
|
1608
|
+
onAuthFailed === null || onAuthFailed === void 0 ? void 0 : onAuthFailed();
|
|
1609
|
+
onComplete === null || onComplete === void 0 ? void 0 : onComplete(false);
|
|
1610
|
+
});
|
|
1611
|
+
}, 3000);
|
|
1612
|
+
}
|
|
1613
|
+
_a.label = 3;
|
|
1614
|
+
case 3: return [2 /*return*/];
|
|
1606
1615
|
}
|
|
1607
|
-
}
|
|
1608
|
-
},
|
|
1609
|
-
}), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading,
|
|
1616
|
+
});
|
|
1617
|
+
}); },
|
|
1618
|
+
}), handleSubmitOTP = _j.handleSubmitOTP, loading = _j.loading,
|
|
1619
|
+
// setLoading,
|
|
1620
|
+
attemptCount = _j.attemptCount, remainingAttempts = _j.remainingAttempts, isMaxAttemptsReached = _j.isMaxAttemptsReached, resetAttempts = _j.resetAttempts;
|
|
1610
1621
|
var handleGoBack = function () {
|
|
1611
1622
|
setAuthType(null);
|
|
1612
1623
|
setOtpVisible(false);
|
|
@@ -1615,9 +1626,7 @@ var MFAOptions = function (_a) {
|
|
|
1615
1626
|
};
|
|
1616
1627
|
// Show success animation if authentication is successful
|
|
1617
1628
|
if (showSuccessAnimation) {
|
|
1618
|
-
return (jsxRuntime.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntime.jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsxRuntime.jsx(AuthSuccessAnimation, { onComplete: function () {
|
|
1619
|
-
// Animation completed, can add additional logic here if needed
|
|
1620
|
-
} }) }) }));
|
|
1629
|
+
return (jsxRuntime.jsx("div", { className: "flex justify-center items-center h-dvh", children: jsxRuntime.jsx(Card, { className: "mx-auto space-y-6 p-6 bg-white rounded-lg shadow-md", children: jsxRuntime.jsx(AuthSuccessAnimation, { onComplete: function () { return onComplete(true); } }) }) }));
|
|
1621
1630
|
}
|
|
1622
1631
|
var content = jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
1623
1632
|
if (!authType) {
|
|
@@ -1853,14 +1862,16 @@ var MFAGate = function (_a) {
|
|
|
1853
1862
|
var contextAccessToken = "accessToken" in context ? context.accessToken : "";
|
|
1854
1863
|
var handleComplete = React.useCallback(function (success) {
|
|
1855
1864
|
var _a;
|
|
1856
|
-
if (success
|
|
1865
|
+
if (success) {
|
|
1857
1866
|
var accessToken = "accessToken" in context ? context.accessToken : "";
|
|
1858
1867
|
var idToken = "idToken" in context ? context.idToken : "";
|
|
1859
|
-
|
|
1868
|
+
camsSdk.Logger.info("MFA Authentication Successful", { context: context || null });
|
|
1869
|
+
context.isAuthenticated = true;
|
|
1870
|
+
setAuthState("Authenticated");
|
|
1871
|
+
if (context.authMode === "MSAL") {
|
|
1860
1872
|
var tokens = { accessToken: accessToken, idToken: idToken };
|
|
1861
1873
|
onAuthSuccess === null || onAuthSuccess === void 0 ? void 0 : onAuthSuccess(tokens);
|
|
1862
1874
|
if ("onAuthSuccess" in context) {
|
|
1863
|
-
context.isAuthenticated = true;
|
|
1864
1875
|
(_a = context.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(context, tokens);
|
|
1865
1876
|
}
|
|
1866
1877
|
}
|