@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.esm.js
CHANGED
|
@@ -16737,15 +16737,15 @@ function useCAMSMSALAuth(options) {
|
|
|
16737
16737
|
// const response = await instance.handleRedirectPromise();
|
|
16738
16738
|
// if (response) {
|
|
16739
16739
|
// const account = response.account;
|
|
16740
|
-
// instance.
|
|
16741
|
-
// const tokenResponse = await instance.
|
|
16740
|
+
// instance.setActiveA ccount(account);
|
|
16741
|
+
// const tokenResponse = await instance.acq uireTokenSilent({
|
|
16742
16742
|
// scopes,
|
|
16743
16743
|
// account,
|
|
16744
16744
|
// });
|
|
16745
16745
|
// setToken(tokenResponse.accessToken);
|
|
16746
16746
|
// setAccessToken(tokenResponse.accessToken);
|
|
16747
|
-
// setIdToken(tokenResponse.
|
|
16748
|
-
// options.onAuthSuccess?.(
|
|
16747
|
+
// setIdToken(tokenResponse.idTo ken);
|
|
16748
|
+
// options.onAuthSuccess?.(tokenR esponse.accessToken);
|
|
16749
16749
|
// if (
|
|
16750
16750
|
// typeof window !== "undefined" &&
|
|
16751
16751
|
// process.env.NODE_ENV !== "test"
|
|
@@ -16769,7 +16769,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16769
16769
|
_d.label = 1;
|
|
16770
16770
|
case 1:
|
|
16771
16771
|
_d.trys.push([1, 3, , 4]);
|
|
16772
|
-
// await instance.
|
|
16772
|
+
// await instance.loginR edirect({
|
|
16773
16773
|
// scopes,
|
|
16774
16774
|
// prompt: options.prompt || "login",
|
|
16775
16775
|
// });
|
|
@@ -16802,7 +16802,7 @@ function useCAMSMSALAuth(options) {
|
|
|
16802
16802
|
}
|
|
16803
16803
|
})];
|
|
16804
16804
|
case 2:
|
|
16805
|
-
// await instance.
|
|
16805
|
+
// await instance.loginR edirect({
|
|
16806
16806
|
// scopes,
|
|
16807
16807
|
// prompt: options.prompt || "login",
|
|
16808
16808
|
// });
|
|
@@ -17317,6 +17317,24 @@ function ProtectedRoute(_a) {
|
|
|
17317
17317
|
}
|
|
17318
17318
|
|
|
17319
17319
|
var CAMSMSALContext = createContext(null);
|
|
17320
|
+
var setCookie = function (name, value, days) {
|
|
17321
|
+
var expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
17322
|
+
document.cookie = "".concat(name, "=").concat(encodeURIComponent(value), "; expires=").concat(expires, "; path=/; samesite=strict");
|
|
17323
|
+
};
|
|
17324
|
+
var getCookie = function (name) {
|
|
17325
|
+
var _a;
|
|
17326
|
+
return ((_a = document.cookie
|
|
17327
|
+
.split("; ")
|
|
17328
|
+
.find(function (row) { return row.startsWith(name + "="); })) === null || _a === void 0 ? void 0 : _a.split("=")[1])
|
|
17329
|
+
? decodeURIComponent(document.cookie
|
|
17330
|
+
.split("; ")
|
|
17331
|
+
.find(function (row) { return row.startsWith(name + "="); })
|
|
17332
|
+
.split("=")[1])
|
|
17333
|
+
: null;
|
|
17334
|
+
};
|
|
17335
|
+
var deleteCookie = function (name) {
|
|
17336
|
+
document.cookie = name + "=; Max-Age=-99999999; path=/";
|
|
17337
|
+
};
|
|
17320
17338
|
var isTokenValid = function (token) {
|
|
17321
17339
|
try {
|
|
17322
17340
|
var payload = JSON.parse(atob(token.split(".")[1]));
|
|
@@ -17330,12 +17348,25 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17330
17348
|
var _this = this;
|
|
17331
17349
|
var children = _a.children, authOptions = __rest(_a, ["children"]);
|
|
17332
17350
|
var auth = useCAMSMSALAuth(authOptions);
|
|
17333
|
-
var
|
|
17351
|
+
var getInitialProfile = function () {
|
|
17352
|
+
if (typeof window === "undefined") {
|
|
17353
|
+
return null;
|
|
17354
|
+
}
|
|
17355
|
+
try {
|
|
17356
|
+
var storedProfile = localStorage.getItem(profileStorageKey);
|
|
17357
|
+
return storedProfile ? JSON.parse(storedProfile) : null;
|
|
17358
|
+
}
|
|
17359
|
+
catch (_a) {
|
|
17360
|
+
return null;
|
|
17361
|
+
}
|
|
17362
|
+
};
|
|
17363
|
+
var _b = useState(getInitialProfile), userProfile = _b[0], setUserProfile = _b[1];
|
|
17334
17364
|
var profileStorageKey = "".concat(auth.storageKey, "-PROFILE");
|
|
17335
17365
|
// Load profile from storage on mount
|
|
17336
17366
|
useEffect(function () {
|
|
17337
|
-
if (typeof window !== "undefined"
|
|
17338
|
-
|
|
17367
|
+
if (typeof window !== "undefined") {
|
|
17368
|
+
// const storedProfile = localStorage.get Item(profileStorageKey);
|
|
17369
|
+
var storedProfile = getCookie(profileStorageKey);
|
|
17339
17370
|
if (storedProfile) {
|
|
17340
17371
|
try {
|
|
17341
17372
|
setUserProfile(JSON.parse(storedProfile));
|
|
@@ -17343,7 +17374,7 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17343
17374
|
catch (_a) { }
|
|
17344
17375
|
}
|
|
17345
17376
|
}
|
|
17346
|
-
}, [profileStorageKey
|
|
17377
|
+
}, [profileStorageKey]);
|
|
17347
17378
|
// Persist tokens and profile
|
|
17348
17379
|
useEffect(function () {
|
|
17349
17380
|
if (auth.accessToken &&
|
|
@@ -17358,11 +17389,16 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17358
17389
|
// Persist profile separately
|
|
17359
17390
|
useEffect(function () {
|
|
17360
17391
|
if (typeof window !== "undefined") {
|
|
17392
|
+
// if (userProfile) {
|
|
17393
|
+
// localStorage.setItem(profileStorageKey, JSO N.stringify(userProfile));
|
|
17394
|
+
// } else {
|
|
17395
|
+
// localStorage.removeItem(profileStorageKey);
|
|
17396
|
+
// }
|
|
17361
17397
|
if (userProfile) {
|
|
17362
|
-
|
|
17398
|
+
setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
|
|
17363
17399
|
}
|
|
17364
17400
|
else {
|
|
17365
|
-
|
|
17401
|
+
deleteCookie(profileStorageKey);
|
|
17366
17402
|
}
|
|
17367
17403
|
}
|
|
17368
17404
|
}, [userProfile, profileStorageKey]);
|
|
@@ -17374,6 +17410,9 @@ function CAMSMSALProviderInner(_a) {
|
|
|
17374
17410
|
case 1:
|
|
17375
17411
|
_a.sent();
|
|
17376
17412
|
setUserProfile(null);
|
|
17413
|
+
if (typeof window !== "undefined") {
|
|
17414
|
+
deleteCookie(profileStorageKey);
|
|
17415
|
+
}
|
|
17377
17416
|
return [2 /*return*/];
|
|
17378
17417
|
}
|
|
17379
17418
|
});
|