@asgardeo/react 0.5.16 → 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
@@ -676,31 +676,35 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
676
676
  }
677
677
  }
678
678
  async getDecodedIdToken(sessionId) {
679
- return this.asgardeo.getDecodedIdToken(sessionId);
679
+ return this.withLoading(async () => {
680
+ return this.asgardeo.getDecodedIdToken(sessionId);
681
+ });
680
682
  }
681
683
  async getUserProfile(options) {
682
- try {
683
- let baseUrl = options?.baseUrl;
684
- if (!baseUrl) {
685
- const configData = await this.asgardeo.getConfigData();
686
- 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
+ };
687
706
  }
688
- const profile = await getScim2Me_default({ baseUrl });
689
- const schemas = await getSchemas_default({ baseUrl });
690
- const processedSchemas = (0, import_browser6.flattenUserSchema)(schemas);
691
- const output = {
692
- schemas: processedSchemas,
693
- flattenedProfile: (0, import_browser6.generateFlattenedUserProfile)(profile, processedSchemas),
694
- profile
695
- };
696
- return output;
697
- } catch (error) {
698
- return {
699
- schemas: [],
700
- flattenedProfile: (0, import_browser6.extractUserClaimsFromIdToken)(await this.getDecodedIdToken()),
701
- profile: (0, import_browser6.extractUserClaimsFromIdToken)(await this.getDecodedIdToken())
702
- };
703
- }
707
+ });
704
708
  }
705
709
  async getMyOrganizations(options, sessionId) {
706
710
  try {
@@ -737,12 +741,14 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
737
741
  }
738
742
  }
739
743
  async getCurrentOrganization() {
740
- const idToken = await this.getDecodedIdToken();
741
- return {
742
- orgHandle: idToken?.org_handle,
743
- name: idToken?.org_name,
744
- id: idToken?.org_id
745
- };
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
+ });
746
752
  }
747
753
  async switchOrganization(organization, sessionId) {
748
754
  return this.withLoading(async () => {
@@ -787,8 +793,8 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
787
793
  async isInitialized() {
788
794
  return this.asgardeo.isInitialized();
789
795
  }
790
- isSignedIn() {
791
- return this.asgardeo.isSignedIn();
796
+ async isSignedIn() {
797
+ return await this.asgardeo.isSignedIn();
792
798
  }
793
799
  getConfiguration() {
794
800
  return this.asgardeo.getConfigData();
@@ -850,7 +856,9 @@ var AsgardeoReactClient = class extends import_browser6.AsgardeoBrowserClient {
850
856
  return this.asgardeo.httpRequestAll(requestConfigs);
851
857
  }
852
858
  async getAccessToken(sessionId) {
853
- return this.asgardeo.getAccessToken(sessionId);
859
+ return this.withLoading(async () => {
860
+ return this.asgardeo.getAccessToken(sessionId);
861
+ });
854
862
  }
855
863
  };
856
864
  var AsgardeoReactClient_default = AsgardeoReactClient;
@@ -1514,6 +1522,7 @@ var AsgardeoProvider = ({
1514
1522
  syncSession,
1515
1523
  ...rest
1516
1524
  });
1525
+ const [isUpdatingSession, setIsUpdatingSession] = (0, import_react15.useState)(false);
1517
1526
  const [brandingPreference, setBrandingPreference] = (0, import_react15.useState)(null);
1518
1527
  const [isBrandingLoading, setIsBrandingLoading] = (0, import_react15.useState)(false);
1519
1528
  const [brandingError, setBrandingError] = (0, import_react15.useState)(null);
@@ -1538,11 +1547,14 @@ var AsgardeoProvider = ({
1538
1547
  }
1539
1548
  reRenderCheckRef.current = true;
1540
1549
  (async () => {
1541
- if (await asgardeo.isSignedIn()) {
1550
+ const isAlreadySignedIn = await asgardeo.isSignedIn();
1551
+ if (isAlreadySignedIn) {
1542
1552
  await updateSession();
1543
1553
  return;
1544
1554
  }
1545
- 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) {
1546
1558
  try {
1547
1559
  await signIn(
1548
1560
  { callOnlyOnRedirect: true }
@@ -1554,6 +1566,7 @@ var AsgardeoProvider = ({
1554
1566
  if (error && Object.prototype.hasOwnProperty.call(error, "code")) {
1555
1567
  }
1556
1568
  }
1569
+ } else {
1557
1570
  }
1558
1571
  })();
1559
1572
  }, []);
@@ -1571,6 +1584,7 @@ var AsgardeoProvider = ({
1571
1584
  clearInterval(interval);
1572
1585
  }
1573
1586
  }, 1e3);
1587
+ } else {
1574
1588
  }
1575
1589
  } catch (error) {
1576
1590
  setIsSignedInSync(false);
@@ -1594,28 +1608,40 @@ var AsgardeoProvider = ({
1594
1608
  }, [asgardeo]);
1595
1609
  (0, import_react15.useEffect)(() => {
1596
1610
  const checkLoadingState = () => {
1597
- const loadingState = asgardeo.isLoading();
1598
- setIsLoadingSync(loadingState);
1611
+ if (isUpdatingSession) {
1612
+ return;
1613
+ }
1614
+ setIsLoadingSync(asgardeo.isLoading());
1599
1615
  };
1600
1616
  checkLoadingState();
1601
1617
  const interval = setInterval(checkLoadingState, 100);
1602
1618
  return () => {
1603
1619
  clearInterval(interval);
1604
1620
  };
1605
- }, [asgardeo]);
1621
+ }, [asgardeo, isLoadingSync, isSignedInSync, isUpdatingSession]);
1606
1622
  const updateSession = async () => {
1607
1623
  try {
1624
+ setIsUpdatingSession(true);
1608
1625
  setIsLoadingSync(true);
1609
1626
  let _baseUrl2 = baseUrl;
1610
- if ((await asgardeo.getDecodedIdToken())?.["user_org"]) {
1627
+ const decodedToken = await asgardeo.getDecodedIdToken();
1628
+ if (decodedToken?.["user_org"]) {
1611
1629
  _baseUrl2 = `${(await asgardeo.getConfiguration()).baseUrl}/o`;
1612
1630
  setBaseUrl(_baseUrl2);
1613
1631
  }
1614
- setUser(await asgardeo.getUser({ baseUrl: _baseUrl2 }));
1615
- setUserProfile(await asgardeo.getUserProfile({ baseUrl: _baseUrl2 }));
1616
- setCurrentOrganization(await asgardeo.getCurrentOrganization());
1617
- 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) {
1618
1643
  } finally {
1644
+ setIsUpdatingSession(false);
1619
1645
  setIsLoadingSync(asgardeo.isLoading());
1620
1646
  }
1621
1647
  };
@@ -1665,6 +1691,7 @@ var AsgardeoProvider = ({
1665
1691
  ]);
1666
1692
  const signIn = async (...args) => {
1667
1693
  try {
1694
+ setIsUpdatingSession(true);
1668
1695
  setIsLoadingSync(true);
1669
1696
  const response = await asgardeo.signIn(...args);
1670
1697
  if (await asgardeo.isSignedIn()) {
@@ -1674,11 +1701,13 @@ var AsgardeoProvider = ({
1674
1701
  } catch (error) {
1675
1702
  throw new Error(`Error while signing in: ${error}`);
1676
1703
  } finally {
1704
+ setIsUpdatingSession(false);
1677
1705
  setIsLoadingSync(asgardeo.isLoading());
1678
1706
  }
1679
1707
  };
1680
1708
  const signInSilently = async (options) => {
1681
1709
  try {
1710
+ setIsUpdatingSession(true);
1682
1711
  setIsLoadingSync(true);
1683
1712
  const response = await asgardeo.signInSilently(options);
1684
1713
  if (await asgardeo.isSignedIn()) {
@@ -1693,11 +1722,13 @@ var AsgardeoProvider = ({
1693
1722
  "An error occurred while trying to sign in silently."
1694
1723
  );
1695
1724
  } finally {
1725
+ setIsUpdatingSession(false);
1696
1726
  setIsLoadingSync(asgardeo.isLoading());
1697
1727
  }
1698
1728
  };
1699
1729
  const switchOrganization = async (organization) => {
1700
1730
  try {
1731
+ setIsUpdatingSession(true);
1701
1732
  setIsLoadingSync(true);
1702
1733
  await asgardeo.switchOrganization(organization);
1703
1734
  if (await asgardeo.isSignedIn()) {
@@ -1711,6 +1742,7 @@ var AsgardeoProvider = ({
1711
1742
  "An error occurred while switching to the specified organization."
1712
1743
  );
1713
1744
  } finally {
1745
+ setIsUpdatingSession(false);
1714
1746
  setIsLoadingSync(asgardeo.isLoading());
1715
1747
  }
1716
1748
  };