@saasquatch/component-environment 1.0.2-0 → 1.0.2-1
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.js +20 -1
- package/dist/index.mjs +20 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -534,7 +534,18 @@ function _getInitialValue() {
|
|
|
534
534
|
case "SquatchIOS":
|
|
535
535
|
case "SquatchAndroid":
|
|
536
536
|
case "SquatchJS2":
|
|
537
|
-
|
|
537
|
+
if (!sdk.widgetIdent)
|
|
538
|
+
return void 0;
|
|
539
|
+
const { programId, tenantAlias, userId, accountId, token } = sdk.widgetIdent;
|
|
540
|
+
const storedSquatchUser = localStorage.getItem(`${USER_CONTEXT_NAME}:${tenantAlias}:${programId || "global"}`);
|
|
541
|
+
if (storedSquatchUser) {
|
|
542
|
+
try {
|
|
543
|
+
const potentialUserIdent = JSON.parse(storedSquatchUser);
|
|
544
|
+
return userIdentityFromJwt(potentialUserIdent.jwt);
|
|
545
|
+
} catch (e) {
|
|
546
|
+
return void 0;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
538
549
|
if (!userId || !accountId || !token)
|
|
539
550
|
return void 0;
|
|
540
551
|
return {
|
|
@@ -567,10 +578,18 @@ function _getInitialValue() {
|
|
|
567
578
|
}
|
|
568
579
|
function setUserIdentity(identity) {
|
|
569
580
|
const globalProvider = lazilyStartUserContext();
|
|
581
|
+
const sdk = getEnvironmentSDK();
|
|
582
|
+
const widgetIdent = sdk.type === "SquatchJS2" ? sdk.widgetIdent : void 0;
|
|
583
|
+
console.log({ sdk, widgetIdent });
|
|
570
584
|
if (!(0, import_equality.equal)(globalProvider.context, identity)) {
|
|
571
585
|
debug6(`Setting user context value [${JSON.stringify(identity)}]`);
|
|
572
586
|
globalProvider.context = identity;
|
|
573
587
|
}
|
|
588
|
+
if (identity && widgetIdent) {
|
|
589
|
+
localStorage.setItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`, JSON.stringify(identity));
|
|
590
|
+
} else if (!identity && widgetIdent) {
|
|
591
|
+
localStorage.removeItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`);
|
|
592
|
+
}
|
|
574
593
|
if (identity && getEnvironmentSDK().type === "SquatchPortal") {
|
|
575
594
|
localStorage.setItem(USER_CONTEXT_NAME, JSON.stringify(identity));
|
|
576
595
|
} else if (!identity) {
|
package/dist/index.mjs
CHANGED
|
@@ -485,7 +485,18 @@ function _getInitialValue() {
|
|
|
485
485
|
case "SquatchIOS":
|
|
486
486
|
case "SquatchAndroid":
|
|
487
487
|
case "SquatchJS2":
|
|
488
|
-
|
|
488
|
+
if (!sdk.widgetIdent)
|
|
489
|
+
return void 0;
|
|
490
|
+
const { programId, tenantAlias, userId, accountId, token } = sdk.widgetIdent;
|
|
491
|
+
const storedSquatchUser = localStorage.getItem(`${USER_CONTEXT_NAME}:${tenantAlias}:${programId || "global"}`);
|
|
492
|
+
if (storedSquatchUser) {
|
|
493
|
+
try {
|
|
494
|
+
const potentialUserIdent = JSON.parse(storedSquatchUser);
|
|
495
|
+
return userIdentityFromJwt(potentialUserIdent.jwt);
|
|
496
|
+
} catch (e) {
|
|
497
|
+
return void 0;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
489
500
|
if (!userId || !accountId || !token)
|
|
490
501
|
return void 0;
|
|
491
502
|
return {
|
|
@@ -518,10 +529,18 @@ function _getInitialValue() {
|
|
|
518
529
|
}
|
|
519
530
|
function setUserIdentity(identity) {
|
|
520
531
|
const globalProvider = lazilyStartUserContext();
|
|
532
|
+
const sdk = getEnvironmentSDK();
|
|
533
|
+
const widgetIdent = sdk.type === "SquatchJS2" ? sdk.widgetIdent : void 0;
|
|
534
|
+
console.log({ sdk, widgetIdent });
|
|
521
535
|
if (!equal(globalProvider.context, identity)) {
|
|
522
536
|
debug6(`Setting user context value [${JSON.stringify(identity)}]`);
|
|
523
537
|
globalProvider.context = identity;
|
|
524
538
|
}
|
|
539
|
+
if (identity && widgetIdent) {
|
|
540
|
+
localStorage.setItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`, JSON.stringify(identity));
|
|
541
|
+
} else if (!identity && widgetIdent) {
|
|
542
|
+
localStorage.removeItem(`${USER_CONTEXT_NAME}:${widgetIdent.tenantAlias}:${widgetIdent.programId || "global"}`);
|
|
543
|
+
}
|
|
525
544
|
if (identity && getEnvironmentSDK().type === "SquatchPortal") {
|
|
526
545
|
localStorage.setItem(USER_CONTEXT_NAME, JSON.stringify(identity));
|
|
527
546
|
} else if (!identity) {
|