@ttoss/react-auth 1.6.41 → 1.7.0

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 React5 from "react";
79
+ import * as React6 from "react";
80
80
  import { Auth as AmplifyAuth } from "aws-amplify";
81
81
 
82
82
  // src/AuthCard.tsx
@@ -236,32 +236,115 @@ var AuthConfirmSignUp = ({
236
236
  });
237
237
  };
238
238
 
239
- // src/AuthFullScreen.tsx
240
- import { Flex as Flex2 } from "@ttoss/ui";
241
- import { jsx as jsx4 } from "react/jsx-runtime";
242
- var AuthFullScreen = ({
243
- children
239
+ // src/AuthForgotPassword.tsx
240
+ import { Button as Button2, Link, Text } from "@ttoss/ui";
241
+ import { Form as Form2, FormFieldInput as FormFieldInput2, useForm as useForm2, yup as yup2, yupResolver as yupResolver2 } from "@ttoss/forms";
242
+ import { NotificationsBox } from "@ttoss/react-notifications";
243
+ import { useI18n as useI18n2 } from "@ttoss/react-i18n";
244
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
245
+ var AuthForgotPassword = ({
246
+ onForgotPassword,
247
+ onCancel,
248
+ onSignUp
244
249
  }) => {
245
- return /* @__PURE__ */jsx4(Flex2, {
250
+ const {
251
+ intl
252
+ } = useI18n2();
253
+ const schema = yup2.object().shape({
254
+ email: yup2.string().required(intl.formatMessage({
255
+ id: "5oOshZ",
256
+ defaultMessage: [{
257
+ "type": 0,
258
+ "value": "Enter your email address"
259
+ }]
260
+ })).email(intl.formatMessage({
261
+ id: "SnONhb",
262
+ defaultMessage: [{
263
+ "type": 0,
264
+ "value": "Please, insert a valid e-mail"
265
+ }]
266
+ }))
267
+ }).required();
268
+ const formMethods = useForm2({
269
+ resolver: yupResolver2(schema),
270
+ mode: "onBlur"
271
+ });
272
+ return /* @__PURE__ */jsx4(Form2, {
273
+ ...formMethods,
246
274
  sx: {
247
- height: "100vh",
248
- width: "100vw",
249
- justifyContent: "center",
250
- alignItems: "center",
251
- margin: 0,
252
- backgroundPosition: "center",
253
- backgroundRepeat: "no-repeat",
254
- backgroundSize: "cover"
275
+ maxWidth: "390px"
255
276
  },
256
- children
277
+ onSubmit: ({
278
+ email
279
+ }) => {
280
+ return onForgotPassword({
281
+ email
282
+ });
283
+ },
284
+ children: /* @__PURE__ */jsxs2(AuthCard, {
285
+ buttonLabel: intl.formatMessage({
286
+ id: "mZzmNV",
287
+ defaultMessage: [{
288
+ "type": 0,
289
+ "value": "Recover Password"
290
+ }]
291
+ }),
292
+ isValidForm: formMethods.formState.isValid,
293
+ title: intl.formatMessage({
294
+ id: "S4bbEj",
295
+ defaultMessage: [{
296
+ "type": 0,
297
+ "value": "Recovering Password"
298
+ }]
299
+ }),
300
+ extraButton: /* @__PURE__ */jsx4(Button2, {
301
+ sx: {
302
+ textAlign: "center",
303
+ display: "initial"
304
+ },
305
+ variant: "secondary",
306
+ onClick: onCancel,
307
+ children: intl.formatMessage({
308
+ id: "6PdOcy",
309
+ defaultMessage: [{
310
+ "type": 0,
311
+ "value": "Cancel"
312
+ }]
313
+ })
314
+ }),
315
+ children: [/* @__PURE__ */jsx4(FormFieldInput2, {
316
+ name: "email",
317
+ label: intl.formatMessage({
318
+ id: "XreZg+",
319
+ defaultMessage: [{
320
+ "type": 0,
321
+ "value": "Registered Email"
322
+ }]
323
+ })
324
+ }), /* @__PURE__ */jsx4(NotificationsBox, {}), /* @__PURE__ */jsx4(Text, {
325
+ sx: {
326
+ marginTop: "xl",
327
+ cursor: "pointer"
328
+ },
329
+ as: Link,
330
+ onClick: onSignUp,
331
+ children: intl.formatMessage({
332
+ id: "lZvoYL",
333
+ defaultMessage: [{
334
+ "type": 0,
335
+ "value": "Sign up now"
336
+ }]
337
+ })
338
+ })]
339
+ })
257
340
  });
258
341
  };
259
342
 
260
- // src/AuthSignIn.tsx
343
+ // src/AuthForgotPasswordResetPassword.tsx
261
344
  import * as React3 from "react";
262
- import { Button as Button2, Flex as Flex3, Link, Text } from "@ttoss/ui";
263
- import { Form as Form2, FormFieldInput as FormFieldInput2, FormFieldPassword, useForm as useForm2, yup as yup2, yupResolver as yupResolver2 } from "@ttoss/forms";
264
- import { NotificationsBox, useNotifications as useNotifications2 } from "@ttoss/react-notifications";
345
+ import { Button as Button3 } from "@ttoss/ui";
346
+ import { Form as Form3, FormFieldInput as FormFieldInput3, FormFieldPassword, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
347
+ import { NotificationsBox as NotificationsBox2 } from "@ttoss/react-notifications";
265
348
 
266
349
  // ../cloud-auth/dist/esm/index.js
267
350
  var PASSWORD_MINIMUM_LENGTH = 8;
@@ -506,9 +589,186 @@ createAuthTemplate.CognitoUserPoolLogicalId = CognitoUserPoolLogicalId;
506
589
  createAuthTemplate.CognitoUserPoolClientLogicalId = CognitoUserPoolClientLogicalId;
507
590
  createAuthTemplate.CognitoIdentityPoolLogicalId = CognitoIdentityPoolLogicalId;
508
591
 
592
+ // src/AuthForgotPasswordResetPassword.tsx
593
+ import { useI18n as useI18n3 } from "@ttoss/react-i18n";
594
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
595
+ var AuthForgotPasswordResetPassword = ({
596
+ email,
597
+ onForgotPasswordResetPassword,
598
+ onCancel
599
+ }) => {
600
+ const {
601
+ intl
602
+ } = useI18n3();
603
+ const schema = React3.useMemo(() => {
604
+ return yup3.object().shape({
605
+ code: yup3.string().required(intl.formatMessage({
606
+ id: "0XOzcH",
607
+ defaultMessage: [{
608
+ "type": 0,
609
+ "value": "Required field"
610
+ }]
611
+ })).max(6, intl.formatMessage({
612
+ id: "S3pjKw",
613
+ defaultMessage: [{
614
+ "type": 0,
615
+ "value": "Minimum "
616
+ }, {
617
+ "type": 1,
618
+ "value": "value"
619
+ }, {
620
+ "type": 0,
621
+ "value": " characters"
622
+ }]
623
+ }, {
624
+ value: 6
625
+ })),
626
+ password: yup3.string().required(intl.formatMessage({
627
+ id: "kdFYba",
628
+ defaultMessage: [{
629
+ "type": 0,
630
+ "value": "Password field is required"
631
+ }]
632
+ })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
633
+ id: "TZ4WUk",
634
+ defaultMessage: [{
635
+ "type": 0,
636
+ "value": "Password requires "
637
+ }, {
638
+ "type": 1,
639
+ "value": "value"
640
+ }, {
641
+ "type": 0,
642
+ "value": " characters"
643
+ }]
644
+ }, {
645
+ value: PASSWORD_MINIMUM_LENGTH
646
+ })).trim(),
647
+ confirmPassword: yup3.string().required(intl.formatMessage({
648
+ id: "NJ57Qj",
649
+ defaultMessage: [{
650
+ "type": 0,
651
+ "value": "Confirm password field is required"
652
+ }]
653
+ })).oneOf([yup3.ref("password")], intl.formatMessage({
654
+ id: "WU/CqP",
655
+ defaultMessage: [{
656
+ "type": 0,
657
+ "value": "Passwords are not the same"
658
+ }]
659
+ }))
660
+ }).required();
661
+ }, [intl]);
662
+ const formMethods = useForm3({
663
+ resolver: yupResolver3(schema),
664
+ mode: "onBlur"
665
+ });
666
+ return /* @__PURE__ */jsx5(Form3, {
667
+ ...formMethods,
668
+ sx: {
669
+ maxWidth: "390px"
670
+ },
671
+ onSubmit: ({
672
+ code,
673
+ password
674
+ }) => {
675
+ return onForgotPasswordResetPassword({
676
+ email,
677
+ code,
678
+ newPassword: password
679
+ });
680
+ },
681
+ children: /* @__PURE__ */jsxs3(AuthCard, {
682
+ buttonLabel: intl.formatMessage({
683
+ id: "mZzmNV",
684
+ defaultMessage: [{
685
+ "type": 0,
686
+ "value": "Recover Password"
687
+ }]
688
+ }),
689
+ isValidForm: formMethods.formState.isValid,
690
+ title: intl.formatMessage({
691
+ id: "S4bbEj",
692
+ defaultMessage: [{
693
+ "type": 0,
694
+ "value": "Recovering Password"
695
+ }]
696
+ }),
697
+ extraButton: /* @__PURE__ */jsx5(Button3, {
698
+ sx: {
699
+ textAlign: "center",
700
+ display: "initial"
701
+ },
702
+ variant: "secondary",
703
+ onClick: onCancel,
704
+ children: intl.formatMessage({
705
+ id: "6PdOcy",
706
+ defaultMessage: [{
707
+ "type": 0,
708
+ "value": "Cancel"
709
+ }]
710
+ })
711
+ }),
712
+ children: [/* @__PURE__ */jsx5(FormFieldInput3, {
713
+ name: "code",
714
+ label: intl.formatMessage({
715
+ id: "42HafR",
716
+ defaultMessage: [{
717
+ "type": 0,
718
+ "value": "Code"
719
+ }]
720
+ })
721
+ }), /* @__PURE__ */jsx5(FormFieldPassword, {
722
+ name: "password",
723
+ label: intl.formatMessage({
724
+ id: "PylVqx",
725
+ defaultMessage: [{
726
+ "type": 0,
727
+ "value": "Password"
728
+ }]
729
+ })
730
+ }), /* @__PURE__ */jsx5(FormFieldPassword, {
731
+ name: "confirmPassword",
732
+ label: intl.formatMessage({
733
+ id: "lY+cuM",
734
+ defaultMessage: [{
735
+ "type": 0,
736
+ "value": "Confirm password"
737
+ }]
738
+ })
739
+ }), /* @__PURE__ */jsx5(NotificationsBox2, {})]
740
+ })
741
+ });
742
+ };
743
+
744
+ // src/AuthFullScreen.tsx
745
+ import { Flex as Flex2 } from "@ttoss/ui";
746
+ import { jsx as jsx6 } from "react/jsx-runtime";
747
+ var AuthFullScreen = ({
748
+ children
749
+ }) => {
750
+ return /* @__PURE__ */jsx6(Flex2, {
751
+ sx: {
752
+ height: "100vh",
753
+ width: "100vw",
754
+ justifyContent: "center",
755
+ alignItems: "center",
756
+ margin: 0,
757
+ backgroundPosition: "center",
758
+ backgroundRepeat: "no-repeat",
759
+ backgroundSize: "cover"
760
+ },
761
+ children
762
+ });
763
+ };
764
+
509
765
  // src/AuthSignIn.tsx
510
- import { useI18n as useI18n2 } from "@ttoss/react-i18n";
511
- import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
766
+ import * as React4 from "react";
767
+ import { Button as Button4, Flex as Flex3, Link as Link2, Text as Text2 } from "@ttoss/ui";
768
+ import { Form as Form4, FormFieldInput as FormFieldInput4, FormFieldPassword as FormFieldPassword2, useForm as useForm4, yup as yup4, yupResolver as yupResolver4 } from "@ttoss/forms";
769
+ import { NotificationsBox as NotificationsBox3, useNotifications as useNotifications2 } from "@ttoss/react-notifications";
770
+ import { useI18n as useI18n4 } from "@ttoss/react-i18n";
771
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
512
772
  var AuthSignIn = ({
513
773
  onSignIn,
514
774
  onSignUp,
@@ -517,15 +777,15 @@ var AuthSignIn = ({
517
777
  }) => {
518
778
  const {
519
779
  intl
520
- } = useI18n2();
780
+ } = useI18n4();
521
781
  const {
522
782
  setNotifications
523
783
  } = useNotifications2();
524
- React3.useEffect(() => {
784
+ React4.useEffect(() => {
525
785
  setNotifications(void 0);
526
786
  }, [setNotifications]);
527
- const schema = yup2.object().shape({
528
- email: yup2.string().required(intl.formatMessage({
787
+ const schema = yup4.object().shape({
788
+ email: yup4.string().required(intl.formatMessage({
529
789
  id: "d1YCuH",
530
790
  defaultMessage: [{
531
791
  "type": 0,
@@ -538,7 +798,7 @@ var AuthSignIn = ({
538
798
  "value": "Please, insert a valid e-mail"
539
799
  }]
540
800
  })),
541
- password: yup2.string().required(intl.formatMessage({
801
+ password: yup4.string().required(intl.formatMessage({
542
802
  id: "kdFYba",
543
803
  defaultMessage: [{
544
804
  "type": 0,
@@ -562,22 +822,22 @@ var AuthSignIn = ({
562
822
  // remember: yup.boolean(),
563
823
  });
564
824
 
565
- const formMethods = useForm2({
825
+ const formMethods = useForm4({
566
826
  defaultValues,
567
827
  mode: "onBlur",
568
- resolver: yupResolver2(schema)
828
+ resolver: yupResolver4(schema)
569
829
  });
570
830
  const onSubmitForm = data => {
571
831
  return onSignIn(data);
572
832
  };
573
- return /* @__PURE__ */jsx5(Form2, {
833
+ return /* @__PURE__ */jsx7(Form4, {
574
834
  sx: {
575
835
  maxWidth: "390px",
576
836
  width: "100%"
577
837
  },
578
838
  ...formMethods,
579
839
  onSubmit: onSubmitForm,
580
- children: /* @__PURE__ */jsxs2(AuthCard, {
840
+ children: /* @__PURE__ */jsxs4(AuthCard, {
581
841
  title: intl.formatMessage({
582
842
  id: "F2iS37",
583
843
  defaultMessage: [{
@@ -593,7 +853,7 @@ var AuthSignIn = ({
593
853
  }]
594
854
  }),
595
855
  isValidForm: formMethods.formState.isValid,
596
- extraButton: /* @__PURE__ */jsx5(Button2, {
856
+ extraButton: /* @__PURE__ */jsx7(Button4, {
597
857
  type: "button",
598
858
  variant: "secondary",
599
859
  sx: {
@@ -610,12 +870,12 @@ var AuthSignIn = ({
610
870
  }]
611
871
  })
612
872
  }),
613
- children: [/* @__PURE__ */jsxs2(Flex3, {
873
+ children: [/* @__PURE__ */jsxs4(Flex3, {
614
874
  sx: {
615
875
  flexDirection: "column",
616
876
  gap: "xl"
617
877
  },
618
- children: [/* @__PURE__ */jsx5(FormFieldInput2, {
878
+ children: [/* @__PURE__ */jsx7(FormFieldInput4, {
619
879
  name: "email",
620
880
  label: intl.formatMessage({
621
881
  id: "5E12mO",
@@ -624,7 +884,7 @@ var AuthSignIn = ({
624
884
  "value": "Email"
625
885
  }]
626
886
  })
627
- }), /* @__PURE__ */jsx5(FormFieldPassword, {
887
+ }), /* @__PURE__ */jsx7(FormFieldPassword2, {
628
888
  name: "password",
629
889
  label: intl.formatMessage({
630
890
  id: "PylVqx",
@@ -634,16 +894,17 @@ var AuthSignIn = ({
634
894
  }]
635
895
  })
636
896
  })]
637
- }), /* @__PURE__ */jsx5(Flex3, {
897
+ }), /* @__PURE__ */jsx7(Flex3, {
638
898
  sx: {
639
899
  justifyContent: "space-between",
640
900
  marginTop: "lg"
641
901
  },
642
- children: /* @__PURE__ */jsx5(Text, {
902
+ children: /* @__PURE__ */jsx7(Text2, {
643
903
  sx: {
644
- marginLeft: "auto"
904
+ marginLeft: "auto",
905
+ cursor: "pointer"
645
906
  },
646
- as: Link,
907
+ as: Link2,
647
908
  onClick: onForgotPassword,
648
909
  children: intl.formatMessage({
649
910
  id: "BtK6KR",
@@ -653,33 +914,33 @@ var AuthSignIn = ({
653
914
  }]
654
915
  })
655
916
  })
656
- }), /* @__PURE__ */jsx5(NotificationsBox, {})]
917
+ }), /* @__PURE__ */jsx7(NotificationsBox3, {})]
657
918
  })
658
919
  });
659
920
  };
660
921
 
661
922
  // src/AuthSignUp.tsx
662
- import * as React4 from "react";
663
- import { Flex as Flex4, Link as Link2, Text as Text2 } from "@ttoss/ui";
664
- import { Form as Form3, FormFieldInput as FormFieldInput3, FormFieldPassword as FormFieldPassword2, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
665
- import { NotificationsBox as NotificationsBox2, useNotifications as useNotifications3 } from "@ttoss/react-notifications";
666
- import { useI18n as useI18n3 } from "@ttoss/react-i18n";
667
- import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
923
+ import * as React5 from "react";
924
+ import { Flex as Flex4, Link as Link3, Text as Text3 } from "@ttoss/ui";
925
+ import { Form as Form5, FormFieldInput as FormFieldInput5, FormFieldPassword as FormFieldPassword3, useForm as useForm5, yup as yup5, yupResolver as yupResolver5 } from "@ttoss/forms";
926
+ import { NotificationsBox as NotificationsBox4, useNotifications as useNotifications3 } from "@ttoss/react-notifications";
927
+ import { useI18n as useI18n5 } from "@ttoss/react-i18n";
928
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
668
929
  var AuthSignUp = ({
669
930
  onSignUp,
670
931
  onReturnToSignIn
671
932
  }) => {
672
933
  const {
673
934
  intl
674
- } = useI18n3();
935
+ } = useI18n5();
675
936
  const {
676
937
  setNotifications
677
938
  } = useNotifications3();
678
- React4.useEffect(() => {
939
+ React5.useEffect(() => {
679
940
  setNotifications(void 0);
680
941
  }, [setNotifications]);
681
- const schema = yup3.object().shape({
682
- email: yup3.string().required(intl.formatMessage({
942
+ const schema = yup5.object().shape({
943
+ email: yup5.string().required(intl.formatMessage({
683
944
  id: "d1YCuH",
684
945
  defaultMessage: [{
685
946
  "type": 0,
@@ -692,7 +953,7 @@ var AuthSignUp = ({
692
953
  "value": "Invalid email"
693
954
  }]
694
955
  })),
695
- password: yup3.string().required(intl.formatMessage({
956
+ password: yup5.string().required(intl.formatMessage({
696
957
  id: "kdFYba",
697
958
  defaultMessage: [{
698
959
  "type": 0,
@@ -713,13 +974,13 @@ var AuthSignUp = ({
713
974
  }, {
714
975
  value: PASSWORD_MINIMUM_LENGTH
715
976
  })).trim(),
716
- confirmPassword: yup3.string().required(intl.formatMessage({
977
+ confirmPassword: yup5.string().required(intl.formatMessage({
717
978
  id: "NJ57Qj",
718
979
  defaultMessage: [{
719
980
  "type": 0,
720
981
  "value": "Confirm password field is required"
721
982
  }]
722
- })).oneOf([yup3.ref("password")], intl.formatMessage({
983
+ })).oneOf([yup5.ref("password")], intl.formatMessage({
723
984
  id: "WU/CqP",
724
985
  defaultMessage: [{
725
986
  "type": 0,
@@ -727,21 +988,21 @@ var AuthSignUp = ({
727
988
  }]
728
989
  }))
729
990
  });
730
- const formMethods = useForm3({
991
+ const formMethods = useForm5({
731
992
  mode: "all",
732
- resolver: yupResolver3(schema)
993
+ resolver: yupResolver5(schema)
733
994
  });
734
995
  const onSubmitForm = data => {
735
996
  return onSignUp(data);
736
997
  };
737
- return /* @__PURE__ */jsx6(Form3, {
998
+ return /* @__PURE__ */jsx8(Form5, {
738
999
  sx: {
739
1000
  maxWidth: "390px",
740
1001
  width: "100%"
741
1002
  },
742
1003
  ...formMethods,
743
1004
  onSubmit: onSubmitForm,
744
- children: /* @__PURE__ */jsxs3(AuthCard, {
1005
+ children: /* @__PURE__ */jsxs5(AuthCard, {
745
1006
  buttonLabel: intl.formatMessage({
746
1007
  id: "URJDrG",
747
1008
  defaultMessage: [{
@@ -757,12 +1018,12 @@ var AuthSignUp = ({
757
1018
  }]
758
1019
  }),
759
1020
  isValidForm: formMethods.formState.isValid,
760
- extraButton: /* @__PURE__ */jsx6(Text2, {
1021
+ extraButton: /* @__PURE__ */jsx8(Text3, {
761
1022
  sx: {
762
1023
  cursor: "pointer"
763
1024
  },
764
1025
  onClick: onReturnToSignIn,
765
- as: Link2,
1026
+ as: Link3,
766
1027
  children: intl.formatMessage({
767
1028
  id: "rx8HF/",
768
1029
  defaultMessage: [{
@@ -771,12 +1032,12 @@ var AuthSignUp = ({
771
1032
  }]
772
1033
  })
773
1034
  }),
774
- children: [/* @__PURE__ */jsxs3(Flex4, {
1035
+ children: [/* @__PURE__ */jsxs5(Flex4, {
775
1036
  sx: {
776
1037
  flexDirection: "column",
777
1038
  gap: "xl"
778
1039
  },
779
- children: [/* @__PURE__ */jsx6(FormFieldInput3, {
1040
+ children: [/* @__PURE__ */jsx8(FormFieldInput5, {
780
1041
  name: "email",
781
1042
  label: intl.formatMessage({
782
1043
  id: "5E12mO",
@@ -785,7 +1046,7 @@ var AuthSignUp = ({
785
1046
  "value": "Email"
786
1047
  }]
787
1048
  })
788
- }), /* @__PURE__ */jsx6(FormFieldPassword2, {
1049
+ }), /* @__PURE__ */jsx8(FormFieldPassword3, {
789
1050
  name: "password",
790
1051
  label: intl.formatMessage({
791
1052
  id: "PylVqx",
@@ -794,7 +1055,7 @@ var AuthSignUp = ({
794
1055
  "value": "Password"
795
1056
  }]
796
1057
  })
797
- }), /* @__PURE__ */jsx6(FormFieldPassword2, {
1058
+ }), /* @__PURE__ */jsx8(FormFieldPassword3, {
798
1059
  name: "confirmPassword",
799
1060
  label: intl.formatMessage({
800
1061
  id: "lY+cuM",
@@ -804,7 +1065,7 @@ var AuthSignUp = ({
804
1065
  }]
805
1066
  })
806
1067
  })]
807
- }), /* @__PURE__ */jsx6(NotificationsBox2, {})]
1068
+ }), /* @__PURE__ */jsx8(NotificationsBox4, {})]
808
1069
  })
809
1070
  });
810
1071
  };
@@ -813,7 +1074,7 @@ var AuthSignUp = ({
813
1074
  import { assign, createMachine } from "xstate";
814
1075
  import { useMachine } from "@xstate/react";
815
1076
  import { useNotifications as useNotifications4 } from "@ttoss/react-notifications";
816
- import { jsx as jsx7 } from "react/jsx-runtime";
1077
+ import { jsx as jsx9 } from "react/jsx-runtime";
817
1078
  var authMachine = createMachine({
818
1079
  predictableActionArguments: true,
819
1080
  initial: "signIn",
@@ -826,6 +1087,9 @@ var authMachine = createMachine({
826
1087
  SIGN_UP_RESEND_CONFIRMATION: {
827
1088
  actions: ["assignEmail"],
828
1089
  target: "signUpConfirm"
1090
+ },
1091
+ FORGOT_PASSWORD: {
1092
+ target: "forgotPassword"
829
1093
  }
830
1094
  }
831
1095
  },
@@ -847,13 +1111,41 @@ var authMachine = createMachine({
847
1111
  target: "signIn"
848
1112
  }
849
1113
  }
1114
+ },
1115
+ forgotPassword: {
1116
+ on: {
1117
+ RETURN_TO_SIGN_IN: {
1118
+ target: "signIn"
1119
+ },
1120
+ SIGN_UP: {
1121
+ target: "signUp"
1122
+ },
1123
+ FORGOT_PASSWORD_RESET_PASSWORD: {
1124
+ actions: ["assignEmail"],
1125
+ target: "forgotPasswordResetPassword"
1126
+ }
1127
+ }
1128
+ },
1129
+ forgotPasswordResetPassword: {
1130
+ on: {
1131
+ FORGOT_PASSWORD_CONFIRMED: {
1132
+ actions: ["assignEmail"],
1133
+ target: "signIn"
1134
+ },
1135
+ RETURN_TO_SIGN_IN: {
1136
+ target: "signIn"
1137
+ }
1138
+ }
850
1139
  }
851
1140
  }
852
1141
  }, {
853
1142
  actions: {
854
1143
  assignEmail: assign({
855
1144
  email: (_, event) => {
856
- return event.email;
1145
+ if ("email" in event) {
1146
+ return event.email;
1147
+ }
1148
+ return void 0;
857
1149
  }
858
1150
  })
859
1151
  }
@@ -867,7 +1159,7 @@ var AuthLogic = () => {
867
1159
  setLoading,
868
1160
  setNotifications
869
1161
  } = useNotifications4();
870
- const onSignIn = React5.useCallback(async ({
1162
+ const onSignIn = React6.useCallback(async ({
871
1163
  email,
872
1164
  password
873
1165
  }) => {
@@ -893,7 +1185,7 @@ var AuthLogic = () => {
893
1185
  setLoading(false);
894
1186
  }
895
1187
  }, [send, setLoading, setNotifications]);
896
- const onSignUp = React5.useCallback(async ({
1188
+ const onSignUp = React6.useCallback(async ({
897
1189
  email,
898
1190
  password
899
1191
  }) => {
@@ -919,7 +1211,7 @@ var AuthLogic = () => {
919
1211
  setLoading(false);
920
1212
  }
921
1213
  }, [send, setLoading, setNotifications]);
922
- const onConfirmSignUp = React5.useCallback(async ({
1214
+ const onConfirmSignUp = React6.useCallback(async ({
923
1215
  email,
924
1216
  code
925
1217
  }) => {
@@ -939,31 +1231,90 @@ var AuthLogic = () => {
939
1231
  setLoading(false);
940
1232
  }
941
1233
  }, [send, setLoading, setNotifications]);
942
- const onReturnToSignIn = React5.useCallback(() => {
1234
+ const onReturnToSignIn = React6.useCallback(() => {
943
1235
  send({
944
1236
  type: "RETURN_TO_SIGN_IN"
945
1237
  });
946
1238
  }, [send]);
1239
+ const onForgotPassword = React6.useCallback(async ({
1240
+ email
1241
+ }) => {
1242
+ try {
1243
+ setLoading(true);
1244
+ await AmplifyAuth.forgotPassword(email);
1245
+ send({
1246
+ type: "FORGOT_PASSWORD_RESET_PASSWORD",
1247
+ email
1248
+ });
1249
+ } catch (error) {
1250
+ setNotifications({
1251
+ type: "error",
1252
+ message: error.message
1253
+ });
1254
+ } finally {
1255
+ setLoading(false);
1256
+ }
1257
+ }, [send, setLoading, setNotifications]);
1258
+ const onForgotPasswordResetPassword = React6.useCallback(async ({
1259
+ email,
1260
+ code,
1261
+ newPassword
1262
+ }) => {
1263
+ try {
1264
+ setLoading(true);
1265
+ await AmplifyAuth.forgotPasswordSubmit(email, code, newPassword);
1266
+ send({
1267
+ type: "FORGOT_PASSWORD_CONFIRMED",
1268
+ email
1269
+ });
1270
+ } catch (error) {
1271
+ setNotifications({
1272
+ type: "error",
1273
+ message: error.message
1274
+ });
1275
+ } finally {
1276
+ setLoading(false);
1277
+ }
1278
+ }, [send, setLoading, setNotifications]);
947
1279
  if (isAuthenticated) {
948
1280
  return null;
949
1281
  }
950
1282
  if (state.matches("signUp")) {
951
- return /* @__PURE__ */jsx7(AuthSignUp, {
1283
+ return /* @__PURE__ */jsx9(AuthSignUp, {
952
1284
  onSignUp,
953
1285
  onReturnToSignIn
954
1286
  });
955
1287
  }
956
1288
  if (state.matches("signUpConfirm")) {
957
- return /* @__PURE__ */jsx7(AuthConfirmSignUp, {
1289
+ return /* @__PURE__ */jsx9(AuthConfirmSignUp, {
958
1290
  onConfirmSignUp,
959
1291
  email: state.context.email
960
1292
  });
961
1293
  }
962
- return /* @__PURE__ */jsx7(AuthSignIn, {
1294
+ if (state.matches("forgotPassword")) {
1295
+ return /* @__PURE__ */jsx9(AuthForgotPassword, {
1296
+ onForgotPassword,
1297
+ onCancel: onReturnToSignIn,
1298
+ onSignUp: () => {
1299
+ return send("SIGN_UP");
1300
+ }
1301
+ });
1302
+ }
1303
+ if (state.matches("forgotPasswordResetPassword")) {
1304
+ return /* @__PURE__ */jsx9(AuthForgotPasswordResetPassword, {
1305
+ email: state.context.email,
1306
+ onForgotPasswordResetPassword,
1307
+ onCancel: onReturnToSignIn
1308
+ });
1309
+ }
1310
+ return /* @__PURE__ */jsx9(AuthSignIn, {
963
1311
  onSignIn,
964
1312
  onSignUp: () => {
965
1313
  return send("SIGN_UP");
966
1314
  },
1315
+ onForgotPassword: () => {
1316
+ return send("FORGOT_PASSWORD");
1317
+ },
967
1318
  defaultValues: {
968
1319
  email: state.context.email
969
1320
  }
@@ -973,14 +1324,14 @@ var Auth2 = ({
973
1324
  logo,
974
1325
  fullScreen = true
975
1326
  }) => {
976
- const withLogoNode = React5.useMemo(() => {
977
- return /* @__PURE__ */jsx7(LogoProvider, {
1327
+ const withLogoNode = React6.useMemo(() => {
1328
+ return /* @__PURE__ */jsx9(LogoProvider, {
978
1329
  logo,
979
- children: /* @__PURE__ */jsx7(AuthLogic, {})
1330
+ children: /* @__PURE__ */jsx9(AuthLogic, {})
980
1331
  });
981
1332
  }, [logo]);
982
1333
  if (fullScreen) {
983
- return /* @__PURE__ */jsx7(AuthFullScreen, {
1334
+ return /* @__PURE__ */jsx9(AuthFullScreen, {
984
1335
  children: withLogoNode
985
1336
  });
986
1337
  }