@nibssplc/cams-sdk-react 0.0.1-beta.38 → 0.0.1-beta.40

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 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.setActiveAccount(account);
16760
- // const tokenResponse = await instance.acquireTokenSilent({
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.idToken);
16767
- // options.onAuthSuccess?.(tokenResponse.accessToken);
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.loginRedirect({
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.loginRedirect({
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), "; httpOnly; expires=").concat(expires, "; path=/; samesite=Lax");
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]));
@@ -17366,7 +17384,8 @@ function CAMSMSALProviderInner(_a) {
17366
17384
  // Load profile from storage on mount
17367
17385
  React__default.useEffect(function () {
17368
17386
  if (typeof window !== "undefined") {
17369
- var storedProfile = localStorage.getItem(profileStorageKey);
17387
+ // const storedProfile = localStorage.get Item(profileStorageKey);
17388
+ var storedProfile = getCookie(profileStorageKey);
17370
17389
  if (storedProfile) {
17371
17390
  try {
17372
17391
  setUserProfile(JSON.parse(storedProfile));
@@ -17389,11 +17408,16 @@ function CAMSMSALProviderInner(_a) {
17389
17408
  // Persist profile separately
17390
17409
  React__default.useEffect(function () {
17391
17410
  if (typeof window !== "undefined") {
17411
+ // if (userProfile) {
17412
+ // localStorage.setItem(profileStorageKey, JSO N.stringify(userProfile));
17413
+ // } else {
17414
+ // localStorage.removeItem(profileStorageKey);
17415
+ // }
17392
17416
  if (userProfile) {
17393
- localStorage.setItem(profileStorageKey, JSON.stringify(userProfile));
17417
+ setCookie(profileStorageKey, JSON.stringify(userProfile), 1); // Store for 1 day
17394
17418
  }
17395
17419
  else {
17396
- localStorage.removeItem(profileStorageKey);
17420
+ deleteCookie(profileStorageKey);
17397
17421
  }
17398
17422
  }
17399
17423
  }, [userProfile, profileStorageKey]);
@@ -17405,6 +17429,9 @@ function CAMSMSALProviderInner(_a) {
17405
17429
  case 1:
17406
17430
  _a.sent();
17407
17431
  setUserProfile(null);
17432
+ if (typeof window !== "undefined") {
17433
+ deleteCookie(profileStorageKey);
17434
+ }
17408
17435
  return [2 /*return*/];
17409
17436
  }
17410
17437
  });