@dloizides/auth-web 1.18.1 → 1.18.3

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.mjs CHANGED
@@ -617,7 +617,11 @@ function useLoginSubmit({
617
617
  invalidCredentialsLabel
618
618
  }) {
619
619
  const [errorText, setErrorText] = useState(null);
620
+ const inFlight = useRef(false);
620
621
  const runLogin = useCallback(async () => {
622
+ if (inFlight.current) {
623
+ return;
624
+ }
621
625
  setErrorText(null);
622
626
  const trimmedUsername = username.trim();
623
627
  const hasMissingField = trimmedUsername.length === 0 || password.length === 0;
@@ -625,11 +629,14 @@ function useLoginSubmit({
625
629
  setErrorText(missingFieldsLabel);
626
630
  return;
627
631
  }
632
+ inFlight.current = true;
628
633
  try {
629
634
  const user = await login({ username: trimmedUsername, password });
630
635
  onSuccess(user);
631
636
  } catch {
632
637
  setErrorText(invalidCredentialsLabel);
638
+ } finally {
639
+ inFlight.current = false;
633
640
  }
634
641
  }, [username, password, login, onSuccess, missingFieldsLabel, invalidCredentialsLabel]);
635
642
  const handleSubmit = useCallback(() => {
@@ -637,6 +644,21 @@ function useLoginSubmit({
637
644
  }, [runLogin]);
638
645
  return { errorText, handleSubmit };
639
646
  }
647
+ function isKeyRepeat(event) {
648
+ const native = event?.nativeEvent;
649
+ return native?.repeat === true;
650
+ }
651
+ function useSubmitOnEnter(submit) {
652
+ return useCallback(
653
+ (event) => {
654
+ if (isKeyRepeat(event)) {
655
+ return;
656
+ }
657
+ submit();
658
+ },
659
+ [submit]
660
+ );
661
+ }
640
662
  var BffAuthStatus = /* @__PURE__ */ ((BffAuthStatus2) => {
641
663
  BffAuthStatus2["Loading"] = "loading";
642
664
  BffAuthStatus2["Authenticated"] = "authenticated";
@@ -775,6 +797,7 @@ function LoginForm({
775
797
  missingFieldsLabel: labels.missingFields,
776
798
  invalidCredentialsLabel: labels.invalidCredentials
777
799
  });
800
+ const handleSubmitEditing = useSubmitOnEnter(handleSubmit);
778
801
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
779
802
  /* @__PURE__ */ jsx(Text, { style: styles3.title, children: labels.title }),
780
803
  /* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: labels.subtitle }),
@@ -790,10 +813,12 @@ function LoginForm({
790
813
  editable: !isSubmitting,
791
814
  placeholder: labels.usernamePlaceholder,
792
815
  placeholderTextColor: theme.colors.textSecondary,
816
+ returnKeyType: "go",
793
817
  style: styles3.input,
794
818
  testID: withTestIdPrefix(AuthTestIds.loginUsernameInput, testIdPrefix),
795
819
  value: username,
796
- onChangeText: setUsername
820
+ onChangeText: setUsername,
821
+ onSubmitEditing: handleSubmitEditing
797
822
  }
798
823
  )
799
824
  ] }),
@@ -810,10 +835,12 @@ function LoginForm({
810
835
  editable: !isSubmitting,
811
836
  placeholder: labels.passwordPlaceholder,
812
837
  placeholderTextColor: theme.colors.textSecondary,
838
+ returnKeyType: "go",
813
839
  style: styles3.input,
814
840
  testID: withTestIdPrefix(AuthTestIds.loginPasswordInput, testIdPrefix),
815
841
  value: password,
816
- onChangeText: setPassword
842
+ onChangeText: setPassword,
843
+ onSubmitEditing: handleSubmitEditing
817
844
  }
818
845
  )
819
846
  ] }),
@@ -4093,6 +4120,7 @@ function RegisterFormFields({
4093
4120
  theme,
4094
4121
  styles: styles3,
4095
4122
  onChange,
4123
+ onSubmitEditing,
4096
4124
  testIdPrefix
4097
4125
  }) {
4098
4126
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -4112,11 +4140,13 @@ function RegisterFormFields({
4112
4140
  keyboardType: config.keyboardType ?? "default",
4113
4141
  placeholder: copy.placeholder,
4114
4142
  placeholderTextColor: theme.colors.textSecondary,
4143
+ returnKeyType: "go",
4115
4144
  secureTextEntry: config.secure === true,
4116
4145
  style: styles3.input,
4117
4146
  testID: withTestIdPrefix(config.testId, testIdPrefix),
4118
4147
  value: values[config.key],
4119
- onChangeText: (text) => onChange(config.key, text)
4148
+ onChangeText: (text) => onChange(config.key, text),
4149
+ onSubmitEditing
4120
4150
  }
4121
4151
  )
4122
4152
  ] }, config.key);
@@ -4341,6 +4371,7 @@ function RegisterForm({
4341
4371
  const handlePress = useCallback(async () => {
4342
4372
  routeRegisterOutcome(await submit(), { onSuccess, onError });
4343
4373
  }, [onError, onSuccess, submit]);
4374
+ const handleSubmitEditing = useSubmitOnEnter(handlePress);
4344
4375
  return /* @__PURE__ */ jsx(View, { style: styles3.screen, children: /* @__PURE__ */ jsxs(View, { style: styles3.card, testID: withTestIdPrefix(RegisterTestIds.form, testIdPrefix), children: [
4345
4376
  /* @__PURE__ */ jsx(Text, { style: styles3.title, children: labels.title }),
4346
4377
  /* @__PURE__ */ jsx(Text, { style: styles3.subtitle, children: labels.subtitle }),
@@ -4353,7 +4384,8 @@ function RegisterForm({
4353
4384
  testIdPrefix,
4354
4385
  theme,
4355
4386
  values: state,
4356
- onChange: setField
4387
+ onChange: setField,
4388
+ onSubmitEditing: handleSubmitEditing
4357
4389
  }
4358
4390
  ),
4359
4391
  /* @__PURE__ */ jsx(View, { style: styles3.fieldGroup, children: /* @__PURE__ */ jsx(