@asgardeo/react 0.5.16 → 0.5.18

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