@nibssplc/cams-sdk-react 0.0.1-beta.42 → 0.0.1-beta.44
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 +3 -3
- package/dist/index.cjs.js +20 -10
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +20 -10
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,8 +14,8 @@ export interface UseCAMSMSALAuthReturn {
|
|
|
14
14
|
isAuthenticated: boolean;
|
|
15
15
|
isLoading: boolean;
|
|
16
16
|
error: CAMSError | null;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
idToken: string;
|
|
18
|
+
accessToken: string;
|
|
19
|
+
appCode: string;
|
|
20
20
|
}
|
|
21
21
|
export declare function useCAMSMSALAuth(options?: UseCAMSMSALAuthOptions): UseCAMSMSALAuthReturn;
|
package/dist/index.cjs.js
CHANGED
|
@@ -16716,9 +16716,10 @@ function useCAMSMSALAuth(options) {
|
|
|
16716
16716
|
var account = useAccount(accounts[0] || {});
|
|
16717
16717
|
var storageKey = "CAMS-MSAL-AUTH-SDK";
|
|
16718
16718
|
var _b = React__default.useState(null), error = _b[0], setError = _b[1];
|
|
16719
|
-
var _c = React__default.useState(
|
|
16720
|
-
var _d = React__default.useState(
|
|
16721
|
-
var _e = React__default.useState(
|
|
16719
|
+
var _c = React__default.useState(""), token = _c[0], setToken = _c[1];
|
|
16720
|
+
var _d = React__default.useState(""), idToken = _d[0], setIdToken = _d[1];
|
|
16721
|
+
var _e = React__default.useState(""), appCode = _e[0], setAppCode = _e[1];
|
|
16722
|
+
var _f = React__default.useState(""), accessToken = _f[0], setAccessToken = _f[1];
|
|
16722
16723
|
var isLoading = inProgress !== InteractionStatus.None;
|
|
16723
16724
|
var isAuthenticated = !!account && !!token;
|
|
16724
16725
|
var scopes = options.scopes || ["openid", "profile", "email"];
|
|
@@ -16736,11 +16737,12 @@ function useCAMSMSALAuth(options) {
|
|
|
16736
16737
|
var stored = localStorage.getItem(storageKey);
|
|
16737
16738
|
if (stored) {
|
|
16738
16739
|
try {
|
|
16739
|
-
var _a = JSON.parse(stored), accessToken_1 = _a.accessToken, idToken_1 = _a.idToken;
|
|
16740
|
+
var _a = JSON.parse(stored), accessToken_1 = _a.accessToken, idToken_1 = _a.idToken, appCode_1 = _a.appCode;
|
|
16740
16741
|
if (accessToken_1 && isTokenValid(accessToken_1)) {
|
|
16741
16742
|
setToken(accessToken_1);
|
|
16742
16743
|
setAccessToken(accessToken_1);
|
|
16743
16744
|
setIdToken(idToken_1);
|
|
16745
|
+
setAppCode(appCode_1);
|
|
16744
16746
|
}
|
|
16745
16747
|
else {
|
|
16746
16748
|
localStorage.removeItem(storageKey);
|
|
@@ -16814,13 +16816,21 @@ function useCAMSMSALAuth(options) {
|
|
|
16814
16816
|
idToken: response.idToken,
|
|
16815
16817
|
}));
|
|
16816
16818
|
}
|
|
16817
|
-
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16818
16819
|
if (typeof window !== "undefined" &&
|
|
16819
16820
|
process.env.NODE_ENV !== "test") {
|
|
16820
16821
|
// Center the popup window
|
|
16821
16822
|
var left = (window.screen.width - 500) / 2;
|
|
16822
16823
|
var top_1 = (window.screen.height - 600) / 2;
|
|
16823
|
-
window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
|
|
16824
|
+
var authWindow = window.open(options.mfaUrl, "_blank", "width=500,height=600,left=".concat(left, ",top=").concat(top_1, ",scrollbars=yes,resizable=yes"));
|
|
16825
|
+
if (!authWindow) {
|
|
16826
|
+
camsSdk.Logger.error("Popup window blocked");
|
|
16827
|
+
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16828
|
+
}
|
|
16829
|
+
if (authWindow.closed) {
|
|
16830
|
+
camsSdk.Logger.error("Popup immediately closed by blocker");
|
|
16831
|
+
throw new camsSdk.CAMSError(camsSdk.CAMSErrorType.POPUP_BLOCKED, "Popup blocked by browser. Please allow popups and try again.");
|
|
16832
|
+
}
|
|
16833
|
+
(_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken);
|
|
16824
16834
|
}
|
|
16825
16835
|
})];
|
|
16826
16836
|
case 2:
|
|
@@ -16857,9 +16867,9 @@ function useCAMSMSALAuth(options) {
|
|
|
16857
16867
|
return [4 /*yield*/, instance.logoutRedirect()];
|
|
16858
16868
|
case 1:
|
|
16859
16869
|
_a.sent();
|
|
16860
|
-
setToken(
|
|
16861
|
-
setAccessToken(
|
|
16862
|
-
setIdToken(
|
|
16870
|
+
setToken("");
|
|
16871
|
+
setAccessToken("");
|
|
16872
|
+
setIdToken("");
|
|
16863
16873
|
setError(null);
|
|
16864
16874
|
if (typeof window !== "undefined") {
|
|
16865
16875
|
localStorage.removeItem(storageKey);
|
|
@@ -16881,9 +16891,9 @@ function useCAMSMSALAuth(options) {
|
|
|
16881
16891
|
isAuthenticated: isAuthenticated,
|
|
16882
16892
|
isLoading: isLoading,
|
|
16883
16893
|
error: error,
|
|
16884
|
-
token: token,
|
|
16885
16894
|
idToken: idToken,
|
|
16886
16895
|
accessToken: accessToken,
|
|
16896
|
+
appCode: appCode,
|
|
16887
16897
|
};
|
|
16888
16898
|
}
|
|
16889
16899
|
|