@asgardeo/react 0.5.15 → 0.5.17

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/cjs/index.js CHANGED
@@ -177,7 +177,8 @@ var AsgardeoContext = (0, import_react.createContext)({
177
177
  request: () => null,
178
178
  requestAll: () => null
179
179
  },
180
- signInOptions: {}
180
+ signInOptions: {},
181
+ getDecodedIdToken: null
181
182
  });
182
183
  AsgardeoContext.displayName = "AsgardeoContext";
183
184
  var AsgardeoContext_default = AsgardeoContext;
@@ -675,31 +676,35 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
675
676
  }
676
677
  }
677
678
  async getDecodedIdToken(sessionId) {
678
- return this.asgardeo.getDecodedIdToken(sessionId);
679
+ return this.withLoading(async () => {
680
+ return this.asgardeo.getDecodedIdToken(sessionId);
681
+ });
679
682
  }
680
683
  async getUserProfile(options) {
681
- try {
682
- let baseUrl = options?.baseUrl;
683
- if (!baseUrl) {
684
- const configData = await this.asgardeo.getConfigData();
685
- baseUrl = configData?.baseUrl;
684
+ return this.withLoading(async () => {
685
+ try {
686
+ let baseUrl = options?.baseUrl;
687
+ if (!baseUrl) {
688
+ const configData = await this.asgardeo.getConfigData();
689
+ baseUrl = configData?.baseUrl;
690
+ }
691
+ const profile = await getScim2Me_default({ baseUrl });
692
+ const schemas = await getSchemas_default({ baseUrl });
693
+ const processedSchemas = (0, import_browser6.flattenUserSchema)(schemas);
694
+ const output = {
695
+ schemas: processedSchemas,
696
+ flattenedProfile: (0, import_browser6.generateFlattenedUserProfile)(profile, processedSchemas),
697
+ profile
698
+ };
699
+ return output;
700
+ } catch (error) {
701
+ return {
702
+ schemas: [],
703
+ flattenedProfile: (0, import_browser6.extractUserClaimsFromIdToken)(await this.getDecodedIdToken()),
704
+ profile: (0, import_browser6.extractUserClaimsFromIdToken)(await this.getDecodedIdToken())
705
+ };
686
706
  }
687
- const profile = await getScim2Me_default({ baseUrl });
688
- const schemas = await getSchemas_default({ baseUrl });
689
- const processedSchemas = (0, import_browser6.flattenUserSchema)(schemas);
690
- const output = {
691
- schemas: processedSchemas,
692
- flattenedProfile: (0, import_browser6.generateFlattenedUserProfile)(profile, processedSchemas),
693
- profile
694
- };
695
- return output;
696
- } catch (error) {
697
- return {
698
- schemas: [],
699
- flattenedProfile: (0, import_browser6.extractUserClaimsFromIdToken)(await this.getDecodedIdToken()),
700
- profile: (0, import_browser6.extractUserClaimsFromIdToken)(await this.getDecodedIdToken())
701
- };
702
- }
707
+ });
703
708
  }
704
709
  async getMyOrganizations(options, sessionId) {
705
710
  try {
@@ -736,12 +741,14 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
736
741
  }
737
742
  }
738
743
  async getCurrentOrganization() {
739
- const idToken = await this.getDecodedIdToken();
740
- return {
741
- orgHandle: idToken?.org_handle,
742
- name: idToken?.org_name,
743
- id: idToken?.org_id
744
- };
744
+ return this.withLoading(async () => {
745
+ const idToken = await this.getDecodedIdToken();
746
+ return {
747
+ orgHandle: idToken?.org_handle,
748
+ name: idToken?.org_name,
749
+ id: idToken?.org_id
750
+ };
751
+ });
745
752
  }
746
753
  async switchOrganization(organization, sessionId) {
747
754
  return this.withLoading(async () => {
@@ -786,8 +793,8 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
786
793
  async isInitialized() {
787
794
  return this.asgardeo.isInitialized();
788
795
  }
789
- isSignedIn() {
790
- return this.asgardeo.isSignedIn();
796
+ async isSignedIn() {
797
+ return await this.asgardeo.isSignedIn();
791
798
  }
792
799
  getConfiguration() {
793
800
  return this.asgardeo.getConfigData();
@@ -849,7 +856,9 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
849
856
  return this.asgardeo.httpRequestAll(requestConfigs);
850
857
  }
851
858
  async getAccessToken(sessionId) {
852
- return this.asgardeo.getAccessToken(sessionId);
859
+ return this.withLoading(async () => {
860
+ return this.asgardeo.getAccessToken(sessionId);
861
+ });
853
862
  }
854
863
  };
855
864
  var AsgardeoReactClient_default = AsgardeoReactClient;
@@ -1485,6 +1494,7 @@ var AsgardeoProvider = ({
1485
1494
  organizationHandle,
1486
1495
  applicationId,
1487
1496
  signInOptions,
1497
+ syncSession,
1488
1498
  ...rest
1489
1499
  }) => {
1490
1500
  const reRenderCheckRef = (0, import_react15.useRef)(false);
@@ -1509,8 +1519,10 @@ var AsgardeoProvider = ({
1509
1519
  signUpUrl,
1510
1520
  signInUrl,
1511
1521
  signInOptions,
1522
+ syncSession,
1512
1523
  ...rest
1513
1524
  });
1525
+ const [isUpdatingSession, setIsUpdatingSession] = (0, import_react15.useState)(false);
1514
1526
  const [brandingPreference, setBrandingPreference] = (0, import_react15.useState)(null);
1515
1527
  const [isBrandingLoading, setIsBrandingLoading] = (0, import_react15.useState)(false);
1516
1528
  const [brandingError, setBrandingError] = (0, import_react15.useState)(null);
@@ -1535,11 +1547,14 @@ var AsgardeoProvider = ({
1535
1547
  }
1536
1548
  reRenderCheckRef.current = true;
1537
1549
  (async () => {
1538
- if (await asgardeo.isSignedIn()) {
1550
+ const isAlreadySignedIn = await asgardeo.isSignedIn();
1551
+ if (isAlreadySignedIn) {
1539
1552
  await updateSession();
1540
1553
  return;
1541
1554
  }
1542
- if (hasAuthParams(new URL(window.location.href), afterSignInUrl)) {
1555
+ const currentUrl = new URL(window.location.href);
1556
+ const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl);
1557
+ if (hasAuthParamsResult) {
1543
1558
  try {
1544
1559
  await signIn(
1545
1560
  { callOnlyOnRedirect: true }
@@ -1551,6 +1566,7 @@ var AsgardeoProvider = ({
1551
1566
  if (error && Object.prototype.hasOwnProperty.call(error, "code")) {
1552
1567
  }
1553
1568
  }
1569
+ } else {
1554
1570
  }
1555
1571
  })();
1556
1572
  }, []);
@@ -1568,6 +1584,7 @@ var AsgardeoProvider = ({
1568
1584
  clearInterval(interval);
1569
1585
  }
1570
1586
  }, 1e3);
1587
+ } else {
1571
1588
  }
1572
1589
  } catch (error) {
1573
1590
  setIsSignedInSync(false);
@@ -1591,28 +1608,40 @@ var AsgardeoProvider = ({
1591
1608
  }, [asgardeo]);
1592
1609
  (0, import_react15.useEffect)(() => {
1593
1610
  const checkLoadingState = () => {
1594
- const loadingState = asgardeo.isLoading();
1595
- setIsLoadingSync(loadingState);
1611
+ if (isUpdatingSession) {
1612
+ return;
1613
+ }
1614
+ setIsLoadingSync(asgardeo.isLoading());
1596
1615
  };
1597
1616
  checkLoadingState();
1598
1617
  const interval = setInterval(checkLoadingState, 100);
1599
1618
  return () => {
1600
1619
  clearInterval(interval);
1601
1620
  };
1602
- }, [asgardeo]);
1621
+ }, [asgardeo, isLoadingSync, isSignedInSync, isUpdatingSession]);
1603
1622
  const updateSession = async () => {
1604
1623
  try {
1624
+ setIsUpdatingSession(true);
1605
1625
  setIsLoadingSync(true);
1606
1626
  let _baseUrl2 = baseUrl;
1607
- if ((await asgardeo.getDecodedIdToken())?.["user_org"]) {
1627
+ const decodedToken = await asgardeo.getDecodedIdToken();
1628
+ if (decodedToken?.["user_org"]) {
1608
1629
  _baseUrl2 = `${(await asgardeo.getConfiguration()).baseUrl}/o`;
1609
1630
  setBaseUrl(_baseUrl2);
1610
1631
  }
1611
- setUser(await asgardeo.getUser({ baseUrl: _baseUrl2 }));
1612
- setUserProfile(await asgardeo.getUserProfile({ baseUrl: _baseUrl2 }));
1613
- setCurrentOrganization(await asgardeo.getCurrentOrganization());
1614
- setMyOrganizations(await asgardeo.getMyOrganizations());
1632
+ const user2 = await asgardeo.getUser({ baseUrl: _baseUrl2 });
1633
+ const userProfile2 = await asgardeo.getUserProfile({ baseUrl: _baseUrl2 });
1634
+ const currentOrganization2 = await asgardeo.getCurrentOrganization();
1635
+ const myOrganizations2 = await asgardeo.getMyOrganizations();
1636
+ setUser(user2);
1637
+ setUserProfile(userProfile2);
1638
+ setCurrentOrganization(currentOrganization2);
1639
+ setMyOrganizations(myOrganizations2);
1640
+ const currentSignInStatus = await asgardeo.isSignedIn();
1641
+ setIsSignedInSync(await asgardeo.isSignedIn());
1642
+ } catch (error) {
1615
1643
  } finally {
1644
+ setIsUpdatingSession(false);
1616
1645
  setIsLoadingSync(asgardeo.isLoading());
1617
1646
  }
1618
1647
  };
@@ -1662,6 +1691,7 @@ var AsgardeoProvider = ({
1662
1691
  ]);
1663
1692
  const signIn = async (...args) => {
1664
1693
  try {
1694
+ setIsUpdatingSession(true);
1665
1695
  setIsLoadingSync(true);
1666
1696
  const response = await asgardeo.signIn(...args);
1667
1697
  if (await asgardeo.isSignedIn()) {
@@ -1671,11 +1701,13 @@ var AsgardeoProvider = ({
1671
1701
  } catch (error) {
1672
1702
  throw new Error(`Error while signing in: ${error}`);
1673
1703
  } finally {
1704
+ setIsUpdatingSession(false);
1674
1705
  setIsLoadingSync(asgardeo.isLoading());
1675
1706
  }
1676
1707
  };
1677
1708
  const signInSilently = async (options) => {
1678
1709
  try {
1710
+ setIsUpdatingSession(true);
1679
1711
  setIsLoadingSync(true);
1680
1712
  const response = await asgardeo.signInSilently(options);
1681
1713
  if (await asgardeo.isSignedIn()) {
@@ -1690,11 +1722,13 @@ var AsgardeoProvider = ({
1690
1722
  "An error occurred while trying to sign in silently."
1691
1723
  );
1692
1724
  } finally {
1725
+ setIsUpdatingSession(false);
1693
1726
  setIsLoadingSync(asgardeo.isLoading());
1694
1727
  }
1695
1728
  };
1696
1729
  const switchOrganization = async (organization) => {
1697
1730
  try {
1731
+ setIsUpdatingSession(true);
1698
1732
  setIsLoadingSync(true);
1699
1733
  await asgardeo.switchOrganization(organization);
1700
1734
  if (await asgardeo.isSignedIn()) {
@@ -1708,6 +1742,7 @@ var AsgardeoProvider = ({
1708
1742
  "An error occurred while switching to the specified organization."
1709
1743
  );
1710
1744
  } finally {
1745
+ setIsUpdatingSession(false);
1711
1746
  setIsLoadingSync(asgardeo.isLoading());
1712
1747
  }
1713
1748
  };
@@ -1747,7 +1782,9 @@ var AsgardeoProvider = ({
1747
1782
  request: asgardeo.request.bind(asgardeo),
1748
1783
  requestAll: asgardeo.requestAll.bind(asgardeo)
1749
1784
  },
1750
- signInOptions
1785
+ signInOptions,
1786
+ getDecodedIdToken: asgardeo.getDecodedIdToken.bind(asgardeo),
1787
+ syncSession
1751
1788
  }),
1752
1789
  [
1753
1790
  applicationId,
@@ -1764,7 +1801,8 @@ var AsgardeoProvider = ({
1764
1801
  signInSilently,
1765
1802
  user,
1766
1803
  asgardeo,
1767
- signInOptions
1804
+ signInOptions,
1805
+ syncSession
1768
1806
  ]
1769
1807
  );
1770
1808
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AsgardeoContext_default.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(I18nProvider_default, { preferences: preferences?.i18n, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(