@asgardeo/react 0.6.26 → 0.6.28

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
@@ -1897,6 +1897,54 @@ var AsgardeoProvider = ({
1897
1897
  flattenedProfile: (0, import_browser12.generateFlattenedUserProfile)(payload, prev?.schemas)
1898
1898
  }));
1899
1899
  };
1900
+ const getDecodedIdToken = (0, import_react15.useCallback)(async () => {
1901
+ return await asgardeo.getDecodedIdToken();
1902
+ }, [asgardeo]);
1903
+ const getAccessToken = (0, import_react15.useCallback)(async () => {
1904
+ return await asgardeo.getAccessToken();
1905
+ }, [asgardeo]);
1906
+ const request = (0, import_react15.useCallback)(
1907
+ async (...args) => {
1908
+ return await asgardeo.request(...args);
1909
+ },
1910
+ [asgardeo]
1911
+ );
1912
+ const requestAll = (0, import_react15.useCallback)(
1913
+ async (...args) => {
1914
+ return await asgardeo.requestAll(...args);
1915
+ },
1916
+ [asgardeo]
1917
+ );
1918
+ const exchangeToken = (0, import_react15.useCallback)(
1919
+ async (config2, sessionId) => {
1920
+ return await asgardeo.exchangeToken(config2, sessionId);
1921
+ },
1922
+ [asgardeo]
1923
+ );
1924
+ const signOut = (0, import_react15.useCallback)(
1925
+ async (...args) => {
1926
+ return await asgardeo.signOut(...args);
1927
+ },
1928
+ [asgardeo]
1929
+ );
1930
+ const signUp = (0, import_react15.useCallback)(
1931
+ async (...args) => {
1932
+ return await asgardeo.signUp(...args);
1933
+ },
1934
+ [asgardeo]
1935
+ );
1936
+ const clearSession = (0, import_react15.useCallback)(
1937
+ async (...args) => {
1938
+ return await asgardeo.clearSession(...args);
1939
+ },
1940
+ [asgardeo]
1941
+ );
1942
+ const reInitialize = (0, import_react15.useCallback)(
1943
+ async (config2) => {
1944
+ return await asgardeo.reInitialize(config2);
1945
+ },
1946
+ [asgardeo]
1947
+ );
1900
1948
  const value = (0, import_react15.useMemo)(
1901
1949
  () => ({
1902
1950
  applicationId,
@@ -1905,25 +1953,25 @@ var AsgardeoProvider = ({
1905
1953
  signUpUrl,
1906
1954
  afterSignInUrl,
1907
1955
  baseUrl,
1908
- clearSession: asgardeo.clearSession.bind(asgardeo),
1909
- getAccessToken: asgardeo.getAccessToken.bind(asgardeo),
1956
+ clearSession,
1957
+ getAccessToken,
1910
1958
  isInitialized: isInitializedSync,
1911
1959
  isLoading: isLoadingSync,
1912
1960
  isSignedIn: isSignedInSync,
1913
1961
  organization: currentOrganization,
1914
1962
  signIn,
1915
1963
  signInSilently,
1916
- signOut: asgardeo.signOut.bind(asgardeo),
1917
- signUp: asgardeo.signUp.bind(asgardeo),
1964
+ signOut,
1965
+ signUp,
1918
1966
  user,
1919
1967
  http: {
1920
- request: asgardeo.request.bind(asgardeo),
1921
- requestAll: asgardeo.requestAll.bind(asgardeo)
1968
+ request,
1969
+ requestAll
1922
1970
  },
1923
- reInitialize: asgardeo.reInitialize.bind(asgardeo),
1971
+ reInitialize,
1924
1972
  signInOptions,
1925
- getDecodedIdToken: asgardeo.getDecodedIdToken.bind(asgardeo),
1926
- exchangeToken: asgardeo.exchangeToken.bind(asgardeo),
1973
+ getDecodedIdToken,
1974
+ exchangeToken,
1927
1975
  syncSession,
1928
1976
  platform: config?.platform,
1929
1977
  switchOrganization
@@ -1945,7 +1993,16 @@ var AsgardeoProvider = ({
1945
1993
  asgardeo,
1946
1994
  signInOptions,
1947
1995
  syncSession,
1948
- switchOrganization
1996
+ switchOrganization,
1997
+ getDecodedIdToken,
1998
+ getAccessToken,
1999
+ request,
2000
+ requestAll,
2001
+ exchangeToken,
2002
+ signOut,
2003
+ signUp,
2004
+ clearSession,
2005
+ reInitialize
1949
2006
  ]
1950
2007
  );
1951
2008
  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)(
@@ -7300,6 +7357,9 @@ var extractErrorMessage = (error, t, defaultErrorKey = "errors.flow.generic") =>
7300
7357
  if (error && typeof error === "object" && error.failureReason) {
7301
7358
  return error.failureReason;
7302
7359
  }
7360
+ if (error instanceof Error && error.message) {
7361
+ return error.message;
7362
+ }
7303
7363
  return t(defaultErrorKey);
7304
7364
  };
7305
7365
  var checkForErrorResponse = (response, t, defaultErrorKey = "errors.flow.generic") => {
@@ -7395,6 +7455,7 @@ var BaseSignInContent2 = ({
7395
7455
  components = [],
7396
7456
  onSubmit,
7397
7457
  onError,
7458
+ error: externalError,
7398
7459
  className = "",
7399
7460
  inputClassName = "",
7400
7461
  buttonClassName = "",
@@ -7413,10 +7474,12 @@ var BaseSignInContent2 = ({
7413
7474
  const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
7414
7475
  const styles = BaseSignIn_styles_default(theme, theme.vars.colors.text.primary);
7415
7476
  const [isSubmitting, setIsSubmitting] = (0, import_react58.useState)(false);
7477
+ const [apiError, setApiError] = (0, import_react58.useState)(null);
7416
7478
  const isLoading = externalIsLoading || isSubmitting;
7417
7479
  const handleError = (0, import_react58.useCallback)(
7418
7480
  (error) => {
7419
- const errorMessage = extractErrorMessage(error, t);
7481
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
7482
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
7420
7483
  clearMessages();
7421
7484
  addMessage({
7422
7485
  type: "error",
@@ -7430,7 +7493,7 @@ var BaseSignInContent2 = ({
7430
7493
  const fields = [];
7431
7494
  const processComponents = (comps) => {
7432
7495
  comps.forEach((component) => {
7433
- if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT") {
7496
+ if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT" || component.type === "EMAIL_INPUT") {
7434
7497
  const identifier = component.ref;
7435
7498
  fields.push({
7436
7499
  name: identifier,
@@ -7440,6 +7503,9 @@ var BaseSignInContent2 = ({
7440
7503
  if (component.required && (!value || value.trim() === "")) {
7441
7504
  return t("validations.required.field.error");
7442
7505
  }
7506
+ if ((component.type === "EMAIL_INPUT" || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
7507
+ return t("field.email.invalid");
7508
+ }
7443
7509
  return null;
7444
7510
  }
7445
7511
  });
@@ -7487,6 +7553,7 @@ var BaseSignInContent2 = ({
7487
7553
  }
7488
7554
  }
7489
7555
  setIsSubmitting(true);
7556
+ setApiError(null);
7490
7557
  clearMessages();
7491
7558
  console.log("Submitting component:", component, "with data:", data);
7492
7559
  try {
@@ -7573,14 +7640,18 @@ var BaseSignInContent2 = ({
7573
7640
  if (children) {
7574
7641
  const renderProps = {
7575
7642
  values: formValues,
7576
- errors: formErrors,
7643
+ fieldErrors: formErrors,
7644
+ error: apiError,
7577
7645
  touched: touchedFields,
7578
7646
  isValid: isFormValid,
7579
7647
  isLoading,
7580
7648
  components,
7581
7649
  handleInputChange,
7582
7650
  handleSubmit,
7583
- validateForm,
7651
+ validateForm: () => {
7652
+ const result = validateForm();
7653
+ return { isValid: result.isValid, fieldErrors: result.errors };
7654
+ },
7584
7655
  title: flowTitle || t("signin.heading"),
7585
7656
  subtitle: flowSubtitle || t("signin.subheading"),
7586
7657
  messages: flowMessages || []
@@ -7606,6 +7677,7 @@ var BaseSignInContent2 = ({
7606
7677
  showSubtitle && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
7607
7678
  ] }),
7608
7679
  /* @__PURE__ */ (0, import_jsx_runtime56.jsxs)(Card_default.Content, { children: [
7680
+ externalError && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("div", { className: styles.flowMessagesContainer, children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Alert_default, { variant: "error", className: (0, import_css36.cx)(styles.flowMessageItem, messageClasses), children: /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(Alert_default.Description, { children: externalError.message }) }) }),
7609
7681
  flowMessages && flowMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime56.jsx)("div", { className: styles.flowMessagesContainer, children: flowMessages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime56.jsx)(
7610
7682
  Alert_default,
7611
7683
  {
@@ -7705,7 +7777,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7705
7777
  window?.history?.replaceState({}, "", url.toString());
7706
7778
  };
7707
7779
  const handleOAuthError = (error, errorDescription) => {
7708
- console.warn("[SignIn] OAuth error detected:", error);
7709
7780
  clearFlowState();
7710
7781
  const errorMessage = errorDescription || `OAuth error: ${error}`;
7711
7782
  const err = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
@@ -7791,9 +7862,8 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7791
7862
  } catch (error) {
7792
7863
  const err = error;
7793
7864
  clearFlowState();
7794
- const errorMessage = err instanceof Error ? err.message : String(err);
7795
- const displayError = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7796
- setError(displayError);
7865
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7866
+ setError(new Error(errorMessage));
7797
7867
  initializationAttemptedRef.current = false;
7798
7868
  return;
7799
7869
  }
@@ -7801,10 +7871,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7801
7871
  const handleSubmit = async (payload) => {
7802
7872
  const effectiveFlowId = payload.flowId || currentFlowId;
7803
7873
  if (!effectiveFlowId) {
7804
- console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
7805
- payloadFlowId: payload.flowId,
7806
- currentFlowId
7807
- });
7808
7874
  throw new Error("No active flow ID");
7809
7875
  }
7810
7876
  try {
@@ -7817,18 +7883,17 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7817
7883
  if (handleRedirection(response)) {
7818
7884
  return;
7819
7885
  }
7820
- const { flowId, components: components2 } = normalizeFlowResponse(response, t, {
7886
+ const { flowId, components: components2, ...rest } = normalizeFlowResponse(response, t, {
7821
7887
  resolveTranslations: !children
7822
7888
  });
7823
7889
  if (response.flowStatus === import_browser48.EmbeddedSignInFlowStatusV2.Error) {
7824
- console.error("[SignIn] Flow returned Error status, clearing flow state");
7825
7890
  clearFlowState();
7826
7891
  const failureReason = response?.failureReason;
7827
7892
  const errorMessage = failureReason || "Authentication flow failed. Please try again.";
7828
- const err = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7893
+ const err = new Error(errorMessage);
7829
7894
  setError(err);
7830
7895
  cleanupFlowUrlParams();
7831
- return;
7896
+ throw err;
7832
7897
  }
7833
7898
  if (response.flowStatus === import_browser48.EmbeddedSignInFlowStatusV2.Complete) {
7834
7899
  const redirectUrl = response?.redirectUrl || response?.redirect_uri;
@@ -7845,8 +7910,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7845
7910
  });
7846
7911
  if (finalRedirectUrl && window?.location) {
7847
7912
  window.location.href = finalRedirectUrl;
7848
- } else {
7849
- console.warn("[SignIn] Flow completed but no redirect URL available");
7850
7913
  }
7851
7914
  return;
7852
7915
  }
@@ -7859,16 +7922,14 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7859
7922
  } catch (error) {
7860
7923
  const err = error;
7861
7924
  clearFlowState();
7862
- const errorMessage = err instanceof Error ? err.message : String(err);
7863
- const displayError = new import_browser48.AsgardeoRuntimeError(errorMessage, "SIGN_IN_ERROR", "react");
7864
- setError(displayError);
7925
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7926
+ setError(new Error(errorMessage));
7865
7927
  return;
7866
7928
  } finally {
7867
7929
  setIsSubmitting(false);
7868
7930
  }
7869
7931
  };
7870
7932
  const handleError = (error) => {
7871
- console.error("Authentication error:", error);
7872
7933
  setError(error);
7873
7934
  };
7874
7935
  (0, import_react59.useEffect)(() => {
@@ -7898,7 +7959,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7898
7959
  }
7899
7960
  };
7900
7961
  handleSubmit(submitPayload).catch((error) => {
7901
- console.error("[SignIn] OAuth callback submission failed:", error);
7902
7962
  cleanupOAuthUrlParams(true);
7903
7963
  });
7904
7964
  }, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
@@ -7920,6 +7980,7 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7920
7980
  isLoading: isLoading || !isInitialized || !isFlowInitialized,
7921
7981
  onSubmit: handleSubmit,
7922
7982
  onError: handleError,
7983
+ error: flowError,
7923
7984
  className,
7924
7985
  size,
7925
7986
  variant
@@ -9133,6 +9194,7 @@ var BaseSignUpContent2 = ({
9133
9194
  onError,
9134
9195
  onFlowChange,
9135
9196
  onComplete,
9197
+ error: externalError,
9136
9198
  className = "",
9137
9199
  inputClassName = "",
9138
9200
  buttonClassName = "",
@@ -9152,7 +9214,8 @@ var BaseSignUpContent2 = ({
9152
9214
  const styles = BaseSignUp_styles_default(theme, colorScheme);
9153
9215
  const handleError = (0, import_react62.useCallback)(
9154
9216
  (error) => {
9155
- const errorMessage = extractErrorMessage(error, t);
9217
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
9218
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
9156
9219
  clearMessages();
9157
9220
  addMessage({
9158
9221
  type: "error",
@@ -9164,7 +9227,7 @@ var BaseSignUpContent2 = ({
9164
9227
  const [isLoading, setIsLoading] = (0, import_react62.useState)(false);
9165
9228
  const [isFlowInitialized, setIsFlowInitialized] = (0, import_react62.useState)(false);
9166
9229
  const [currentFlow, setCurrentFlow] = (0, import_react62.useState)(null);
9167
- const [formData, setFormData] = (0, import_react62.useState)({});
9230
+ const [apiError, setApiError] = (0, import_react62.useState)(null);
9168
9231
  const initializationAttemptedRef = (0, import_react62.useRef)(false);
9169
9232
  const normalizeFlowResponseLocal = (0, import_react62.useCallback)(
9170
9233
  (response) => {
@@ -9197,7 +9260,7 @@ var BaseSignUpContent2 = ({
9197
9260
  const fields = [];
9198
9261
  const processComponents = (comps) => {
9199
9262
  comps.forEach((component) => {
9200
- if (component.type === import_browser59.EmbeddedFlowComponentTypeV2.TextInput) {
9263
+ if (component.type === import_browser59.EmbeddedFlowComponentTypeV2.TextInput || component.type === import_browser59.EmbeddedFlowComponentTypeV2.PasswordInput || component.type === import_browser59.EmbeddedFlowComponentTypeV2.EmailInput) {
9201
9264
  const fieldName = component.ref || component.id;
9202
9265
  fields.push({
9203
9266
  name: fieldName,
@@ -9207,12 +9270,9 @@ var BaseSignUpContent2 = ({
9207
9270
  if (component.required && (!value || value.trim() === "")) {
9208
9271
  return t("validations.required.field.error");
9209
9272
  }
9210
- if (component.variant === "EMAIL" && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
9273
+ if ((component.type === import_browser59.EmbeddedFlowComponentTypeV2.EmailInput || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
9211
9274
  return t("field.email.invalid");
9212
9275
  }
9213
- if (component.type === "PASSWORD_INPUT" && value && value.length < 8) {
9214
- return t("field.password.weak");
9215
- }
9216
9276
  return null;
9217
9277
  }
9218
9278
  });
@@ -9232,7 +9292,7 @@ var BaseSignUpContent2 = ({
9232
9292
  initialValues: {},
9233
9293
  fields: formFields,
9234
9294
  validateOnBlur: true,
9235
- validateOnChange: true,
9295
+ validateOnChange: false,
9236
9296
  requiredMessage: t("validations.required.field.error")
9237
9297
  });
9238
9298
  const {
@@ -9264,6 +9324,8 @@ var BaseSignUpContent2 = ({
9264
9324
  );
9265
9325
  const handleInputChange = (name, value) => {
9266
9326
  setFormValue(name, value);
9327
+ };
9328
+ const handleInputBlur = (name) => {
9267
9329
  setFormTouched(name, true);
9268
9330
  };
9269
9331
  const handleSubmit = async (component, data, skipValidation) => {
@@ -9278,6 +9340,7 @@ var BaseSignUpContent2 = ({
9278
9340
  }
9279
9341
  }
9280
9342
  setIsLoading(true);
9343
+ setApiError(null);
9281
9344
  clearMessages();
9282
9345
  try {
9283
9346
  const filteredInputs = {};
@@ -9291,7 +9354,7 @@ var BaseSignUpContent2 = ({
9291
9354
  const payload = {
9292
9355
  ...currentFlow.flowId && { flowId: currentFlow.flowId },
9293
9356
  flowType: currentFlow.flowType || "REGISTRATION",
9294
- ...component.id && { actionId: component.id },
9357
+ ...component.id && { action: component.id },
9295
9358
  inputs: filteredInputs
9296
9359
  };
9297
9360
  const rawResponse = await onSubmit(payload);
@@ -9340,7 +9403,7 @@ var BaseSignUpContent2 = ({
9340
9403
  code,
9341
9404
  state
9342
9405
  },
9343
- actionId: ""
9406
+ action: ""
9344
9407
  };
9345
9408
  try {
9346
9409
  const continueResponse = await onSubmit(payload);
@@ -9400,7 +9463,7 @@ var BaseSignUpContent2 = ({
9400
9463
  code,
9401
9464
  state
9402
9465
  },
9403
- actionId: ""
9466
+ action: ""
9404
9467
  };
9405
9468
  try {
9406
9469
  const continueResponse = await onSubmit(payload);
@@ -9467,6 +9530,7 @@ var BaseSignUpContent2 = ({
9467
9530
  {
9468
9531
  buttonClassName: buttonClasses,
9469
9532
  inputClassName: inputClasses,
9533
+ onInputBlur: handleInputBlur,
9470
9534
  onSubmit: handleSubmit,
9471
9535
  size,
9472
9536
  variant
@@ -9482,7 +9546,8 @@ var BaseSignUpContent2 = ({
9482
9546
  variant,
9483
9547
  inputClasses,
9484
9548
  buttonClasses,
9485
- handleSubmit
9549
+ handleSubmit,
9550
+ handleInputBlur
9486
9551
  ]
9487
9552
  );
9488
9553
  const getUrlParams = () => {
@@ -9502,6 +9567,7 @@ var BaseSignUpContent2 = ({
9502
9567
  initializationAttemptedRef.current = true;
9503
9568
  (async () => {
9504
9569
  setIsLoading(true);
9570
+ setApiError(null);
9505
9571
  clearMessages();
9506
9572
  try {
9507
9573
  const rawResponse = await onInitialize();
@@ -9539,14 +9605,18 @@ var BaseSignUpContent2 = ({
9539
9605
  if (children) {
9540
9606
  const renderProps = {
9541
9607
  values: formValues,
9542
- errors: formErrors,
9608
+ fieldErrors: formErrors,
9609
+ error: apiError,
9543
9610
  touched: touchedFields,
9544
9611
  isValid: isFormValid,
9545
9612
  isLoading,
9546
9613
  components: currentFlow?.data?.components || [],
9547
9614
  handleInputChange,
9548
9615
  handleSubmit,
9549
- validateForm,
9616
+ validateForm: () => {
9617
+ const result = validateForm();
9618
+ return { isValid: result.isValid, fieldErrors: result.errors };
9619
+ },
9550
9620
  title: flowTitle || t("signup.heading"),
9551
9621
  subtitle: flowSubtitle || t("signup.subheading"),
9552
9622
  messages: flowMessages || []
@@ -9576,6 +9646,7 @@ var BaseSignUpContent2 = ({
9576
9646
  showSubtitle && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
9577
9647
  ] }),
9578
9648
  /* @__PURE__ */ (0, import_jsx_runtime68.jsxs)(Card_default.Content, { children: [
9649
+ externalError && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: styles.flowMessagesContainer, children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Alert_default, { variant: "error", className: (0, import_css39.cx)(styles.flowMessageItem, messageClasses), children: /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(Alert_default.Description, { children: externalError.message }) }) }),
9579
9650
  flowMessages && flowMessages.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime68.jsx)("div", { className: styles.flowMessagesContainer, children: flowMessages.map((message, index) => /* @__PURE__ */ (0, import_jsx_runtime68.jsx)(
9580
9651
  Alert_default,
9581
9652
  {