@ttoss/react-auth 1.6.6 → 1.6.8

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/esm/index.js CHANGED
@@ -76,7 +76,7 @@ var useAuth = () => {
76
76
  };
77
77
 
78
78
  // src/Auth.tsx
79
- import * as React3 from "react";
79
+ import * as React5 from "react";
80
80
  import { Auth as AmplifyAuth } from "aws-amplify";
81
81
 
82
82
  // src/AuthCard.tsx
@@ -257,8 +257,10 @@ var AuthFullScreen = ({
257
257
  };
258
258
 
259
259
  // src/AuthSignIn.tsx
260
+ import * as React3 from "react";
260
261
  import { Button as Button2, Flex as Flex3, Link, Text } from "@ttoss/ui";
261
262
  import { Form as Form2, FormFieldInput as FormFieldInput2, FormFieldPassword, useForm as useForm2, yup as yup2, yupResolver as yupResolver2 } from "@ttoss/forms";
263
+ import { NotificationsBox, useNotifications as useNotifications2 } from "@ttoss/react-notifications";
262
264
 
263
265
  // ../cloud-auth/dist/esm/index.js
264
266
  var PASSWORD_MINIMUM_LENGTH = 8;
@@ -515,6 +517,12 @@ var AuthSignIn = ({
515
517
  const {
516
518
  intl
517
519
  } = useI18n2();
520
+ const {
521
+ setNotifications
522
+ } = useNotifications2();
523
+ React3.useEffect(() => {
524
+ setNotifications(void 0);
525
+ }, [setNotifications]);
518
526
  const schema = yup2.object().shape({
519
527
  email: yup2.string().required(intl.formatMessage({
520
528
  id: "r+QgO+",
@@ -636,14 +644,16 @@ var AuthSignIn = ({
636
644
  }]
637
645
  })
638
646
  })
639
- })]
647
+ }), /* @__PURE__ */jsx5(NotificationsBox, {})]
640
648
  })
641
649
  });
642
650
  };
643
651
 
644
652
  // src/AuthSignUp.tsx
645
- import { Form as Form3, FormFieldInput as FormFieldInput3, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
646
- import { Link as Link2, Text as Text2 } from "@ttoss/ui";
653
+ import * as React4 from "react";
654
+ import { Flex as Flex4, Link as Link2, Text as Text2 } from "@ttoss/ui";
655
+ import { Form as Form3, FormFieldInput as FormFieldInput3, FormFieldPassword as FormFieldPassword2, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
656
+ import { NotificationsBox as NotificationsBox2, useNotifications as useNotifications3 } from "@ttoss/react-notifications";
647
657
  import { useI18n as useI18n3 } from "@ttoss/react-i18n";
648
658
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
649
659
  var AuthSignUp = ({
@@ -653,6 +663,12 @@ var AuthSignUp = ({
653
663
  const {
654
664
  intl
655
665
  } = useI18n3();
666
+ const {
667
+ setNotifications
668
+ } = useNotifications3();
669
+ React4.useEffect(() => {
670
+ setNotifications(void 0);
671
+ }, [setNotifications]);
656
672
  const schema = yup3.object().shape({
657
673
  email: yup3.string().required(intl.formatMessage({
658
674
  id: "r+QgO+",
@@ -687,9 +703,23 @@ var AuthSignUp = ({
687
703
  }]
688
704
  }, {
689
705
  value: PASSWORD_MINIMUM_LENGTH
690
- })).trim()
706
+ })).trim(),
707
+ confirmPassword: yup3.string().required(intl.formatMessage({
708
+ id: "NJ57Qj",
709
+ defaultMessage: [{
710
+ "type": 0,
711
+ "value": "Confirm password field is required"
712
+ }]
713
+ })).oneOf([yup3.ref("password")], intl.formatMessage({
714
+ id: "WU/CqP",
715
+ defaultMessage: [{
716
+ "type": 0,
717
+ "value": "Passwords are not the same"
718
+ }]
719
+ }))
691
720
  });
692
721
  const formMethods = useForm3({
722
+ mode: "all",
693
723
  resolver: yupResolver3(schema)
694
724
  });
695
725
  const onSubmitForm = data => {
@@ -700,17 +730,17 @@ var AuthSignUp = ({
700
730
  onSubmit: onSubmitForm,
701
731
  children: /* @__PURE__ */jsxs3(AuthCard, {
702
732
  buttonLabel: intl.formatMessage({
703
- id: "Pdio77",
733
+ id: "URJDrG",
704
734
  defaultMessage: [{
705
735
  "type": 0,
706
- "value": "Create account"
736
+ "value": "Sign up"
707
737
  }]
708
738
  }),
709
739
  title: intl.formatMessage({
710
- id: "EXZxA0",
740
+ id: "oayEC3",
711
741
  defaultMessage: [{
712
742
  "type": 0,
713
- "value": "Register"
743
+ "value": "Sign up"
714
744
  }]
715
745
  }),
716
746
  isValidForm: formMethods.formState.isValid,
@@ -718,33 +748,47 @@ var AuthSignUp = ({
718
748
  onClick: onReturnToSignIn,
719
749
  as: Link2,
720
750
  children: intl.formatMessage({
721
- id: "LU2ddR",
751
+ id: "rx8HF/",
722
752
  defaultMessage: [{
723
753
  "type": 0,
724
- "value": "Do you already have an account? Sign in"
754
+ "value": "I’m already registered"
725
755
  }]
726
756
  })
727
757
  }),
728
- children: [/* @__PURE__ */jsx6(FormFieldInput3, {
729
- name: "email",
730
- label: intl.formatMessage({
731
- id: "5E12mO",
732
- defaultMessage: [{
733
- "type": 0,
734
- "value": "Email"
735
- }]
736
- })
737
- }), /* @__PURE__ */jsx6(FormFieldInput3, {
738
- name: "password",
739
- type: "password",
740
- label: intl.formatMessage({
741
- id: "PylVqx",
742
- defaultMessage: [{
743
- "type": 0,
744
- "value": "Password"
745
- }]
746
- })
747
- })]
758
+ children: [/* @__PURE__ */jsxs3(Flex4, {
759
+ sx: {
760
+ flexDirection: "column",
761
+ gap: "xl"
762
+ },
763
+ children: [/* @__PURE__ */jsx6(FormFieldInput3, {
764
+ name: "email",
765
+ label: intl.formatMessage({
766
+ id: "5E12mO",
767
+ defaultMessage: [{
768
+ "type": 0,
769
+ "value": "Email"
770
+ }]
771
+ })
772
+ }), /* @__PURE__ */jsx6(FormFieldPassword2, {
773
+ name: "password",
774
+ label: intl.formatMessage({
775
+ id: "PylVqx",
776
+ defaultMessage: [{
777
+ "type": 0,
778
+ "value": "Password"
779
+ }]
780
+ })
781
+ }), /* @__PURE__ */jsx6(FormFieldPassword2, {
782
+ name: "confirmPassword",
783
+ label: intl.formatMessage({
784
+ id: "lY+cuM",
785
+ defaultMessage: [{
786
+ "type": 0,
787
+ "value": "Confirm password"
788
+ }]
789
+ })
790
+ })]
791
+ }), /* @__PURE__ */jsx6(NotificationsBox2, {})]
748
792
  })
749
793
  });
750
794
  };
@@ -752,7 +796,7 @@ var AuthSignUp = ({
752
796
  // src/Auth.tsx
753
797
  import { assign, createMachine } from "xstate";
754
798
  import { useMachine } from "@xstate/react";
755
- import { useNotifications as useNotifications2 } from "@ttoss/react-notifications";
799
+ import { useNotifications as useNotifications4 } from "@ttoss/react-notifications";
756
800
  import { jsx as jsx7 } from "react/jsx-runtime";
757
801
  var authMachine = createMachine({
758
802
  predictableActionArguments: true,
@@ -804,9 +848,10 @@ var AuthLogic = () => {
804
848
  } = useAuth();
805
849
  const [state, send] = useMachine(authMachine);
806
850
  const {
807
- setLoading
808
- } = useNotifications2();
809
- const onSignIn = React3.useCallback(async ({
851
+ setLoading,
852
+ setNotifications
853
+ } = useNotifications4();
854
+ const onSignIn = React5.useCallback(async ({
810
855
  email,
811
856
  password
812
857
  }) => {
@@ -824,11 +869,15 @@ var AuthLogic = () => {
824
869
  break;
825
870
  default:
826
871
  }
872
+ setNotifications({
873
+ type: "error",
874
+ message: error.message
875
+ });
827
876
  } finally {
828
877
  setLoading(false);
829
878
  }
830
- }, [send, setLoading]);
831
- const onSignUp = React3.useCallback(async ({
879
+ }, [send, setLoading, setNotifications]);
880
+ const onSignUp = React5.useCallback(async ({
832
881
  email,
833
882
  password
834
883
  }) => {
@@ -845,11 +894,16 @@ var AuthLogic = () => {
845
894
  type: "SIGN_UP_CONFIRM",
846
895
  email
847
896
  });
848
- } catch (error) {} finally {
897
+ } catch (error) {
898
+ setNotifications({
899
+ type: "error",
900
+ message: error.message
901
+ });
902
+ } finally {
849
903
  setLoading(false);
850
904
  }
851
- }, [send, setLoading]);
852
- const onConfirmSignUp = React3.useCallback(async ({
905
+ }, [send, setLoading, setNotifications]);
906
+ const onConfirmSignUp = React5.useCallback(async ({
853
907
  email,
854
908
  code
855
909
  }) => {
@@ -860,11 +914,16 @@ var AuthLogic = () => {
860
914
  type: "SIGN_UP_CONFIRMED",
861
915
  email
862
916
  });
863
- } catch (error) {} finally {
917
+ } catch (error) {
918
+ setNotifications({
919
+ type: "error",
920
+ message: error.message
921
+ });
922
+ } finally {
864
923
  setLoading(false);
865
924
  }
866
- }, [send, setLoading]);
867
- const onReturnToSignIn = React3.useCallback(() => {
925
+ }, [send, setLoading, setNotifications]);
926
+ const onReturnToSignIn = React5.useCallback(() => {
868
927
  send({
869
928
  type: "RETURN_TO_SIGN_IN"
870
929
  });
@@ -898,7 +957,7 @@ var Auth2 = ({
898
957
  logo,
899
958
  fullScreen = true
900
959
  }) => {
901
- const withLogoNode = React3.useMemo(() => {
960
+ const withLogoNode = React5.useMemo(() => {
902
961
  return /* @__PURE__ */jsx7(LogoProvider, {
903
962
  logo,
904
963
  children: /* @__PURE__ */jsx7(AuthLogic, {})
package/dist/index.d.ts CHANGED
@@ -38,6 +38,7 @@ type OnSignIn = (input: OnSignInInput) => void;
38
38
  type OnSignUpInput = {
39
39
  email: string;
40
40
  password: string;
41
+ confirmPassword: string;
41
42
  };
42
43
  type OnSignUp = (input: OnSignUpInput) => void;
43
44
  type OnConfirmSignUp = (input: {
package/dist/index.js CHANGED
@@ -120,7 +120,7 @@ var useAuth = () => {
120
120
  };
121
121
 
122
122
  // src/Auth.tsx
123
- var React3 = __toESM(require("react"));
123
+ var React5 = __toESM(require("react"));
124
124
  var import_aws_amplify2 = require("aws-amplify");
125
125
 
126
126
  // src/AuthCard.tsx
@@ -301,8 +301,10 @@ var AuthFullScreen = ({
301
301
  };
302
302
 
303
303
  // src/AuthSignIn.tsx
304
+ var React3 = __toESM(require("react"));
304
305
  var import_ui3 = require("@ttoss/ui");
305
306
  var import_forms2 = require("@ttoss/forms");
307
+ var import_react_notifications2 = require("@ttoss/react-notifications");
306
308
 
307
309
  // ../cloud-auth/dist/esm/index.js
308
310
  var PASSWORD_MINIMUM_LENGTH = 8;
@@ -559,6 +561,12 @@ var AuthSignIn = ({
559
561
  const {
560
562
  intl
561
563
  } = (0, import_react_i18n2.useI18n)();
564
+ const {
565
+ setNotifications
566
+ } = (0, import_react_notifications2.useNotifications)();
567
+ React3.useEffect(() => {
568
+ setNotifications(void 0);
569
+ }, [setNotifications]);
562
570
  const schema = import_forms2.yup.object().shape({
563
571
  email: import_forms2.yup.string().required(intl.formatMessage({
564
572
  id: "r+QgO+",
@@ -680,14 +688,16 @@ var AuthSignIn = ({
680
688
  }]
681
689
  })
682
690
  })
683
- })]
691
+ }), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_react_notifications2.NotificationsBox, {})]
684
692
  })
685
693
  });
686
694
  };
687
695
 
688
696
  // src/AuthSignUp.tsx
689
- var import_forms3 = require("@ttoss/forms");
697
+ var React4 = __toESM(require("react"));
690
698
  var import_ui4 = require("@ttoss/ui");
699
+ var import_forms3 = require("@ttoss/forms");
700
+ var import_react_notifications3 = require("@ttoss/react-notifications");
691
701
  var import_react_i18n3 = require("@ttoss/react-i18n");
692
702
  var import_jsx_runtime6 = require("react/jsx-runtime");
693
703
  var AuthSignUp = ({
@@ -697,6 +707,12 @@ var AuthSignUp = ({
697
707
  const {
698
708
  intl
699
709
  } = (0, import_react_i18n3.useI18n)();
710
+ const {
711
+ setNotifications
712
+ } = (0, import_react_notifications3.useNotifications)();
713
+ React4.useEffect(() => {
714
+ setNotifications(void 0);
715
+ }, [setNotifications]);
700
716
  const schema = import_forms3.yup.object().shape({
701
717
  email: import_forms3.yup.string().required(intl.formatMessage({
702
718
  id: "r+QgO+",
@@ -731,9 +747,23 @@ var AuthSignUp = ({
731
747
  }]
732
748
  }, {
733
749
  value: PASSWORD_MINIMUM_LENGTH
734
- })).trim()
750
+ })).trim(),
751
+ confirmPassword: import_forms3.yup.string().required(intl.formatMessage({
752
+ id: "NJ57Qj",
753
+ defaultMessage: [{
754
+ "type": 0,
755
+ "value": "Confirm password field is required"
756
+ }]
757
+ })).oneOf([import_forms3.yup.ref("password")], intl.formatMessage({
758
+ id: "WU/CqP",
759
+ defaultMessage: [{
760
+ "type": 0,
761
+ "value": "Passwords are not the same"
762
+ }]
763
+ }))
735
764
  });
736
765
  const formMethods = (0, import_forms3.useForm)({
766
+ mode: "all",
737
767
  resolver: (0, import_forms3.yupResolver)(schema)
738
768
  });
739
769
  const onSubmitForm = data => {
@@ -744,17 +774,17 @@ var AuthSignUp = ({
744
774
  onSubmit: onSubmitForm,
745
775
  children: /* @__PURE__ */(0, import_jsx_runtime6.jsxs)(AuthCard, {
746
776
  buttonLabel: intl.formatMessage({
747
- id: "Pdio77",
777
+ id: "URJDrG",
748
778
  defaultMessage: [{
749
779
  "type": 0,
750
- "value": "Create account"
780
+ "value": "Sign up"
751
781
  }]
752
782
  }),
753
783
  title: intl.formatMessage({
754
- id: "EXZxA0",
784
+ id: "oayEC3",
755
785
  defaultMessage: [{
756
786
  "type": 0,
757
- "value": "Register"
787
+ "value": "Sign up"
758
788
  }]
759
789
  }),
760
790
  isValidForm: formMethods.formState.isValid,
@@ -762,33 +792,47 @@ var AuthSignUp = ({
762
792
  onClick: onReturnToSignIn,
763
793
  as: import_ui4.Link,
764
794
  children: intl.formatMessage({
765
- id: "LU2ddR",
795
+ id: "rx8HF/",
766
796
  defaultMessage: [{
767
797
  "type": 0,
768
- "value": "Do you already have an account? Sign in"
798
+ "value": "I’m already registered"
769
799
  }]
770
800
  })
771
801
  }),
772
- children: [/* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldInput, {
773
- name: "email",
774
- label: intl.formatMessage({
775
- id: "5E12mO",
776
- defaultMessage: [{
777
- "type": 0,
778
- "value": "Email"
779
- }]
780
- })
781
- }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldInput, {
782
- name: "password",
783
- type: "password",
784
- label: intl.formatMessage({
785
- id: "PylVqx",
786
- defaultMessage: [{
787
- "type": 0,
788
- "value": "Password"
789
- }]
790
- })
791
- })]
802
+ children: [/* @__PURE__ */(0, import_jsx_runtime6.jsxs)(import_ui4.Flex, {
803
+ sx: {
804
+ flexDirection: "column",
805
+ gap: "xl"
806
+ },
807
+ children: [/* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldInput, {
808
+ name: "email",
809
+ label: intl.formatMessage({
810
+ id: "5E12mO",
811
+ defaultMessage: [{
812
+ "type": 0,
813
+ "value": "Email"
814
+ }]
815
+ })
816
+ }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldPassword, {
817
+ name: "password",
818
+ label: intl.formatMessage({
819
+ id: "PylVqx",
820
+ defaultMessage: [{
821
+ "type": 0,
822
+ "value": "Password"
823
+ }]
824
+ })
825
+ }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldPassword, {
826
+ name: "confirmPassword",
827
+ label: intl.formatMessage({
828
+ id: "lY+cuM",
829
+ defaultMessage: [{
830
+ "type": 0,
831
+ "value": "Confirm password"
832
+ }]
833
+ })
834
+ })]
835
+ }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_react_notifications3.NotificationsBox, {})]
792
836
  })
793
837
  });
794
838
  };
@@ -796,7 +840,7 @@ var AuthSignUp = ({
796
840
  // src/Auth.tsx
797
841
  var import_xstate = require("xstate");
798
842
  var import_react = require("@xstate/react");
799
- var import_react_notifications2 = require("@ttoss/react-notifications");
843
+ var import_react_notifications4 = require("@ttoss/react-notifications");
800
844
  var import_jsx_runtime7 = require("react/jsx-runtime");
801
845
  var authMachine = (0, import_xstate.createMachine)({
802
846
  predictableActionArguments: true,
@@ -848,9 +892,10 @@ var AuthLogic = () => {
848
892
  } = useAuth();
849
893
  const [state, send] = (0, import_react.useMachine)(authMachine);
850
894
  const {
851
- setLoading
852
- } = (0, import_react_notifications2.useNotifications)();
853
- const onSignIn = React3.useCallback(async ({
895
+ setLoading,
896
+ setNotifications
897
+ } = (0, import_react_notifications4.useNotifications)();
898
+ const onSignIn = React5.useCallback(async ({
854
899
  email,
855
900
  password
856
901
  }) => {
@@ -868,11 +913,15 @@ var AuthLogic = () => {
868
913
  break;
869
914
  default:
870
915
  }
916
+ setNotifications({
917
+ type: "error",
918
+ message: error.message
919
+ });
871
920
  } finally {
872
921
  setLoading(false);
873
922
  }
874
- }, [send, setLoading]);
875
- const onSignUp = React3.useCallback(async ({
923
+ }, [send, setLoading, setNotifications]);
924
+ const onSignUp = React5.useCallback(async ({
876
925
  email,
877
926
  password
878
927
  }) => {
@@ -889,11 +938,16 @@ var AuthLogic = () => {
889
938
  type: "SIGN_UP_CONFIRM",
890
939
  email
891
940
  });
892
- } catch (error) {} finally {
941
+ } catch (error) {
942
+ setNotifications({
943
+ type: "error",
944
+ message: error.message
945
+ });
946
+ } finally {
893
947
  setLoading(false);
894
948
  }
895
- }, [send, setLoading]);
896
- const onConfirmSignUp = React3.useCallback(async ({
949
+ }, [send, setLoading, setNotifications]);
950
+ const onConfirmSignUp = React5.useCallback(async ({
897
951
  email,
898
952
  code
899
953
  }) => {
@@ -904,11 +958,16 @@ var AuthLogic = () => {
904
958
  type: "SIGN_UP_CONFIRMED",
905
959
  email
906
960
  });
907
- } catch (error) {} finally {
961
+ } catch (error) {
962
+ setNotifications({
963
+ type: "error",
964
+ message: error.message
965
+ });
966
+ } finally {
908
967
  setLoading(false);
909
968
  }
910
- }, [send, setLoading]);
911
- const onReturnToSignIn = React3.useCallback(() => {
969
+ }, [send, setLoading, setNotifications]);
970
+ const onReturnToSignIn = React5.useCallback(() => {
912
971
  send({
913
972
  type: "RETURN_TO_SIGN_IN"
914
973
  });
@@ -942,7 +1001,7 @@ var Auth2 = ({
942
1001
  logo,
943
1002
  fullScreen = true
944
1003
  }) => {
945
- const withLogoNode = React3.useMemo(() => {
1004
+ const withLogoNode = React5.useMemo(() => {
946
1005
  return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(LogoProvider, {
947
1006
  logo,
948
1007
  children: /* @__PURE__ */(0, import_jsx_runtime7.jsx)(AuthLogic, {})
@@ -23,12 +23,6 @@
23
23
  "value": "Forgot password?"
24
24
  }
25
25
  ],
26
- "EXZxA0": [
27
- {
28
- "type": 0,
29
- "value": "Register"
30
- }
31
- ],
32
26
  "EZ3YF2": [
33
27
  {
34
28
  "type": 0,
@@ -47,10 +41,10 @@
47
41
  "value": "Code"
48
42
  }
49
43
  ],
50
- "LU2ddR": [
44
+ "NJ57Qj": [
51
45
  {
52
46
  "type": 0,
53
- "value": "Do you already have an account? Sign in"
47
+ "value": "Confirm password field is required"
54
48
  }
55
49
  ],
56
50
  "OhDL0i": [
@@ -59,12 +53,6 @@
59
53
  "value": "Invalid email"
60
54
  }
61
55
  ],
62
- "Pdio77": [
63
- {
64
- "type": 0,
65
- "value": "Create account"
66
- }
67
- ],
68
56
  "PylVqx": [
69
57
  {
70
58
  "type": 0,
@@ -105,6 +93,18 @@
105
93
  "value": "Confirm"
106
94
  }
107
95
  ],
96
+ "URJDrG": [
97
+ {
98
+ "type": 0,
99
+ "value": "Sign up"
100
+ }
101
+ ],
102
+ "WU/CqP": [
103
+ {
104
+ "type": 0,
105
+ "value": "Passwords are not the same"
106
+ }
107
+ ],
108
108
  "cGR2eI": [
109
109
  {
110
110
  "type": 0,
@@ -117,10 +117,28 @@
117
117
  "value": "Password field is required"
118
118
  }
119
119
  ],
120
+ "lY+cuM": [
121
+ {
122
+ "type": 0,
123
+ "value": "Confirm password"
124
+ }
125
+ ],
126
+ "oayEC3": [
127
+ {
128
+ "type": 0,
129
+ "value": "Sign up"
130
+ }
131
+ ],
120
132
  "r+QgO+": [
121
133
  {
122
134
  "type": 0,
123
135
  "value": "Email field is required"
124
136
  }
137
+ ],
138
+ "rx8HF/": [
139
+ {
140
+ "type": 0,
141
+ "value": "I’m already registered"
142
+ }
125
143
  ]
126
144
  }
package/i18n/lang/en.json CHANGED
@@ -15,10 +15,6 @@
15
15
  "defaultMessage": "Forgot password?",
16
16
  "description": "Forgot password?"
17
17
  },
18
- "EXZxA0": {
19
- "defaultMessage": "Register",
20
- "description": "Title on sign up."
21
- },
22
18
  "EZ3YF2": {
23
19
  "defaultMessage": "Sign up",
24
20
  "description": "Sign up"
@@ -31,18 +27,14 @@
31
27
  "defaultMessage": "Code",
32
28
  "description": "Sign up confirmation code"
33
29
  },
34
- "LU2ddR": {
35
- "defaultMessage": "Do you already have an account? Sign in",
36
- "description": "Link to sign in on sign up."
30
+ "NJ57Qj": {
31
+ "defaultMessage": "Confirm password field is required",
32
+ "description": "Confirm Password is required."
37
33
  },
38
34
  "OhDL0i": {
39
35
  "defaultMessage": "Invalid email",
40
36
  "description": "Invalid email."
41
37
  },
42
- "Pdio77": {
43
- "defaultMessage": "Create account",
44
- "description": "Create account."
45
- },
46
38
  "PylVqx": {
47
39
  "defaultMessage": "Password",
48
40
  "description": "Password label."
@@ -59,6 +51,14 @@
59
51
  "defaultMessage": "Confirm",
60
52
  "description": "Confirm"
61
53
  },
54
+ "URJDrG": {
55
+ "defaultMessage": "Sign up",
56
+ "description": "Create account."
57
+ },
58
+ "WU/CqP": {
59
+ "defaultMessage": "Passwords are not the same",
60
+ "description": "Passwords are not the same"
61
+ },
62
62
  "cGR2eI": {
63
63
  "defaultMessage": "Confirmation",
64
64
  "description": "Confirmation"
@@ -67,8 +67,20 @@
67
67
  "defaultMessage": "Password field is required",
68
68
  "description": "Password is required."
69
69
  },
70
+ "lY+cuM": {
71
+ "defaultMessage": "Confirm password",
72
+ "description": "Confirm Password label."
73
+ },
74
+ "oayEC3": {
75
+ "defaultMessage": "Sign up",
76
+ "description": "Title on sign up."
77
+ },
70
78
  "r+QgO+": {
71
79
  "defaultMessage": "Email field is required",
72
80
  "description": "Email is a required field."
81
+ },
82
+ "rx8HF/": {
83
+ "defaultMessage": "I’m already registered",
84
+ "description": "Link to sign in on sign up."
73
85
  }
74
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/react-auth",
3
- "version": "1.6.6",
3
+ "version": "1.6.8",
4
4
  "description": "ttoss authentication module for React apps.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ttoss",
@@ -19,13 +19,13 @@
19
19
  "dependencies": {
20
20
  "@xstate/react": "^3.2.2",
21
21
  "xstate": "^4.37.2",
22
- "@ttoss/forms": "^0.17.6"
22
+ "@ttoss/forms": "^0.17.7"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "aws-amplify": "^5.0.0",
26
26
  "react": ">=16.8.0",
27
27
  "@ttoss/react-i18n": "^1.22.0",
28
- "@ttoss/react-notifications": "^1.22.6",
28
+ "@ttoss/react-notifications": "^1.22.8",
29
29
  "@ttoss/ui": "^1.36.6"
30
30
  },
31
31
  "devDependencies": {
@@ -37,7 +37,7 @@
37
37
  "@ttoss/config": "^1.30.0",
38
38
  "@ttoss/i18n-cli": "^0.5.0",
39
39
  "@ttoss/react-i18n": "^1.22.0",
40
- "@ttoss/react-notifications": "^1.22.6",
40
+ "@ttoss/react-notifications": "^1.22.8",
41
41
  "@ttoss/test-utils": "^1.23.0",
42
42
  "@ttoss/ui": "^1.36.6"
43
43
  },
package/src/Auth.tsx CHANGED
@@ -87,7 +87,7 @@ const AuthLogic = () => {
87
87
 
88
88
  const [state, send] = useMachine(authMachine);
89
89
 
90
- const { setLoading } = useNotifications();
90
+ const { setLoading, setNotifications } = useNotifications();
91
91
 
92
92
  const onSignIn = React.useCallback<OnSignIn>(
93
93
  async ({ email, password }) => {
@@ -95,8 +95,8 @@ const AuthLogic = () => {
95
95
  setLoading(true);
96
96
  await AmplifyAuth.signIn(email, password);
97
97
  // toast('Signed In');
98
- } catch (error) {
99
- switch ((error as any).code) {
98
+ } catch (error: any) {
99
+ switch (error.code) {
100
100
  case 'UserNotConfirmedException':
101
101
  await AmplifyAuth.resendSignUp(email);
102
102
  send({ type: 'SIGN_UP_RESEND_CONFIRMATION', email } as any);
@@ -104,11 +104,12 @@ const AuthLogic = () => {
104
104
  default:
105
105
  // toast(JSON.stringify(error, null, 2));
106
106
  }
107
+ setNotifications({ type: 'error', message: error.message });
107
108
  } finally {
108
109
  setLoading(false);
109
110
  }
110
111
  },
111
- [send, setLoading]
112
+ [send, setLoading, setNotifications]
112
113
  );
113
114
 
114
115
  const onSignUp = React.useCallback<OnSignUp>(
@@ -122,13 +123,14 @@ const AuthLogic = () => {
122
123
  });
123
124
  // toast('Signed Up');
124
125
  send({ type: 'SIGN_UP_CONFIRM', email } as any);
125
- } catch (error) {
126
+ } catch (error: any) {
127
+ setNotifications({ type: 'error', message: error.message });
126
128
  // toast(JSON.stringify(error, null, 2));
127
129
  } finally {
128
130
  setLoading(false);
129
131
  }
130
132
  },
131
- [send, setLoading]
133
+ [send, setLoading, setNotifications]
132
134
  );
133
135
 
134
136
  const onConfirmSignUp = React.useCallback<OnConfirmSignUp>(
@@ -138,13 +140,14 @@ const AuthLogic = () => {
138
140
  await AmplifyAuth.confirmSignUp(email, code);
139
141
  // toast('Confirmed Signed In');
140
142
  send({ type: 'SIGN_UP_CONFIRMED', email } as any);
141
- } catch (error) {
143
+ } catch (error: any) {
144
+ setNotifications({ type: 'error', message: error.message });
142
145
  // toast(JSON.stringify(error, null, 2));
143
146
  } finally {
144
147
  setLoading(false);
145
148
  }
146
149
  },
147
- [send, setLoading]
150
+ [send, setLoading, setNotifications]
148
151
  );
149
152
 
150
153
  const onReturnToSignIn = React.useCallback(() => {
@@ -84,7 +84,14 @@ export const AuthProvider = ({ children }: { children: React.ReactNode }) => {
84
84
  }
85
85
 
86
86
  return (
87
- <AuthContext.Provider value={{ signOut, isAuthenticated, user, tokens }}>
87
+ <AuthContext.Provider
88
+ value={{
89
+ signOut,
90
+ isAuthenticated,
91
+ user,
92
+ tokens,
93
+ }}
94
+ >
88
95
  {children}
89
96
  </AuthContext.Provider>
90
97
  );
@@ -1,3 +1,4 @@
1
+ import * as React from 'react';
1
2
  import { AuthCard } from './AuthCard';
2
3
  import { Button, Flex, Link, Text } from '@ttoss/ui';
3
4
  import {
@@ -8,6 +9,7 @@ import {
8
9
  yup,
9
10
  yupResolver,
10
11
  } from '@ttoss/forms';
12
+ import { NotificationsBox, useNotifications } from '@ttoss/react-notifications';
11
13
  import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
12
14
  import { useI18n } from '@ttoss/react-i18n';
13
15
  import type { OnSignIn, OnSignInInput } from './types';
@@ -27,6 +29,11 @@ export const AuthSignIn = ({
27
29
  onForgotPassword,
28
30
  }: AuthSignInProps) => {
29
31
  const { intl } = useI18n();
32
+ const { setNotifications } = useNotifications();
33
+
34
+ React.useEffect(() => {
35
+ setNotifications(undefined);
36
+ }, [setNotifications]);
30
37
 
31
38
  const schema = yup.object().shape({
32
39
  email: yup
@@ -135,6 +142,8 @@ export const AuthSignIn = ({
135
142
  })}
136
143
  </Text>
137
144
  </Flex>
145
+
146
+ <NotificationsBox />
138
147
  </AuthCard>
139
148
  </Form>
140
149
  );
@@ -1,6 +1,15 @@
1
+ import * as React from 'react';
1
2
  import { AuthCard } from './AuthCard';
2
- import { Form, FormFieldInput, useForm, yup, yupResolver } from '@ttoss/forms';
3
- import { Link, Text } from '@ttoss/ui';
3
+ import { Flex, Link, Text } from '@ttoss/ui';
4
+ import {
5
+ Form,
6
+ FormFieldInput,
7
+ FormFieldPassword,
8
+ useForm,
9
+ yup,
10
+ yupResolver,
11
+ } from '@ttoss/forms';
12
+ import { NotificationsBox, useNotifications } from '@ttoss/react-notifications';
4
13
  import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
5
14
  import { useI18n } from '@ttoss/react-i18n';
6
15
  import type { OnSignUp, OnSignUpInput } from './types';
@@ -12,6 +21,11 @@ export type AuthSignUpProps = {
12
21
 
13
22
  export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
14
23
  const { intl } = useI18n();
24
+ const { setNotifications } = useNotifications();
25
+
26
+ React.useEffect(() => {
27
+ setNotifications(undefined);
28
+ }, [setNotifications]);
15
29
 
16
30
  const schema = yup.object().shape({
17
31
  email: yup
@@ -47,9 +61,25 @@ export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
47
61
  )
48
62
  )
49
63
  .trim(),
64
+ confirmPassword: yup
65
+ .string()
66
+ .required(
67
+ intl.formatMessage({
68
+ description: 'Confirm Password is required.',
69
+ defaultMessage: 'Confirm password field is required',
70
+ })
71
+ )
72
+ .oneOf(
73
+ [yup.ref('password')],
74
+ intl.formatMessage({
75
+ description: 'Passwords are not the same',
76
+ defaultMessage: 'Passwords are not the same',
77
+ })
78
+ ),
50
79
  });
51
80
 
52
81
  const formMethods = useForm<OnSignUpInput>({
82
+ mode: 'all',
53
83
  resolver: yupResolver(schema),
54
84
  });
55
85
 
@@ -62,37 +92,47 @@ export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
62
92
  <AuthCard
63
93
  buttonLabel={intl.formatMessage({
64
94
  description: 'Create account.',
65
- defaultMessage: 'Create account',
95
+ defaultMessage: 'Sign up',
66
96
  })}
67
97
  title={intl.formatMessage({
68
98
  description: 'Title on sign up.',
69
- defaultMessage: 'Register',
99
+ defaultMessage: 'Sign up',
70
100
  })}
71
101
  isValidForm={formMethods.formState.isValid}
72
102
  extraButton={
73
103
  <Text onClick={onReturnToSignIn} as={Link}>
74
104
  {intl.formatMessage({
75
105
  description: 'Link to sign in on sign up.',
76
- defaultMessage: 'Do you already have an account? Sign in',
106
+ defaultMessage: 'I’m already registered',
77
107
  })}
78
108
  </Text>
79
109
  }
80
110
  >
81
- <FormFieldInput
82
- name="email"
83
- label={intl.formatMessage({
84
- description: 'Email label.',
85
- defaultMessage: 'Email',
86
- })}
87
- />
88
- <FormFieldInput
89
- name="password"
90
- type="password"
91
- label={intl.formatMessage({
92
- description: 'Password label.',
93
- defaultMessage: 'Password',
94
- })}
95
- />
111
+ <Flex sx={{ flexDirection: 'column', gap: 'xl' }}>
112
+ <FormFieldInput
113
+ name="email"
114
+ label={intl.formatMessage({
115
+ description: 'Email label.',
116
+ defaultMessage: 'Email',
117
+ })}
118
+ />
119
+ <FormFieldPassword
120
+ name="password"
121
+ label={intl.formatMessage({
122
+ description: 'Password label.',
123
+ defaultMessage: 'Password',
124
+ })}
125
+ />
126
+ <FormFieldPassword
127
+ name="confirmPassword"
128
+ label={intl.formatMessage({
129
+ description: 'Confirm Password label.',
130
+ defaultMessage: 'Confirm password',
131
+ })}
132
+ />
133
+ </Flex>
134
+
135
+ <NotificationsBox />
96
136
  </AuthCard>
97
137
  </Form>
98
138
  );
package/src/types.ts CHANGED
@@ -8,6 +8,7 @@ export type OnSignIn = (input: OnSignInInput) => void;
8
8
  export type OnSignUpInput = {
9
9
  email: string;
10
10
  password: string;
11
+ confirmPassword: string;
11
12
  };
12
13
 
13
14
  export type OnSignUp = (input: OnSignUpInput) => void;