@nibssplc/cams-sdk-react 0.0.1-beta.37 → 0.0.1-beta.39
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 +51 -12
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +51 -12
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -16756,15 +16756,15 @@ function useCAMSMSALAuth(options) {
|
|
|
16756
16756
|
// const response = await instance.handleRedirectPromise();
|
|
16757
16757
|
// if (response) {
|
|
16758
16758
|
// const account = response.account;
|
|
16759
|
-
// instance.
|
|
16760
|
-
// const tokenResponse = await instance.
|
|
16759
|
+
// instance.setActiveA ccount(account);
|
|
16760
|
+
// const tokenResponse = await instance.acq uireTokenSilent({
|
|
16761
16761
|
// scopes,
|
|
16762
16762
|
// account,
|
|
16763
16763
|
// });
|
|
16764
16764
|
// setToken(tokenResponse.accessToken);
|
|
16765
16765
|
// setAccessToken(tokenResponse.accessToken);
|
|
16766
|
-
// setIdToken(tokenResponse.
|
|
16767
|
-
// options.onAuthSuccess?.(
|
|
16766
|
+
// setIdToken(tokenResponse.idTo ken);
|
|
16767
|
+
// options.onAuthSuccess?.(tokenR esponse.accessToken);
|
|
16768
16768
|
// if (
|
|
16769
16769
|
// typeof window !== "undefined" &&
|
|
16770
16770
|
// process.env.NODE_ENV !== "test"
|
|
@@ -16788,7 +16788,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16788
16788
|
_d.label = 1;
|
|
16789
16789
|
case 1:
|
|
16790
16790
|
_d.trys.push([1, 3, , 4]);
|
|
16791
|
-
// await instance.
|
|
16791
|
+
// await instance.loginR edirect({
|
|
16792
16792
|
// scopes,
|
|
16793
16793
|
// prompt: options.prompt || "login",
|
|
16794
16794
|
// });
|
|
@@ -16821,7 +16821,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16821
16821
|
}
|
|
16822
16822
|
})];
|
|
16823
16823
|
case 2:
|
|
16824
|
-
// await instance.
|
|
16824
|
+
// await instance.loginR edirect({
|
|
16825
16825
|
// scopes,
|
|
16826
16826
|
// prompt: options.prompt || "login",
|
|
16827
16827
|
// });
|
|
@@ -17336,6 +17336,24 @@ function ProtectedRoute(_a) {
|
|
|
17336
17336
|
}
|
|
17337
17337
|
|
|
17338
17338
|
var CAMSMSALContext = React__default.createContext(null);
|
|
17339
|
+
var setCookie = function (name, value, days) {
|
|
17340
|
+
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
17341
|
+
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=strict");
|
|
17342
|
+
};
|
|
17343
|
+
var getCookie = function (name) {
|
|
17344
|
+
var _a;
|
|
17345
|
+
return ((_a = document.cookie
|
|
17346
|
+
.split("; ")
|
|
17347
|
+
.find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
|
|
17348
|
+
? decodeURIComponent(document.cookie
|
|
17349
|
+
.split("; ")
|
|
17350
|
+
.find(function (row) { return row.startsWith(name + "="); })
|
|
17351
|
+
.split("=")[1])
|
|
17352
|
+
: null;
|
|
17353
|
+
};
|
|
17354
|
+
var deleteCookie = function (name) {
|
|
17355
|
+
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
17356
|
+
};
|
|
17339
17357
|
var isTokenValid = function (token) {
|
|
17340
17358
|
try {
|
|
17341
17359
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -17349,12 +17367,25 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17349
17367
|
var _this = this;
|
|
17350
17368
|
var children = _a.children, authOptions = __rest(_a, ["children"]);
|
|
17351
17369
|
var auth = useCAMSMSALAuth(authOptions);
|
|
17352
|
-
var
|
|
17370
|
+
var getInitialProfile = function () {
|
|
17371
|
+
if (typeof window === "undefined") {
|
|
17372
|
+
return null;
|
|
17373
|
+
}
|
|
17374
|
+
try {
|
|
17375
|
+
var storedProfile = localStorage.getItem(profileStorageKey);
|
|
17376
|
+
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
17377
|
+
}
|
|
17378
|
+
catch (_a) {
|
|
17379
|
+
return null;
|
|
17380
|
+
}
|
|
17381
|
+
};
|
|
17382
|
+
var _b = React__default.useState(getInitialProfile), userProfile = _b[0], setUserProfile = _b[1];
|
|
17353
17383
|
var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
|
|
17354
17384
|
// Load profile from storage on mount
|
|
17355
17385
|
React__default.useEffect(function () {
|
|
17356
|
-
if (typeof window !== "undefined"
|
|
17357
|
-
|
|
17386
|
+
if (typeof window !== "undefined") {
|
|
17387
|
+
// const storedProfile = localStorage.get Item(profileStorageKey);
|
|
17388
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
17358
17389
|
if (storedProfile) {
|
|
17359
17390
|
try {
|
|
17360
17391
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -17362,7 +17393,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17362
17393
|
catch (_a) { }
|
|
17363
17394
|
}
|
|
17364
17395
|
}
|
|
17365
|
-
}, [profileStorageKey
|
|
17396
|
+
}, [profileStorageKey]);
|
|
17366
17397
|
// Persist tokens and profile
|
|
17367
17398
|
React__default.useEffect(function () {
|
|
17368
17399
|
if (auth.accessToken &&
|
|
@@ -17377,11 +17408,16 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17377
17408
|
// Persist profile separately
|
|
17378
17409
|
React__default.useEffect(function () {
|
|
17379
17410
|
if (typeof window !== "undefined") {
|
|
17411
|
+
// if (userProfile) {
|
|
17412
|
+
// localStorage.setItem(profileStorageKey, JSO N.stringify(userProfile));
|
|
17413
|
+
// } else {
|
|
17414
|
+
// localStorage.removeItem(profileStorageKey);
|
|
17415
|
+
// }
|
|
17380
17416
|
if (userProfile) {
|
|
17381
|
-
|
|
17417
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
|
|
17382
17418
|
}
|
|
17383
17419
|
else {
|
|
17384
|
-
|
|
17420
|
+
deleteCookie(profileStorageKey);
|
|
17385
17421
|
}
|
|
17386
17422
|
}
|
|
17387
17423
|
}, [userProfile, profileStorageKey]);
|
|
@@ -17393,6 +17429,9 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17393
17429
|
case 1:
|
|
17394
17430
|
_a.sent();
|
|
17395
17431
|
setUserProfile(null);
|
|
17432
|
+
if (typeof window !== "undefined") {
|
|
17433
|
+
deleteCookie(profileStorageKey);
|
|
17434
|
+
}
|
|
17396
17435
|
return [2 /*return*/];
|
|
17397
17436
|
}
|
|
17398
17437
|
});
|