@asgardeo/react 0.6.26 → 0.6.27

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.
@@ -27,9 +27,13 @@ export interface BaseSignInRenderProps {
27
27
  */
28
28
  values: Record<string, string>;
29
29
  /**
30
- * Form errors
30
+ * Field validation errors
31
31
  */
32
- errors: Record<string, string>;
32
+ fieldErrors: Record<string, string>;
33
+ /**
34
+ * API error (if any)
35
+ */
36
+ error?: Error | null;
33
37
  /**
34
38
  * Touched fields
35
39
  */
@@ -59,7 +63,7 @@ export interface BaseSignInRenderProps {
59
63
  */
60
64
  validateForm: () => {
61
65
  isValid: boolean;
62
- errors: Record<string, string>;
66
+ fieldErrors: Record<string, string>;
63
67
  };
64
68
  /**
65
69
  * Flow title
@@ -97,6 +101,10 @@ export interface BaseSignInProps {
97
101
  * Custom CSS class name for error messages.
98
102
  */
99
103
  errorClassName?: string;
104
+ /**
105
+ * Error object to display
106
+ */
107
+ error?: Error | null;
100
108
  /**
101
109
  * Flag to determine if the component is ready to be rendered.
102
110
  */
@@ -27,9 +27,13 @@ export interface BaseSignUpRenderProps {
27
27
  */
28
28
  values: Record<string, string>;
29
29
  /**
30
- * Form errors
30
+ * Field validation errors
31
31
  */
32
- errors: Record<string, string>;
32
+ fieldErrors: Record<string, string>;
33
+ /**
34
+ * API error (if any)
35
+ */
36
+ error?: Error | null;
33
37
  /**
34
38
  * Touched fields
35
39
  */
@@ -59,7 +63,7 @@ export interface BaseSignUpRenderProps {
59
63
  */
60
64
  validateForm: () => {
61
65
  isValid: boolean;
62
- errors: Record<string, string>;
66
+ fieldErrors: Record<string, string>;
63
67
  };
64
68
  /**
65
69
  * Flow title
@@ -97,6 +101,10 @@ export interface BaseSignUpProps {
97
101
  * Custom CSS class name for error messages.
98
102
  */
99
103
  errorClassName?: string;
104
+ /**
105
+ * Error object to display
106
+ */
107
+ error?: Error | null;
100
108
  /**
101
109
  * Custom CSS class name for form inputs.
102
110
  */
package/dist/index.js CHANGED
@@ -7216,6 +7216,9 @@ var extractErrorMessage = (error, t, defaultErrorKey = "errors.flow.generic") =>
7216
7216
  if (error && typeof error === "object" && error.failureReason) {
7217
7217
  return error.failureReason;
7218
7218
  }
7219
+ if (error instanceof Error && error.message) {
7220
+ return error.message;
7221
+ }
7219
7222
  return t(defaultErrorKey);
7220
7223
  };
7221
7224
  var checkForErrorResponse = (response, t, defaultErrorKey = "errors.flow.generic") => {
@@ -7311,6 +7314,7 @@ var BaseSignInContent2 = ({
7311
7314
  components = [],
7312
7315
  onSubmit,
7313
7316
  onError,
7317
+ error: externalError,
7314
7318
  className = "",
7315
7319
  inputClassName = "",
7316
7320
  buttonClassName = "",
@@ -7329,10 +7333,12 @@ var BaseSignInContent2 = ({
7329
7333
  const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
7330
7334
  const styles = BaseSignIn_styles_default(theme, theme.vars.colors.text.primary);
7331
7335
  const [isSubmitting, setIsSubmitting] = useState15(false);
7336
+ const [apiError, setApiError] = useState15(null);
7332
7337
  const isLoading = externalIsLoading || isSubmitting;
7333
7338
  const handleError = useCallback10(
7334
7339
  (error) => {
7335
- const errorMessage = extractErrorMessage(error, t);
7340
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
7341
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
7336
7342
  clearMessages();
7337
7343
  addMessage({
7338
7344
  type: "error",
@@ -7346,7 +7352,7 @@ var BaseSignInContent2 = ({
7346
7352
  const fields = [];
7347
7353
  const processComponents = (comps) => {
7348
7354
  comps.forEach((component) => {
7349
- if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT") {
7355
+ if (component.type === "TEXT_INPUT" || component.type === "PASSWORD_INPUT" || component.type === "EMAIL_INPUT") {
7350
7356
  const identifier = component.ref;
7351
7357
  fields.push({
7352
7358
  name: identifier,
@@ -7356,6 +7362,9 @@ var BaseSignInContent2 = ({
7356
7362
  if (component.required && (!value || value.trim() === "")) {
7357
7363
  return t("validations.required.field.error");
7358
7364
  }
7365
+ if ((component.type === "EMAIL_INPUT" || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
7366
+ return t("field.email.invalid");
7367
+ }
7359
7368
  return null;
7360
7369
  }
7361
7370
  });
@@ -7403,6 +7412,7 @@ var BaseSignInContent2 = ({
7403
7412
  }
7404
7413
  }
7405
7414
  setIsSubmitting(true);
7415
+ setApiError(null);
7406
7416
  clearMessages();
7407
7417
  console.log("Submitting component:", component, "with data:", data);
7408
7418
  try {
@@ -7489,14 +7499,18 @@ var BaseSignInContent2 = ({
7489
7499
  if (children) {
7490
7500
  const renderProps = {
7491
7501
  values: formValues,
7492
- errors: formErrors,
7502
+ fieldErrors: formErrors,
7503
+ error: apiError,
7493
7504
  touched: touchedFields,
7494
7505
  isValid: isFormValid,
7495
7506
  isLoading,
7496
7507
  components,
7497
7508
  handleInputChange,
7498
7509
  handleSubmit,
7499
- validateForm,
7510
+ validateForm: () => {
7511
+ const result = validateForm();
7512
+ return { isValid: result.isValid, fieldErrors: result.errors };
7513
+ },
7500
7514
  title: flowTitle || t("signin.heading"),
7501
7515
  subtitle: flowSubtitle || t("signin.subheading"),
7502
7516
  messages: flowMessages || []
@@ -7522,6 +7536,7 @@ var BaseSignInContent2 = ({
7522
7536
  showSubtitle && /* @__PURE__ */ jsx56(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
7523
7537
  ] }),
7524
7538
  /* @__PURE__ */ jsxs27(Card_default.Content, { children: [
7539
+ externalError && /* @__PURE__ */ jsx56("div", { className: styles.flowMessagesContainer, children: /* @__PURE__ */ jsx56(Alert_default, { variant: "error", className: cx20(styles.flowMessageItem, messageClasses), children: /* @__PURE__ */ jsx56(Alert_default.Description, { children: externalError.message }) }) }),
7525
7540
  flowMessages && flowMessages.length > 0 && /* @__PURE__ */ jsx56("div", { className: styles.flowMessagesContainer, children: flowMessages.map((message, index) => /* @__PURE__ */ jsx56(
7526
7541
  Alert_default,
7527
7542
  {
@@ -7628,7 +7643,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7628
7643
  window?.history?.replaceState({}, "", url.toString());
7629
7644
  };
7630
7645
  const handleOAuthError = (error, errorDescription) => {
7631
- console.warn("[SignIn] OAuth error detected:", error);
7632
7646
  clearFlowState();
7633
7647
  const errorMessage = errorDescription || `OAuth error: ${error}`;
7634
7648
  const err = new AsgardeoRuntimeError8(errorMessage, "SIGN_IN_ERROR", "react");
@@ -7714,9 +7728,8 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7714
7728
  } catch (error) {
7715
7729
  const err = error;
7716
7730
  clearFlowState();
7717
- const errorMessage = err instanceof Error ? err.message : String(err);
7718
- const displayError = new AsgardeoRuntimeError8(errorMessage, "SIGN_IN_ERROR", "react");
7719
- setError(displayError);
7731
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7732
+ setError(new Error(errorMessage));
7720
7733
  initializationAttemptedRef.current = false;
7721
7734
  return;
7722
7735
  }
@@ -7724,10 +7737,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7724
7737
  const handleSubmit = async (payload) => {
7725
7738
  const effectiveFlowId = payload.flowId || currentFlowId;
7726
7739
  if (!effectiveFlowId) {
7727
- console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
7728
- payloadFlowId: payload.flowId,
7729
- currentFlowId
7730
- });
7731
7740
  throw new Error("No active flow ID");
7732
7741
  }
7733
7742
  try {
@@ -7740,18 +7749,17 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7740
7749
  if (handleRedirection(response)) {
7741
7750
  return;
7742
7751
  }
7743
- const { flowId, components: components2 } = normalizeFlowResponse(response, t, {
7752
+ const { flowId, components: components2, ...rest } = normalizeFlowResponse(response, t, {
7744
7753
  resolveTranslations: !children
7745
7754
  });
7746
7755
  if (response.flowStatus === EmbeddedSignInFlowStatusV2.Error) {
7747
- console.error("[SignIn] Flow returned Error status, clearing flow state");
7748
7756
  clearFlowState();
7749
7757
  const failureReason = response?.failureReason;
7750
7758
  const errorMessage = failureReason || "Authentication flow failed. Please try again.";
7751
- const err = new AsgardeoRuntimeError8(errorMessage, "SIGN_IN_ERROR", "react");
7759
+ const err = new Error(errorMessage);
7752
7760
  setError(err);
7753
7761
  cleanupFlowUrlParams();
7754
- return;
7762
+ throw err;
7755
7763
  }
7756
7764
  if (response.flowStatus === EmbeddedSignInFlowStatusV2.Complete) {
7757
7765
  const redirectUrl = response?.redirectUrl || response?.redirect_uri;
@@ -7768,8 +7776,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7768
7776
  });
7769
7777
  if (finalRedirectUrl && window?.location) {
7770
7778
  window.location.href = finalRedirectUrl;
7771
- } else {
7772
- console.warn("[SignIn] Flow completed but no redirect URL available");
7773
7779
  }
7774
7780
  return;
7775
7781
  }
@@ -7782,16 +7788,14 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7782
7788
  } catch (error) {
7783
7789
  const err = error;
7784
7790
  clearFlowState();
7785
- const errorMessage = err instanceof Error ? err.message : String(err);
7786
- const displayError = new AsgardeoRuntimeError8(errorMessage, "SIGN_IN_ERROR", "react");
7787
- setError(displayError);
7791
+ const errorMessage = err?.failureReason || (err instanceof Error ? err.message : String(err));
7792
+ setError(new Error(errorMessage));
7788
7793
  return;
7789
7794
  } finally {
7790
7795
  setIsSubmitting(false);
7791
7796
  }
7792
7797
  };
7793
7798
  const handleError = (error) => {
7794
- console.error("Authentication error:", error);
7795
7799
  setError(error);
7796
7800
  };
7797
7801
  useEffect13(() => {
@@ -7821,7 +7825,6 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7821
7825
  }
7822
7826
  };
7823
7827
  handleSubmit(submitPayload).catch((error) => {
7824
- console.error("[SignIn] OAuth callback submission failed:", error);
7825
7828
  cleanupOAuthUrlParams(true);
7826
7829
  });
7827
7830
  }, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
@@ -7843,6 +7846,7 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
7843
7846
  isLoading: isLoading || !isInitialized || !isFlowInitialized,
7844
7847
  onSubmit: handleSubmit,
7845
7848
  onError: handleError,
7849
+ error: flowError,
7846
7850
  className,
7847
7851
  size,
7848
7852
  variant
@@ -9066,6 +9070,7 @@ var BaseSignUpContent2 = ({
9066
9070
  onError,
9067
9071
  onFlowChange,
9068
9072
  onComplete,
9073
+ error: externalError,
9069
9074
  className = "",
9070
9075
  inputClassName = "",
9071
9076
  buttonClassName = "",
@@ -9085,7 +9090,8 @@ var BaseSignUpContent2 = ({
9085
9090
  const styles = BaseSignUp_styles_default(theme, colorScheme);
9086
9091
  const handleError = useCallback12(
9087
9092
  (error) => {
9088
- const errorMessage = extractErrorMessage(error, t);
9093
+ const errorMessage = error?.failureReason || extractErrorMessage(error, t);
9094
+ setApiError(error instanceof Error ? error : new Error(errorMessage));
9089
9095
  clearMessages();
9090
9096
  addMessage({
9091
9097
  type: "error",
@@ -9097,7 +9103,7 @@ var BaseSignUpContent2 = ({
9097
9103
  const [isLoading, setIsLoading] = useState18(false);
9098
9104
  const [isFlowInitialized, setIsFlowInitialized] = useState18(false);
9099
9105
  const [currentFlow, setCurrentFlow] = useState18(null);
9100
- const [formData, setFormData] = useState18({});
9106
+ const [apiError, setApiError] = useState18(null);
9101
9107
  const initializationAttemptedRef = useRef6(false);
9102
9108
  const normalizeFlowResponseLocal = useCallback12(
9103
9109
  (response) => {
@@ -9130,7 +9136,7 @@ var BaseSignUpContent2 = ({
9130
9136
  const fields = [];
9131
9137
  const processComponents = (comps) => {
9132
9138
  comps.forEach((component) => {
9133
- if (component.type === EmbeddedFlowComponentType4.TextInput) {
9139
+ if (component.type === EmbeddedFlowComponentType4.TextInput || component.type === EmbeddedFlowComponentType4.PasswordInput || component.type === EmbeddedFlowComponentType4.EmailInput) {
9134
9140
  const fieldName = component.ref || component.id;
9135
9141
  fields.push({
9136
9142
  name: fieldName,
@@ -9140,12 +9146,9 @@ var BaseSignUpContent2 = ({
9140
9146
  if (component.required && (!value || value.trim() === "")) {
9141
9147
  return t("validations.required.field.error");
9142
9148
  }
9143
- if (component.variant === "EMAIL" && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
9149
+ if ((component.type === EmbeddedFlowComponentType4.EmailInput || component.variant === "EMAIL") && value && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
9144
9150
  return t("field.email.invalid");
9145
9151
  }
9146
- if (component.type === "PASSWORD_INPUT" && value && value.length < 8) {
9147
- return t("field.password.weak");
9148
- }
9149
9152
  return null;
9150
9153
  }
9151
9154
  });
@@ -9165,7 +9168,7 @@ var BaseSignUpContent2 = ({
9165
9168
  initialValues: {},
9166
9169
  fields: formFields,
9167
9170
  validateOnBlur: true,
9168
- validateOnChange: true,
9171
+ validateOnChange: false,
9169
9172
  requiredMessage: t("validations.required.field.error")
9170
9173
  });
9171
9174
  const {
@@ -9197,6 +9200,8 @@ var BaseSignUpContent2 = ({
9197
9200
  );
9198
9201
  const handleInputChange = (name, value) => {
9199
9202
  setFormValue(name, value);
9203
+ };
9204
+ const handleInputBlur = (name) => {
9200
9205
  setFormTouched(name, true);
9201
9206
  };
9202
9207
  const handleSubmit = async (component, data, skipValidation) => {
@@ -9211,6 +9216,7 @@ var BaseSignUpContent2 = ({
9211
9216
  }
9212
9217
  }
9213
9218
  setIsLoading(true);
9219
+ setApiError(null);
9214
9220
  clearMessages();
9215
9221
  try {
9216
9222
  const filteredInputs = {};
@@ -9224,7 +9230,7 @@ var BaseSignUpContent2 = ({
9224
9230
  const payload = {
9225
9231
  ...currentFlow.flowId && { flowId: currentFlow.flowId },
9226
9232
  flowType: currentFlow.flowType || "REGISTRATION",
9227
- ...component.id && { actionId: component.id },
9233
+ ...component.id && { action: component.id },
9228
9234
  inputs: filteredInputs
9229
9235
  };
9230
9236
  const rawResponse = await onSubmit(payload);
@@ -9273,7 +9279,7 @@ var BaseSignUpContent2 = ({
9273
9279
  code,
9274
9280
  state
9275
9281
  },
9276
- actionId: ""
9282
+ action: ""
9277
9283
  };
9278
9284
  try {
9279
9285
  const continueResponse = await onSubmit(payload);
@@ -9333,7 +9339,7 @@ var BaseSignUpContent2 = ({
9333
9339
  code,
9334
9340
  state
9335
9341
  },
9336
- actionId: ""
9342
+ action: ""
9337
9343
  };
9338
9344
  try {
9339
9345
  const continueResponse = await onSubmit(payload);
@@ -9400,6 +9406,7 @@ var BaseSignUpContent2 = ({
9400
9406
  {
9401
9407
  buttonClassName: buttonClasses,
9402
9408
  inputClassName: inputClasses,
9409
+ onInputBlur: handleInputBlur,
9403
9410
  onSubmit: handleSubmit,
9404
9411
  size,
9405
9412
  variant
@@ -9415,7 +9422,8 @@ var BaseSignUpContent2 = ({
9415
9422
  variant,
9416
9423
  inputClasses,
9417
9424
  buttonClasses,
9418
- handleSubmit
9425
+ handleSubmit,
9426
+ handleInputBlur
9419
9427
  ]
9420
9428
  );
9421
9429
  const getUrlParams = () => {
@@ -9435,6 +9443,7 @@ var BaseSignUpContent2 = ({
9435
9443
  initializationAttemptedRef.current = true;
9436
9444
  (async () => {
9437
9445
  setIsLoading(true);
9446
+ setApiError(null);
9438
9447
  clearMessages();
9439
9448
  try {
9440
9449
  const rawResponse = await onInitialize();
@@ -9472,14 +9481,18 @@ var BaseSignUpContent2 = ({
9472
9481
  if (children) {
9473
9482
  const renderProps = {
9474
9483
  values: formValues,
9475
- errors: formErrors,
9484
+ fieldErrors: formErrors,
9485
+ error: apiError,
9476
9486
  touched: touchedFields,
9477
9487
  isValid: isFormValid,
9478
9488
  isLoading,
9479
9489
  components: currentFlow?.data?.components || [],
9480
9490
  handleInputChange,
9481
9491
  handleSubmit,
9482
- validateForm,
9492
+ validateForm: () => {
9493
+ const result = validateForm();
9494
+ return { isValid: result.isValid, fieldErrors: result.errors };
9495
+ },
9483
9496
  title: flowTitle || t("signup.heading"),
9484
9497
  subtitle: flowSubtitle || t("signup.subheading"),
9485
9498
  messages: flowMessages || []
@@ -9509,6 +9522,7 @@ var BaseSignUpContent2 = ({
9509
9522
  showSubtitle && /* @__PURE__ */ jsx68(Typography_default, { variant: "body1", className: styles.subtitle, children: subtitle })
9510
9523
  ] }),
9511
9524
  /* @__PURE__ */ jsxs29(Card_default.Content, { children: [
9525
+ externalError && /* @__PURE__ */ jsx68("div", { className: styles.flowMessagesContainer, children: /* @__PURE__ */ jsx68(Alert_default, { variant: "error", className: cx22(styles.flowMessageItem, messageClasses), children: /* @__PURE__ */ jsx68(Alert_default.Description, { children: externalError.message }) }) }),
9512
9526
  flowMessages && flowMessages.length > 0 && /* @__PURE__ */ jsx68("div", { className: styles.flowMessagesContainer, children: flowMessages.map((message, index) => /* @__PURE__ */ jsx68(
9513
9527
  Alert_default,
9514
9528
  {