@asgardeo/react 0.20.1 → 0.21.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com).
2
+ * Copyright (c) 2025-2026, WSO2 LLC. (https://www.wso2.com).
3
3
  *
4
4
  * WSO2 LLC. licenses this file to you under the Apache License,
5
5
  * Version 2.0 (the "License"); you may not use this file except
package/dist/index.js CHANGED
@@ -9,7 +9,8 @@ import {
9
9
  getBrandingPreference,
10
10
  getActiveTheme,
11
11
  Platform as Platform4,
12
- extractUserClaimsFromIdToken as extractUserClaimsFromIdToken2
12
+ extractUserClaimsFromIdToken as extractUserClaimsFromIdToken2,
13
+ createPackageComponentLogger as createPackageComponentLogger3
13
14
  } from "@asgardeo/browser";
14
15
  import { useEffect as useEffect6, useMemo as useMemo7, useRef as useRef2, useState as useState8, useCallback as useCallback8 } from "react";
15
16
 
@@ -283,7 +284,7 @@ var _AuthAPI = class _AuthAPI {
283
284
  /**
284
285
  * This methods returns the Axios http client.
285
286
  *
286
- * @return {HttpClientInstance} - The Axios HTTP client.
287
+ * @return {HttpClient} - The Axios HTTP client.
287
288
  */
288
289
  async getHttpClient() {
289
290
  return this.client.getHttpClient();
@@ -361,6 +362,9 @@ var _AuthAPI = class _AuthAPI {
361
362
  async isSignedIn() {
362
363
  return this.client.isSignedIn();
363
364
  }
365
+ async startAutoRefreshToken() {
366
+ return this.client.startAutoRefreshToken();
367
+ }
364
368
  /**
365
369
  * This method specifies if the session is active or not.
366
370
  *
@@ -616,7 +620,11 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
616
620
  resolvedOrganizationHandle = deriveOrganizationHandleFromBaseUrl(config?.baseUrl);
617
621
  }
618
622
  return this.withLoading(async () => {
619
- this.initializeConfig = { ...config, organizationHandle: resolvedOrganizationHandle };
623
+ this.initializeConfig = {
624
+ ...config,
625
+ organizationHandle: resolvedOrganizationHandle,
626
+ periodicTokenRefresh: config?.tokenLifecycle?.refreshToken?.autoRefresh ?? config?.periodicTokenRefresh
627
+ };
620
628
  return this.asgardeo.init(this.initializeConfig);
621
629
  });
622
630
  }
@@ -787,6 +795,9 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
787
795
  async isSignedIn() {
788
796
  return this.asgardeo.isSignedIn();
789
797
  }
798
+ async startAutoRefreshToken() {
799
+ return this.asgardeo.startAutoRefreshToken();
800
+ }
790
801
  getConfiguration() {
791
802
  return this.asgardeo.getConfigData();
792
803
  }
@@ -1997,6 +2008,10 @@ var UserProvider_default = UserProvider;
1997
2008
 
1998
2009
  // src/contexts/Asgardeo/AsgardeoProvider.tsx
1999
2010
  import { jsx as jsx10 } from "react/jsx-runtime";
2011
+ var logger3 = createPackageComponentLogger3(
2012
+ "@asgardeo/react",
2013
+ "AsgardeoProvider"
2014
+ );
2000
2015
  var AsgardeoProvider = ({
2001
2016
  afterSignInUrl = window.location.origin,
2002
2017
  afterSignOutUrl = window.location.origin,
@@ -2154,8 +2169,23 @@ var AsgardeoProvider = ({
2154
2169
  reRenderCheckRef.current = true;
2155
2170
  (async () => {
2156
2171
  const isAlreadySignedIn = await asgardeo.isSignedIn();
2157
- if (isAlreadySignedIn) {
2172
+ const scheduleAutoRefresh = async () => {
2173
+ try {
2174
+ await asgardeo.startAutoRefreshToken();
2175
+ } catch (error) {
2176
+ logger3.warn("Failed to schedule automatic token refresh.", error);
2177
+ }
2178
+ };
2179
+ const resumeSession = async () => {
2158
2180
  await updateSession();
2181
+ await scheduleAutoRefresh();
2182
+ };
2183
+ if (isAlreadySignedIn) {
2184
+ await resumeSession();
2185
+ }
2186
+ await scheduleAutoRefresh();
2187
+ if (await asgardeo.isSignedIn()) {
2188
+ await resumeSession();
2159
2189
  return;
2160
2190
  }
2161
2191
  const currentUrl = new URL(window.location.href);
@@ -2810,8 +2840,8 @@ var useForm = (config = {}) => {
2810
2840
  var useForm_default = useForm;
2811
2841
 
2812
2842
  // src/hooks/useBranding.ts
2813
- import { createPackageComponentLogger as createPackageComponentLogger3 } from "@asgardeo/browser";
2814
- var logger3 = createPackageComponentLogger3(
2843
+ import { createPackageComponentLogger as createPackageComponentLogger4 } from "@asgardeo/browser";
2844
+ var logger4 = createPackageComponentLogger4(
2815
2845
  "@asgardeo/react",
2816
2846
  "useBranding"
2817
2847
  );
@@ -2819,7 +2849,7 @@ var useBranding = () => {
2819
2849
  try {
2820
2850
  return useBrandingContext_default();
2821
2851
  } catch (error) {
2822
- logger3.warn(
2852
+ logger4.warn(
2823
2853
  "useBranding: BrandingProvider not available. Make sure to wrap your app with BrandingProvider or AsgardeoProvider with branding preferences."
2824
2854
  );
2825
2855
  return {
@@ -3698,7 +3728,7 @@ import {
3698
3728
  AsgardeoAPIError,
3699
3729
  withVendorCSSClassPrefix as withVendorCSSClassPrefix19,
3700
3730
  handleWebAuthnAuthentication,
3701
- createPackageComponentLogger as createPackageComponentLogger4
3731
+ createPackageComponentLogger as createPackageComponentLogger5
3702
3732
  } from "@asgardeo/browser";
3703
3733
  import { cx as cx19 } from "@emotion/css";
3704
3734
  import { useEffect as useEffect14, useState as useState15, useCallback as useCallback10, useRef as useRef5 } from "react";
@@ -6918,7 +6948,7 @@ var BaseSignIn_styles_default = useStyles16;
6918
6948
 
6919
6949
  // src/components/presentation/auth/SignIn/v1/BaseSignIn.tsx
6920
6950
  import { jsx as jsx58, jsxs as jsxs26 } from "react/jsx-runtime";
6921
- var logger4 = createPackageComponentLogger4(
6951
+ var logger5 = createPackageComponentLogger5(
6922
6952
  "@asgardeo/react",
6923
6953
  "BaseSignIn"
6924
6954
  );
@@ -7005,7 +7035,7 @@ var BaseSignInContent = ({
7005
7035
  "width=500,height=600,scrollbars=yes,resizable=yes"
7006
7036
  );
7007
7037
  if (!popup) {
7008
- logger4.error("Failed to open popup window");
7038
+ logger5.error("Failed to open popup window");
7009
7039
  return false;
7010
7040
  }
7011
7041
  let messageHandler;
@@ -7067,7 +7097,7 @@ var BaseSignInContent = ({
7067
7097
  const state = url.searchParams.get("state");
7068
7098
  const oauthError = url.searchParams.get("error");
7069
7099
  if (oauthError) {
7070
- logger4.error("OAuth error:");
7100
+ logger5.error("OAuth error:");
7071
7101
  popup.close();
7072
7102
  cleanup();
7073
7103
  return;
@@ -7097,7 +7127,7 @@ var BaseSignInContent = ({
7097
7127
  } catch (e) {
7098
7128
  }
7099
7129
  } catch (e) {
7100
- logger4.error("Error monitoring popup:");
7130
+ logger5.error("Error monitoring popup:");
7101
7131
  }
7102
7132
  }, 1e3);
7103
7133
  return true;
@@ -7236,7 +7266,7 @@ var BaseSignInContent = ({
7236
7266
  }
7237
7267
  }
7238
7268
  } catch (passkeyError) {
7239
- logger4.error("Passkey authentication error:");
7269
+ logger5.error("Passkey authentication error:");
7240
7270
  let errorMessage = passkeyError instanceof Error ? passkeyError.message : t("errors.signin.flow.passkeys.failure");
7241
7271
  if (passkeyError instanceof Error && passkeyError.message.includes("security")) {
7242
7272
  errorMessage += " This may be due to browser security settings, an insecure connection, or device restrictions.";
@@ -7806,7 +7836,7 @@ import {
7806
7836
  FieldType as FieldType7,
7807
7837
  EmbeddedFlowComponentTypeV2 as EmbeddedFlowComponentType,
7808
7838
  EmbeddedFlowEventTypeV2 as EmbeddedFlowEventType,
7809
- createPackageComponentLogger as createPackageComponentLogger5,
7839
+ createPackageComponentLogger as createPackageComponentLogger6,
7810
7840
  resolveFlowTemplateLiterals as resolveFlowTemplateLiterals3,
7811
7841
  resolveEmojiUrisInHtml
7812
7842
  } from "@asgardeo/browser";
@@ -8638,7 +8668,7 @@ var flowIconRegistry_default = flowIconRegistry;
8638
8668
 
8639
8669
  // src/components/presentation/auth/AuthOptionFactory.tsx
8640
8670
  import { jsx as jsx68 } from "react/jsx-runtime";
8641
- var logger5 = createPackageComponentLogger5(
8671
+ var logger6 = createPackageComponentLogger6(
8642
8672
  "@asgardeo/react",
8643
8673
  "AuthOptionFactory"
8644
8674
  );
@@ -8881,7 +8911,7 @@ var createAuthComponentFromFlow = (component, formValues, touchedFields, formErr
8881
8911
  const identifier = component.ref ?? component.id;
8882
8912
  const rootOuId = options.additionalData?.["rootOuId"];
8883
8913
  if (!rootOuId || !options.fetchOrganizationUnitChildren) {
8884
- logger5.warn("OU_SELECT requires additionalData.rootOuId and fetchOrganizationUnitChildren. Skipping render.");
8914
+ logger6.warn("OU_SELECT requires additionalData.rootOuId and fetchOrganizationUnitChildren. Skipping render.");
8885
8915
  return null;
8886
8916
  }
8887
8917
  return /* @__PURE__ */ jsx68(
@@ -8962,7 +8992,7 @@ var createAuthComponentFromFlow = (component, formValues, touchedFields, formErr
8962
8992
  const iconName = component.name || "";
8963
8993
  const IconComponent = flowIconRegistry_default[iconName];
8964
8994
  if (!IconComponent) {
8965
- logger5.warn(`Unknown icon name: "${iconName}". Skipping render.`);
8995
+ logger6.warn(`Unknown icon name: "${iconName}". Skipping render.`);
8966
8996
  return null;
8967
8997
  }
8968
8998
  return /* @__PURE__ */ jsx68(IconComponent, { size: component.size || 24, color: component.color || "currentColor" }, key);
@@ -9018,7 +9048,7 @@ var createAuthComponentFromFlow = (component, formValues, touchedFields, formErr
9018
9048
  return /* @__PURE__ */ jsx68(FlowTimer_default, { expiresIn, textTemplate }, key);
9019
9049
  }
9020
9050
  default:
9021
- logger5.warn(`Unsupported component type: ${component.type}. Skipping render.`);
9051
+ logger6.warn(`Unsupported component type: ${component.type}. Skipping render.`);
9022
9052
  return null;
9023
9053
  }
9024
9054
  };
@@ -10119,7 +10149,7 @@ import {
10119
10149
  EmbeddedFlowComponentType as EmbeddedFlowComponentType3,
10120
10150
  EmbeddedFlowResponseType,
10121
10151
  withVendorCSSClassPrefix as withVendorCSSClassPrefix23,
10122
- createPackageComponentLogger as createPackageComponentLogger6
10152
+ createPackageComponentLogger as createPackageComponentLogger7
10123
10153
  } from "@asgardeo/browser";
10124
10154
  import { cx as cx24 } from "@emotion/css";
10125
10155
  import { useEffect as useEffect19, useState as useState20, useCallback as useCallback13, useRef as useRef8 } from "react";
@@ -10777,7 +10807,7 @@ var BaseSignUp_styles_default = useStyles20;
10777
10807
 
10778
10808
  // src/components/presentation/auth/SignUp/v1/BaseSignUp.tsx
10779
10809
  import { jsx as jsx79, jsxs as jsxs34 } from "react/jsx-runtime";
10780
- var logger6 = createPackageComponentLogger6(
10810
+ var logger7 = createPackageComponentLogger7(
10781
10811
  "@asgardeo/react",
10782
10812
  "BaseSignUp"
10783
10813
  );
@@ -10918,7 +10948,7 @@ var BaseSignUpContent = ({
10918
10948
  const redirectUrl = response.data.redirectURL;
10919
10949
  const popup = window.open(redirectUrl, "oauth_popup", "width=500,height=600,scrollbars=yes,resizable=yes");
10920
10950
  if (!popup) {
10921
- logger6.error("Failed to open popup window");
10951
+ logger7.error("Failed to open popup window");
10922
10952
  return false;
10923
10953
  }
10924
10954
  let hasProcessedCallback = false;
@@ -10987,7 +11017,7 @@ var BaseSignUpContent = ({
10987
11017
  const state = url.searchParams.get("state");
10988
11018
  const error = url.searchParams.get("error");
10989
11019
  if (error) {
10990
- logger6.error("OAuth error:");
11020
+ logger7.error("OAuth error:");
10991
11021
  popup.close();
10992
11022
  cleanup();
10993
11023
  return;
@@ -11022,7 +11052,7 @@ var BaseSignUpContent = ({
11022
11052
  } catch (e) {
11023
11053
  }
11024
11054
  } catch (e) {
11025
- logger6.error("Error monitoring popup:");
11055
+ logger7.error("Error monitoring popup:");
11026
11056
  }
11027
11057
  }, 1e3);
11028
11058
  return true;
@@ -11225,7 +11255,7 @@ import {
11225
11255
  EmbeddedFlowResponseType as EmbeddedFlowResponseType2,
11226
11256
  withVendorCSSClassPrefix as withVendorCSSClassPrefix24,
11227
11257
  EmbeddedFlowComponentTypeV2 as EmbeddedFlowComponentType4,
11228
- createPackageComponentLogger as createPackageComponentLogger7
11258
+ createPackageComponentLogger as createPackageComponentLogger8
11229
11259
  } from "@asgardeo/browser";
11230
11260
  import { cx as cx25 } from "@emotion/css";
11231
11261
  import { useEffect as useEffect20, useState as useState21, useCallback as useCallback14, useRef as useRef9 } from "react";
@@ -11292,7 +11322,7 @@ var getAuthComponentHeadings_default = getAuthComponentHeadings;
11292
11322
 
11293
11323
  // src/components/presentation/auth/SignUp/v2/BaseSignUp.tsx
11294
11324
  import { jsx as jsx80, jsxs as jsxs35 } from "react/jsx-runtime";
11295
- var logger7 = createPackageComponentLogger7(
11325
+ var logger8 = createPackageComponentLogger8(
11296
11326
  "@asgardeo/react",
11297
11327
  "BaseSignUp"
11298
11328
  );
@@ -11449,7 +11479,7 @@ var BaseSignUpContent2 = ({
11449
11479
  const redirectUrl = response.data.redirectURL;
11450
11480
  const popup = window.open(redirectUrl, "oauth_popup", "width=500,height=600,scrollbars=yes,resizable=yes");
11451
11481
  if (!popup) {
11452
- logger7.error("Failed to open popup window");
11482
+ logger8.error("Failed to open popup window");
11453
11483
  return false;
11454
11484
  }
11455
11485
  let hasProcessedCallback = false;
@@ -11520,7 +11550,7 @@ var BaseSignUpContent2 = ({
11520
11550
  const state = url.searchParams.get("state");
11521
11551
  const error = url.searchParams.get("error");
11522
11552
  if (error) {
11523
- logger7.error("OAuth error:");
11553
+ logger8.error("OAuth error:");
11524
11554
  popup.close();
11525
11555
  cleanup();
11526
11556
  return;
@@ -11555,7 +11585,7 @@ var BaseSignUpContent2 = ({
11555
11585
  } catch (e) {
11556
11586
  }
11557
11587
  } catch (e) {
11558
- logger7.error("Error monitoring popup:");
11588
+ logger8.error("Error monitoring popup:");
11559
11589
  }
11560
11590
  }, 1e3);
11561
11591
  return true;
@@ -15808,7 +15838,7 @@ var BuildingAlt_default = BuildingAlt;
15808
15838
  import { useState as useState32 } from "react";
15809
15839
 
15810
15840
  // src/components/presentation/CreateOrganization/BaseCreateOrganization.tsx
15811
- import { createPackageComponentLogger as createPackageComponentLogger8 } from "@asgardeo/browser";
15841
+ import { createPackageComponentLogger as createPackageComponentLogger9 } from "@asgardeo/browser";
15812
15842
  import { cx as cx34 } from "@emotion/css";
15813
15843
  import { useState as useState31 } from "react";
15814
15844
 
@@ -15952,7 +15982,7 @@ var BaseCreateOrganization_styles_default = useStyles29;
15952
15982
 
15953
15983
  // src/components/presentation/CreateOrganization/BaseCreateOrganization.tsx
15954
15984
  import { jsx as jsx109, jsxs as jsxs50 } from "react/jsx-runtime";
15955
- var logger8 = createPackageComponentLogger8(
15985
+ var logger9 = createPackageComponentLogger9(
15956
15986
  "@asgardeo/react",
15957
15987
  "BaseCreateOrganization"
15958
15988
  );
@@ -16038,7 +16068,7 @@ var BaseCreateOrganization = ({
16038
16068
  onSuccess(payload);
16039
16069
  }
16040
16070
  } catch (submitError) {
16041
- logger8.error("Form submission error:");
16071
+ logger9.error("Form submission error:");
16042
16072
  }
16043
16073
  };
16044
16074
  const createOrganizationContent = /* @__PURE__ */ jsx109("div", { className: cx34(styles["root"], cardLayout && styles["card"], className), style, children: /* @__PURE__ */ jsxs50("div", { className: cx34(styles["content"]), children: [
@@ -16687,7 +16717,7 @@ var OrganizationList = (props) => {
16687
16717
  var OrganizationList_default = OrganizationList;
16688
16718
 
16689
16719
  // src/components/presentation/OrganizationProfile/OrganizationProfile.tsx
16690
- import { createPackageComponentLogger as createPackageComponentLogger9 } from "@asgardeo/browser";
16720
+ import { createPackageComponentLogger as createPackageComponentLogger10 } from "@asgardeo/browser";
16691
16721
  import { useEffect as useEffect25, useState as useState36 } from "react";
16692
16722
 
16693
16723
  // src/components/presentation/OrganizationProfile/BaseOrganizationProfile.tsx
@@ -17575,7 +17605,7 @@ var updateOrganization_default = updateOrganization;
17575
17605
 
17576
17606
  // src/components/presentation/OrganizationProfile/OrganizationProfile.tsx
17577
17607
  import { jsx as jsx115 } from "react/jsx-runtime";
17578
- var logger9 = createPackageComponentLogger9(
17608
+ var logger10 = createPackageComponentLogger10(
17579
17609
  "@asgardeo/react",
17580
17610
  "OrganizationProfile"
17581
17611
  );
@@ -17606,7 +17636,7 @@ var OrganizationProfile = ({
17606
17636
  });
17607
17637
  setOrganization(orgData);
17608
17638
  } catch (err) {
17609
- logger9.error("Failed to fetch organization:");
17639
+ logger10.error("Failed to fetch organization:");
17610
17640
  setOrganization(null);
17611
17641
  }
17612
17642
  };
@@ -17628,7 +17658,7 @@ var OrganizationProfile = ({
17628
17658
  await onUpdate(payload);
17629
17659
  }
17630
17660
  } catch (err) {
17631
- logger9.error("Failed to update organization:");
17661
+ logger10.error("Failed to update organization:");
17632
17662
  throw err;
17633
17663
  }
17634
17664
  };