@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/index.js CHANGED
@@ -556,31 +556,35 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
556
556
  }
557
557
  }
558
558
  async getDecodedIdToken(sessionId) {
559
- return this.asgardeo.getDecodedIdToken(sessionId);
559
+ return this.withLoading(async () => {
560
+ return this.asgardeo.getDecodedIdToken(sessionId);
561
+ });
560
562
  }
561
563
  async getUserProfile(options) {
562
- try {
563
- let baseUrl = options?.baseUrl;
564
- if (!baseUrl) {
565
- const configData = await this.asgardeo.getConfigData();
566
- baseUrl = configData?.baseUrl;
564
+ return this.withLoading(async () => {
565
+ try {
566
+ let baseUrl = options?.baseUrl;
567
+ if (!baseUrl) {
568
+ const configData = await this.asgardeo.getConfigData();
569
+ baseUrl = configData?.baseUrl;
570
+ }
571
+ const profile = await getScim2Me_default({ baseUrl });
572
+ const schemas = await getSchemas_default({ baseUrl });
573
+ const processedSchemas = flattenUserSchema(schemas);
574
+ const output = {
575
+ schemas: processedSchemas,
576
+ flattenedProfile: generateFlattenedUserProfile(profile, processedSchemas),
577
+ profile
578
+ };
579
+ return output;
580
+ } catch (error) {
581
+ return {
582
+ schemas: [],
583
+ flattenedProfile: extractUserClaimsFromIdToken(await this.getDecodedIdToken()),
584
+ profile: extractUserClaimsFromIdToken(await this.getDecodedIdToken())
585
+ };
567
586
  }
568
- const profile = await getScim2Me_default({ baseUrl });
569
- const schemas = await getSchemas_default({ baseUrl });
570
- const processedSchemas = flattenUserSchema(schemas);
571
- const output = {
572
- schemas: processedSchemas,
573
- flattenedProfile: generateFlattenedUserProfile(profile, processedSchemas),
574
- profile
575
- };
576
- return output;
577
- } catch (error) {
578
- return {
579
- schemas: [],
580
- flattenedProfile: extractUserClaimsFromIdToken(await this.getDecodedIdToken()),
581
- profile: extractUserClaimsFromIdToken(await this.getDecodedIdToken())
582
- };
583
- }
587
+ });
584
588
  }
585
589
  async getMyOrganizations(options, sessionId) {
586
590
  try {
@@ -617,12 +621,14 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
617
621
  }
618
622
  }
619
623
  async getCurrentOrganization() {
620
- const idToken = await this.getDecodedIdToken();
621
- return {
622
- orgHandle: idToken?.org_handle,
623
- name: idToken?.org_name,
624
- id: idToken?.org_id
625
- };
624
+ return this.withLoading(async () => {
625
+ const idToken = await this.getDecodedIdToken();
626
+ return {
627
+ orgHandle: idToken?.org_handle,
628
+ name: idToken?.org_name,
629
+ id: idToken?.org_id
630
+ };
631
+ });
626
632
  }
627
633
  async switchOrganization(organization, sessionId) {
628
634
  return this.withLoading(async () => {
@@ -667,8 +673,8 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
667
673
  async isInitialized() {
668
674
  return this.asgardeo.isInitialized();
669
675
  }
670
- isSignedIn() {
671
- return this.asgardeo.isSignedIn();
676
+ async isSignedIn() {
677
+ return await this.asgardeo.isSignedIn();
672
678
  }
673
679
  getConfiguration() {
674
680
  return this.asgardeo.getConfigData();
@@ -730,7 +736,9 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
730
736
  return this.asgardeo.httpRequestAll(requestConfigs);
731
737
  }
732
738
  async getAccessToken(sessionId) {
733
- return this.asgardeo.getAccessToken(sessionId);
739
+ return this.withLoading(async () => {
740
+ return this.asgardeo.getAccessToken(sessionId);
741
+ });
734
742
  }
735
743
  };
736
744
  var AsgardeoReactClient_default = AsgardeoReactClient;
@@ -1401,6 +1409,7 @@ var AsgardeoProvider = ({
1401
1409
  syncSession,
1402
1410
  ...rest
1403
1411
  });
1412
+ const [isUpdatingSession, setIsUpdatingSession] = useState7(false);
1404
1413
  const [brandingPreference, setBrandingPreference] = useState7(null);
1405
1414
  const [isBrandingLoading, setIsBrandingLoading] = useState7(false);
1406
1415
  const [brandingError, setBrandingError] = useState7(null);
@@ -1425,11 +1434,14 @@ var AsgardeoProvider = ({
1425
1434
  }
1426
1435
  reRenderCheckRef.current = true;
1427
1436
  (async () => {
1428
- if (await asgardeo.isSignedIn()) {
1437
+ const isAlreadySignedIn = await asgardeo.isSignedIn();
1438
+ if (isAlreadySignedIn) {
1429
1439
  await updateSession();
1430
1440
  return;
1431
1441
  }
1432
- if (hasAuthParams(new URL(window.location.href), afterSignInUrl)) {
1442
+ const currentUrl = new URL(window.location.href);
1443
+ const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl);
1444
+ if (hasAuthParamsResult) {
1433
1445
  try {
1434
1446
  await signIn(
1435
1447
  { callOnlyOnRedirect: true }
@@ -1441,6 +1453,7 @@ var AsgardeoProvider = ({
1441
1453
  if (error && Object.prototype.hasOwnProperty.call(error, "code")) {
1442
1454
  }
1443
1455
  }
1456
+ } else {
1444
1457
  }
1445
1458
  })();
1446
1459
  }, []);
@@ -1458,6 +1471,7 @@ var AsgardeoProvider = ({
1458
1471
  clearInterval(interval);
1459
1472
  }
1460
1473
  }, 1e3);
1474
+ } else {
1461
1475
  }
1462
1476
  } catch (error) {
1463
1477
  setIsSignedInSync(false);
@@ -1481,28 +1495,40 @@ var AsgardeoProvider = ({
1481
1495
  }, [asgardeo]);
1482
1496
  useEffect5(() => {
1483
1497
  const checkLoadingState = () => {
1484
- const loadingState = asgardeo.isLoading();
1485
- setIsLoadingSync(loadingState);
1498
+ if (isUpdatingSession) {
1499
+ return;
1500
+ }
1501
+ setIsLoadingSync(asgardeo.isLoading());
1486
1502
  };
1487
1503
  checkLoadingState();
1488
1504
  const interval = setInterval(checkLoadingState, 100);
1489
1505
  return () => {
1490
1506
  clearInterval(interval);
1491
1507
  };
1492
- }, [asgardeo]);
1508
+ }, [asgardeo, isLoadingSync, isSignedInSync, isUpdatingSession]);
1493
1509
  const updateSession = async () => {
1494
1510
  try {
1511
+ setIsUpdatingSession(true);
1495
1512
  setIsLoadingSync(true);
1496
1513
  let _baseUrl2 = baseUrl;
1497
- if ((await asgardeo.getDecodedIdToken())?.["user_org"]) {
1514
+ const decodedToken = await asgardeo.getDecodedIdToken();
1515
+ if (decodedToken?.["user_org"]) {
1498
1516
  _baseUrl2 = `${(await asgardeo.getConfiguration()).baseUrl}/o`;
1499
1517
  setBaseUrl(_baseUrl2);
1500
1518
  }
1501
- setUser(await asgardeo.getUser({ baseUrl: _baseUrl2 }));
1502
- setUserProfile(await asgardeo.getUserProfile({ baseUrl: _baseUrl2 }));
1503
- setCurrentOrganization(await asgardeo.getCurrentOrganization());
1504
- setMyOrganizations(await asgardeo.getMyOrganizations());
1519
+ const user2 = await asgardeo.getUser({ baseUrl: _baseUrl2 });
1520
+ const userProfile2 = await asgardeo.getUserProfile({ baseUrl: _baseUrl2 });
1521
+ const currentOrganization2 = await asgardeo.getCurrentOrganization();
1522
+ const myOrganizations2 = await asgardeo.getMyOrganizations();
1523
+ setUser(user2);
1524
+ setUserProfile(userProfile2);
1525
+ setCurrentOrganization(currentOrganization2);
1526
+ setMyOrganizations(myOrganizations2);
1527
+ const currentSignInStatus = await asgardeo.isSignedIn();
1528
+ setIsSignedInSync(await asgardeo.isSignedIn());
1529
+ } catch (error) {
1505
1530
  } finally {
1531
+ setIsUpdatingSession(false);
1506
1532
  setIsLoadingSync(asgardeo.isLoading());
1507
1533
  }
1508
1534
  };
@@ -1552,6 +1578,7 @@ var AsgardeoProvider = ({
1552
1578
  ]);
1553
1579
  const signIn = async (...args) => {
1554
1580
  try {
1581
+ setIsUpdatingSession(true);
1555
1582
  setIsLoadingSync(true);
1556
1583
  const response = await asgardeo.signIn(...args);
1557
1584
  if (await asgardeo.isSignedIn()) {
@@ -1561,11 +1588,13 @@ var AsgardeoProvider = ({
1561
1588
  } catch (error) {
1562
1589
  throw new Error(`Error while signing in: ${error}`);
1563
1590
  } finally {
1591
+ setIsUpdatingSession(false);
1564
1592
  setIsLoadingSync(asgardeo.isLoading());
1565
1593
  }
1566
1594
  };
1567
1595
  const signInSilently = async (options) => {
1568
1596
  try {
1597
+ setIsUpdatingSession(true);
1569
1598
  setIsLoadingSync(true);
1570
1599
  const response = await asgardeo.signInSilently(options);
1571
1600
  if (await asgardeo.isSignedIn()) {
@@ -1580,11 +1609,13 @@ var AsgardeoProvider = ({
1580
1609
  "An error occurred while trying to sign in silently."
1581
1610
  );
1582
1611
  } finally {
1612
+ setIsUpdatingSession(false);
1583
1613
  setIsLoadingSync(asgardeo.isLoading());
1584
1614
  }
1585
1615
  };
1586
1616
  const switchOrganization = async (organization) => {
1587
1617
  try {
1618
+ setIsUpdatingSession(true);
1588
1619
  setIsLoadingSync(true);
1589
1620
  await asgardeo.switchOrganization(organization);
1590
1621
  if (await asgardeo.isSignedIn()) {
@@ -1598,6 +1629,7 @@ var AsgardeoProvider = ({
1598
1629
  "An error occurred while switching to the specified organization."
1599
1630
  );
1600
1631
  } finally {
1632
+ setIsUpdatingSession(false);
1601
1633
  setIsLoadingSync(asgardeo.isLoading());
1602
1634
  }
1603
1635
  };