@ttoss/react-auth 2.0.7 → 2.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/react-auth",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "ttoss authentication module for React apps.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -27,14 +27,14 @@
27
27
  "dependencies": {
28
28
  "@xstate/react": "^3.2.2",
29
29
  "xstate": "^4.38.3",
30
- "@ttoss/forms": "^0.25.4"
30
+ "@ttoss/forms": "^0.25.6"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "aws-amplify": "^6.0.0",
34
34
  "react": ">=16.8.0",
35
- "@ttoss/react-i18n": "^2.0.1",
36
- "@ttoss/ui": "^5.0.4",
37
- "@ttoss/react-notifications": "^1.24.54"
35
+ "@ttoss/react-i18n": "^2.0.2",
36
+ "@ttoss/ui": "^5.0.6",
37
+ "@ttoss/react-notifications": "^1.24.56"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@jest/globals": "^29.7.0",
@@ -43,13 +43,13 @@
43
43
  "jest": "^29.7.0",
44
44
  "react": "^18.3.1",
45
45
  "tsup": "^8.3.0",
46
- "@ttoss/cloud-auth": "^0.12.19",
47
- "@ttoss/config": "^1.32.10",
48
- "@ttoss/i18n-cli": "^0.7.19",
49
- "@ttoss/react-i18n": "^2.0.1",
50
- "@ttoss/react-notifications": "^1.24.54",
51
- "@ttoss/test-utils": "^2.1.14",
52
- "@ttoss/ui": "^5.0.4"
46
+ "@ttoss/cloud-auth": "^0.12.20",
47
+ "@ttoss/config": "^1.33.0",
48
+ "@ttoss/react-notifications": "^1.24.56",
49
+ "@ttoss/i18n-cli": "^0.7.20",
50
+ "@ttoss/test-utils": "^2.1.15",
51
+ "@ttoss/react-i18n": "^2.0.2",
52
+ "@ttoss/ui": "^5.0.6"
53
53
  },
54
54
  "keywords": [
55
55
  "React",
package/dist/esm/index.js DELETED
@@ -1,1119 +0,0 @@
1
- /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
-
3
- // src/AuthProvider.tsx
4
- import * as React from "react";
5
- import { Hub } from "aws-amplify/utils";
6
- import { signOut as awsSignOut, fetchAuthSession, fetchUserAttributes, getCurrentUser } from "aws-amplify/auth";
7
- import { jsx } from "react/jsx-runtime";
8
- var signOut = () => {
9
- return awsSignOut();
10
- };
11
- var AuthContext = React.createContext({
12
- signOut,
13
- isAuthenticated: false,
14
- user: null,
15
- tokens: null
16
- });
17
- var AuthProvider = ({
18
- children
19
- }) => {
20
- const [{
21
- user,
22
- tokens,
23
- isAuthenticated
24
- }, setAuthState] = React.useState({
25
- user: null,
26
- tokens: null,
27
- isAuthenticated: void 0
28
- });
29
- React.useEffect(() => {
30
- const updateUser = () => {
31
- getCurrentUser().then(async ({
32
- userId
33
- }) => {
34
- const [session, user2] = await Promise.all([fetchAuthSession(), fetchUserAttributes()]);
35
- const idToken = session.tokens?.idToken?.toString() ?? "";
36
- const accessToken = session.tokens?.accessToken.toString() ?? "";
37
- setAuthState({
38
- user: {
39
- id: userId,
40
- email: user2.email ?? "",
41
- emailVerified: user2.email_verified ?? ""
42
- },
43
- tokens: {
44
- idToken,
45
- accessToken,
46
- refreshToken: ""
47
- },
48
- isAuthenticated: true
49
- });
50
- }).catch(e => {
51
- console.error(e);
52
- setAuthState({
53
- user: null,
54
- tokens: null,
55
- isAuthenticated: false
56
- });
57
- });
58
- };
59
- const updateUserListener = Hub.listen("auth", updateUser);
60
- updateUser();
61
- return () => {
62
- updateUserListener();
63
- };
64
- }, []);
65
- if (isAuthenticated === void 0) {
66
- return null;
67
- }
68
- return /* @__PURE__ */jsx(AuthContext.Provider, {
69
- value: {
70
- signOut,
71
- isAuthenticated,
72
- user,
73
- tokens
74
- },
75
- children
76
- });
77
- };
78
- var useAuth = () => {
79
- return React.useContext(AuthContext);
80
- };
81
-
82
- // src/Auth.tsx
83
- import * as React6 from "react";
84
-
85
- // src/AuthCard.tsx
86
- import * as React2 from "react";
87
- import { Box, Button, Flex, Heading } from "@ttoss/ui";
88
- import { useNotifications } from "@ttoss/react-notifications";
89
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
90
- var LogoContext = React2.createContext({});
91
- var LogoProvider = ({
92
- children,
93
- ...values
94
- }) => {
95
- return /* @__PURE__ */jsx2(LogoContext.Provider, {
96
- value: values,
97
- children
98
- });
99
- };
100
- var AuthCard = ({
101
- children,
102
- title,
103
- buttonLabel,
104
- extraButton,
105
- isValidForm
106
- }) => {
107
- const {
108
- logo
109
- } = React2.useContext(LogoContext);
110
- const {
111
- isLoading
112
- } = useNotifications();
113
- return /* @__PURE__ */jsxs(Box, {
114
- sx: {
115
- width: "100%",
116
- border: "default",
117
- borderColor: "primary",
118
- paddingX: "2xl",
119
- paddingY: "3xl",
120
- backgroundColor: "surface"
121
- },
122
- children: [logo && /* @__PURE__ */jsx2(Flex, {
123
- sx: {
124
- width: "100%",
125
- maxHeight: "90px",
126
- justifyContent: "center",
127
- marginBottom: "2xl"
128
- },
129
- children: logo
130
- }), /* @__PURE__ */jsxs(Flex, {
131
- sx: {
132
- flexDirection: "column"
133
- },
134
- children: [/* @__PURE__ */jsx2(Heading, {
135
- as: "h2",
136
- variant: "h2",
137
- sx: {
138
- marginBottom: "2xl"
139
- },
140
- children: title
141
- }), children, /* @__PURE__ */jsxs(Flex, {
142
- sx: {
143
- flexDirection: "column",
144
- width: "100%",
145
- gap: "xl",
146
- marginTop: "2xl"
147
- },
148
- children: [/* @__PURE__ */jsx2(Button, {
149
- type: "submit",
150
- "aria-label": "submit-button",
151
- variant: "accent",
152
- disabled: isLoading || !isValidForm,
153
- sx: {
154
- textAlign: "center",
155
- display: "initial"
156
- },
157
- loading: isLoading,
158
- children: buttonLabel
159
- }), extraButton]
160
- })]
161
- })]
162
- });
163
- };
164
-
165
- // src/AuthConfirmSignUp.tsx
166
- import { Form, FormFieldInput, useForm, yup, yupResolver } from "@ttoss/forms";
167
- import { useI18n } from "@ttoss/react-i18n";
168
- import { jsx as jsx3 } from "react/jsx-runtime";
169
- var AuthConfirmSignUp = ({
170
- email,
171
- onConfirmSignUp
172
- }) => {
173
- const {
174
- intl
175
- } = useI18n();
176
- const schema = yup.object().shape({
177
- code: yup.string().required(intl.formatMessage({
178
- id: "0XOzcH",
179
- defaultMessage: [{
180
- "type": 0,
181
- "value": "Required field"
182
- }]
183
- })).max(6, intl.formatMessage({
184
- id: "S3pjKw",
185
- defaultMessage: [{
186
- "type": 0,
187
- "value": "Minimum "
188
- }, {
189
- "type": 1,
190
- "value": "value"
191
- }, {
192
- "type": 0,
193
- "value": " characters"
194
- }]
195
- }, {
196
- value: 6
197
- }))
198
- }).required();
199
- const formMethods = useForm({
200
- resolver: yupResolver(schema)
201
- });
202
- return /* @__PURE__ */jsx3(Form, {
203
- ...formMethods,
204
- onSubmit: ({
205
- code
206
- }) => {
207
- return onConfirmSignUp({
208
- code,
209
- email
210
- });
211
- },
212
- children: /* @__PURE__ */jsx3(AuthCard, {
213
- buttonLabel: intl.formatMessage({
214
- id: "UNttd+",
215
- defaultMessage: [{
216
- "type": 0,
217
- "value": "Confirm"
218
- }]
219
- }),
220
- isValidForm: formMethods.formState.isValid,
221
- title: intl.formatMessage({
222
- id: "cGR2eI",
223
- defaultMessage: [{
224
- "type": 0,
225
- "value": "Confirmation"
226
- }]
227
- }),
228
- children: /* @__PURE__ */jsx3(FormFieldInput, {
229
- name: "code",
230
- label: intl.formatMessage({
231
- id: "KY2T6J",
232
- defaultMessage: [{
233
- "type": 0,
234
- "value": "Code"
235
- }]
236
- })
237
- })
238
- })
239
- });
240
- };
241
-
242
- // src/AuthForgotPassword.tsx
243
- import { Button as Button2, Link, Text } from "@ttoss/ui";
244
- import { Form as Form2, FormFieldInput as FormFieldInput2, useForm as useForm2, yup as yup2, yupResolver as yupResolver2 } from "@ttoss/forms";
245
- import { NotificationsBox } from "@ttoss/react-notifications";
246
- import { useI18n as useI18n2 } from "@ttoss/react-i18n";
247
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
248
- var AuthForgotPassword = ({
249
- onForgotPassword,
250
- onCancel,
251
- onSignUp
252
- }) => {
253
- const {
254
- intl
255
- } = useI18n2();
256
- const schema = yup2.object().shape({
257
- email: yup2.string().required(intl.formatMessage({
258
- id: "5oOshZ",
259
- defaultMessage: [{
260
- "type": 0,
261
- "value": "Enter your email address"
262
- }]
263
- })).email(intl.formatMessage({
264
- id: "SnONhb",
265
- defaultMessage: [{
266
- "type": 0,
267
- "value": "Please, insert a valid e-mail"
268
- }]
269
- }))
270
- }).required();
271
- const formMethods = useForm2({
272
- resolver: yupResolver2(schema),
273
- mode: "onBlur"
274
- });
275
- return /* @__PURE__ */jsx4(Form2, {
276
- ...formMethods,
277
- sx: {
278
- maxWidth: "390px"
279
- },
280
- onSubmit: ({
281
- email
282
- }) => {
283
- return onForgotPassword({
284
- email
285
- });
286
- },
287
- children: /* @__PURE__ */jsxs2(AuthCard, {
288
- buttonLabel: intl.formatMessage({
289
- id: "mZzmNV",
290
- defaultMessage: [{
291
- "type": 0,
292
- "value": "Recover Password"
293
- }]
294
- }),
295
- isValidForm: formMethods.formState.isValid,
296
- title: intl.formatMessage({
297
- id: "S4bbEj",
298
- defaultMessage: [{
299
- "type": 0,
300
- "value": "Recovering Password"
301
- }]
302
- }),
303
- extraButton: /* @__PURE__ */jsx4(Button2, {
304
- sx: {
305
- textAlign: "center",
306
- display: "initial"
307
- },
308
- variant: "secondary",
309
- onClick: onCancel,
310
- children: intl.formatMessage({
311
- id: "6PdOcy",
312
- defaultMessage: [{
313
- "type": 0,
314
- "value": "Cancel"
315
- }]
316
- })
317
- }),
318
- children: [/* @__PURE__ */jsx4(FormFieldInput2, {
319
- name: "email",
320
- label: intl.formatMessage({
321
- id: "XreZg+",
322
- defaultMessage: [{
323
- "type": 0,
324
- "value": "Registered Email"
325
- }]
326
- })
327
- }), /* @__PURE__ */jsx4(NotificationsBox, {}), /* @__PURE__ */jsx4(Text, {
328
- sx: {
329
- marginTop: "xl",
330
- cursor: "pointer"
331
- },
332
- as: Link,
333
- onClick: onSignUp,
334
- children: intl.formatMessage({
335
- id: "lZvoYL",
336
- defaultMessage: [{
337
- "type": 0,
338
- "value": "Sign up now"
339
- }]
340
- })
341
- })]
342
- })
343
- });
344
- };
345
-
346
- // src/AuthForgotPasswordResetPassword.tsx
347
- import * as React3 from "react";
348
- import { Button as Button3 } from "@ttoss/ui";
349
- import { Form as Form3, FormFieldInput as FormFieldInput3, FormFieldPassword, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
350
- import { NotificationsBox as NotificationsBox2 } from "@ttoss/react-notifications";
351
-
352
- // ../cloud-auth/src/config.ts
353
- var PASSWORD_MINIMUM_LENGTH = 8;
354
-
355
- // src/AuthForgotPasswordResetPassword.tsx
356
- import { useI18n as useI18n3 } from "@ttoss/react-i18n";
357
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
358
- var AuthForgotPasswordResetPassword = ({
359
- email,
360
- onForgotPasswordResetPassword,
361
- onCancel
362
- }) => {
363
- const {
364
- intl
365
- } = useI18n3();
366
- const schema = React3.useMemo(() => {
367
- return yup3.object().shape({
368
- code: yup3.string().required(intl.formatMessage({
369
- id: "0XOzcH",
370
- defaultMessage: [{
371
- "type": 0,
372
- "value": "Required field"
373
- }]
374
- })).max(6, intl.formatMessage({
375
- id: "S3pjKw",
376
- defaultMessage: [{
377
- "type": 0,
378
- "value": "Minimum "
379
- }, {
380
- "type": 1,
381
- "value": "value"
382
- }, {
383
- "type": 0,
384
- "value": " characters"
385
- }]
386
- }, {
387
- value: 6
388
- })),
389
- password: yup3.string().required(intl.formatMessage({
390
- id: "kdFYba",
391
- defaultMessage: [{
392
- "type": 0,
393
- "value": "Password field is required"
394
- }]
395
- })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
396
- id: "TZ4WUk",
397
- defaultMessage: [{
398
- "type": 0,
399
- "value": "Password requires "
400
- }, {
401
- "type": 1,
402
- "value": "value"
403
- }, {
404
- "type": 0,
405
- "value": " characters"
406
- }]
407
- }, {
408
- value: PASSWORD_MINIMUM_LENGTH
409
- })).trim(),
410
- confirmPassword: yup3.string().required(intl.formatMessage({
411
- id: "NJ57Qj",
412
- defaultMessage: [{
413
- "type": 0,
414
- "value": "Confirm password field is required"
415
- }]
416
- })).oneOf([yup3.ref("password")], intl.formatMessage({
417
- id: "WU/CqP",
418
- defaultMessage: [{
419
- "type": 0,
420
- "value": "Passwords are not the same"
421
- }]
422
- }))
423
- }).required();
424
- }, [intl]);
425
- const formMethods = useForm3({
426
- resolver: yupResolver3(schema),
427
- mode: "onBlur"
428
- });
429
- return /* @__PURE__ */jsx5(Form3, {
430
- ...formMethods,
431
- sx: {
432
- maxWidth: "390px"
433
- },
434
- onSubmit: ({
435
- code,
436
- password
437
- }) => {
438
- return onForgotPasswordResetPassword({
439
- email,
440
- code,
441
- newPassword: password
442
- });
443
- },
444
- children: /* @__PURE__ */jsxs3(AuthCard, {
445
- buttonLabel: intl.formatMessage({
446
- id: "mZzmNV",
447
- defaultMessage: [{
448
- "type": 0,
449
- "value": "Recover Password"
450
- }]
451
- }),
452
- isValidForm: formMethods.formState.isValid,
453
- title: intl.formatMessage({
454
- id: "S4bbEj",
455
- defaultMessage: [{
456
- "type": 0,
457
- "value": "Recovering Password"
458
- }]
459
- }),
460
- extraButton: /* @__PURE__ */jsx5(Button3, {
461
- sx: {
462
- textAlign: "center",
463
- display: "initial"
464
- },
465
- variant: "secondary",
466
- onClick: onCancel,
467
- children: intl.formatMessage({
468
- id: "6PdOcy",
469
- defaultMessage: [{
470
- "type": 0,
471
- "value": "Cancel"
472
- }]
473
- })
474
- }),
475
- children: [/* @__PURE__ */jsx5(FormFieldInput3, {
476
- name: "code",
477
- label: intl.formatMessage({
478
- id: "42HafR",
479
- defaultMessage: [{
480
- "type": 0,
481
- "value": "Code"
482
- }]
483
- })
484
- }), /* @__PURE__ */jsx5(FormFieldPassword, {
485
- name: "password",
486
- label: intl.formatMessage({
487
- id: "PylVqx",
488
- defaultMessage: [{
489
- "type": 0,
490
- "value": "Password"
491
- }]
492
- })
493
- }), /* @__PURE__ */jsx5(FormFieldPassword, {
494
- name: "confirmPassword",
495
- label: intl.formatMessage({
496
- id: "lY+cuM",
497
- defaultMessage: [{
498
- "type": 0,
499
- "value": "Confirm password"
500
- }]
501
- })
502
- }), /* @__PURE__ */jsx5(NotificationsBox2, {})]
503
- })
504
- });
505
- };
506
-
507
- // src/AuthFullScreen.tsx
508
- import { Flex as Flex2 } from "@ttoss/ui";
509
- import { jsx as jsx6 } from "react/jsx-runtime";
510
- var AuthFullScreen = ({
511
- children
512
- }) => {
513
- return /* @__PURE__ */jsx6(Flex2, {
514
- sx: {
515
- height: "100vh",
516
- width: "100vw",
517
- justifyContent: "center",
518
- alignItems: "center",
519
- margin: 0,
520
- backgroundPosition: "center",
521
- backgroundRepeat: "no-repeat",
522
- backgroundSize: "cover"
523
- },
524
- children
525
- });
526
- };
527
-
528
- // src/AuthSignIn.tsx
529
- import * as React4 from "react";
530
- import { Button as Button4, Flex as Flex3, Link as Link2, Text as Text2 } from "@ttoss/ui";
531
- import { Form as Form4, FormFieldInput as FormFieldInput4, FormFieldPassword as FormFieldPassword2, useForm as useForm4, yup as yup4, yupResolver as yupResolver4 } from "@ttoss/forms";
532
- import { NotificationsBox as NotificationsBox3, useNotifications as useNotifications2 } from "@ttoss/react-notifications";
533
- import { useI18n as useI18n4 } from "@ttoss/react-i18n";
534
- import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
535
- var AuthSignIn = ({
536
- onSignIn,
537
- onSignUp,
538
- defaultValues,
539
- onForgotPassword
540
- }) => {
541
- const {
542
- intl
543
- } = useI18n4();
544
- const {
545
- setNotifications
546
- } = useNotifications2();
547
- React4.useEffect(() => {
548
- setNotifications(void 0);
549
- }, [setNotifications]);
550
- const schema = yup4.object().shape({
551
- email: yup4.string().required(intl.formatMessage({
552
- id: "d1YCuH",
553
- defaultMessage: [{
554
- "type": 0,
555
- "value": "Enter your email address"
556
- }]
557
- })).email(intl.formatMessage({
558
- id: "9cApwd",
559
- defaultMessage: [{
560
- "type": 0,
561
- "value": "Please, insert a valid e-mail"
562
- }]
563
- })),
564
- password: yup4.string().required(intl.formatMessage({
565
- id: "kdFYba",
566
- defaultMessage: [{
567
- "type": 0,
568
- "value": "Password field is required"
569
- }]
570
- })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
571
- id: "TZ4WUk",
572
- defaultMessage: [{
573
- "type": 0,
574
- "value": "Password requires "
575
- }, {
576
- "type": 1,
577
- "value": "value"
578
- }, {
579
- "type": 0,
580
- "value": " characters"
581
- }]
582
- }, {
583
- value: PASSWORD_MINIMUM_LENGTH
584
- })).trim()
585
- // remember: yup.boolean(),
586
- });
587
- const formMethods = useForm4({
588
- defaultValues,
589
- mode: "onBlur",
590
- resolver: yupResolver4(schema)
591
- });
592
- const onSubmitForm = data => {
593
- return onSignIn(data);
594
- };
595
- return /* @__PURE__ */jsx7(Form4, {
596
- sx: {
597
- maxWidth: "390px",
598
- width: "100%"
599
- },
600
- ...formMethods,
601
- onSubmit: onSubmitForm,
602
- children: /* @__PURE__ */jsxs4(AuthCard, {
603
- title: intl.formatMessage({
604
- id: "F2iS37",
605
- defaultMessage: [{
606
- "type": 0,
607
- "value": "Log in"
608
- }]
609
- }),
610
- buttonLabel: intl.formatMessage({
611
- id: "/J+02x",
612
- defaultMessage: [{
613
- "type": 0,
614
- "value": "Log in"
615
- }]
616
- }),
617
- isValidForm: formMethods.formState.isValid,
618
- extraButton: /* @__PURE__ */jsx7(Button4, {
619
- type: "button",
620
- variant: "secondary",
621
- sx: {
622
- textAlign: "center",
623
- display: "initial"
624
- },
625
- onClick: onSignUp,
626
- "aria-label": "sign-up",
627
- children: intl.formatMessage({
628
- id: "EZ3YF2",
629
- defaultMessage: [{
630
- "type": 0,
631
- "value": "Sign up"
632
- }]
633
- })
634
- }),
635
- children: [/* @__PURE__ */jsxs4(Flex3, {
636
- sx: {
637
- flexDirection: "column",
638
- gap: "xl"
639
- },
640
- children: [/* @__PURE__ */jsx7(FormFieldInput4, {
641
- name: "email",
642
- label: intl.formatMessage({
643
- id: "5E12mO",
644
- defaultMessage: [{
645
- "type": 0,
646
- "value": "Email"
647
- }]
648
- })
649
- }), /* @__PURE__ */jsx7(FormFieldPassword2, {
650
- name: "password",
651
- label: intl.formatMessage({
652
- id: "PylVqx",
653
- defaultMessage: [{
654
- "type": 0,
655
- "value": "Password"
656
- }]
657
- })
658
- })]
659
- }), /* @__PURE__ */jsx7(Flex3, {
660
- sx: {
661
- justifyContent: "space-between",
662
- marginTop: "lg"
663
- },
664
- children: /* @__PURE__ */jsx7(Text2, {
665
- sx: {
666
- marginLeft: "auto",
667
- cursor: "pointer"
668
- },
669
- as: Link2,
670
- onClick: onForgotPassword,
671
- children: intl.formatMessage({
672
- id: "BtK6KR",
673
- defaultMessage: [{
674
- "type": 0,
675
- "value": "Forgot password?"
676
- }]
677
- })
678
- })
679
- }), /* @__PURE__ */jsx7(NotificationsBox3, {})]
680
- })
681
- });
682
- };
683
-
684
- // src/AuthSignUp.tsx
685
- import * as React5 from "react";
686
- import { Flex as Flex4, Link as Link3, Text as Text3 } from "@ttoss/ui";
687
- import { Form as Form5, FormFieldInput as FormFieldInput5, FormFieldPassword as FormFieldPassword3, useForm as useForm5, yup as yup5, yupResolver as yupResolver5 } from "@ttoss/forms";
688
- import { NotificationsBox as NotificationsBox4, useNotifications as useNotifications3 } from "@ttoss/react-notifications";
689
- import { useI18n as useI18n5 } from "@ttoss/react-i18n";
690
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
691
- var AuthSignUp = ({
692
- onSignUp,
693
- onReturnToSignIn
694
- }) => {
695
- const {
696
- intl
697
- } = useI18n5();
698
- const {
699
- setNotifications
700
- } = useNotifications3();
701
- React5.useEffect(() => {
702
- setNotifications(void 0);
703
- }, [setNotifications]);
704
- const schema = yup5.object().shape({
705
- email: yup5.string().required(intl.formatMessage({
706
- id: "d1YCuH",
707
- defaultMessage: [{
708
- "type": 0,
709
- "value": "Enter your email address"
710
- }]
711
- })).email(intl.formatMessage({
712
- id: "OhDL0i",
713
- defaultMessage: [{
714
- "type": 0,
715
- "value": "Invalid email"
716
- }]
717
- })),
718
- password: yup5.string().required(intl.formatMessage({
719
- id: "kdFYba",
720
- defaultMessage: [{
721
- "type": 0,
722
- "value": "Password field is required"
723
- }]
724
- })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
725
- id: "TZ4WUk",
726
- defaultMessage: [{
727
- "type": 0,
728
- "value": "Password requires "
729
- }, {
730
- "type": 1,
731
- "value": "value"
732
- }, {
733
- "type": 0,
734
- "value": " characters"
735
- }]
736
- }, {
737
- value: PASSWORD_MINIMUM_LENGTH
738
- })).trim(),
739
- confirmPassword: yup5.string().required(intl.formatMessage({
740
- id: "NJ57Qj",
741
- defaultMessage: [{
742
- "type": 0,
743
- "value": "Confirm password field is required"
744
- }]
745
- })).oneOf([yup5.ref("password")], intl.formatMessage({
746
- id: "WU/CqP",
747
- defaultMessage: [{
748
- "type": 0,
749
- "value": "Passwords are not the same"
750
- }]
751
- }))
752
- });
753
- const formMethods = useForm5({
754
- mode: "all",
755
- resolver: yupResolver5(schema)
756
- });
757
- const onSubmitForm = data => {
758
- return onSignUp(data);
759
- };
760
- return /* @__PURE__ */jsx8(Form5, {
761
- sx: {
762
- maxWidth: "390px",
763
- width: "100%"
764
- },
765
- ...formMethods,
766
- onSubmit: onSubmitForm,
767
- children: /* @__PURE__ */jsxs5(AuthCard, {
768
- buttonLabel: intl.formatMessage({
769
- id: "URJDrG",
770
- defaultMessage: [{
771
- "type": 0,
772
- "value": "Sign up"
773
- }]
774
- }),
775
- title: intl.formatMessage({
776
- id: "oayEC3",
777
- defaultMessage: [{
778
- "type": 0,
779
- "value": "Sign up"
780
- }]
781
- }),
782
- isValidForm: formMethods.formState.isValid,
783
- extraButton: /* @__PURE__ */jsx8(Text3, {
784
- sx: {
785
- cursor: "pointer"
786
- },
787
- onClick: onReturnToSignIn,
788
- as: Link3,
789
- children: intl.formatMessage({
790
- id: "8GMUPk",
791
- defaultMessage: [{
792
- "type": 0,
793
- "value": "I'm already registered"
794
- }]
795
- })
796
- }),
797
- children: [/* @__PURE__ */jsxs5(Flex4, {
798
- sx: {
799
- flexDirection: "column",
800
- gap: "xl"
801
- },
802
- children: [/* @__PURE__ */jsx8(FormFieldInput5, {
803
- name: "email",
804
- label: intl.formatMessage({
805
- id: "5E12mO",
806
- defaultMessage: [{
807
- "type": 0,
808
- "value": "Email"
809
- }]
810
- })
811
- }), /* @__PURE__ */jsx8(FormFieldPassword3, {
812
- name: "password",
813
- label: intl.formatMessage({
814
- id: "PylVqx",
815
- defaultMessage: [{
816
- "type": 0,
817
- "value": "Password"
818
- }]
819
- })
820
- }), /* @__PURE__ */jsx8(FormFieldPassword3, {
821
- name: "confirmPassword",
822
- label: intl.formatMessage({
823
- id: "lY+cuM",
824
- defaultMessage: [{
825
- "type": 0,
826
- "value": "Confirm password"
827
- }]
828
- })
829
- })]
830
- }), /* @__PURE__ */jsx8(NotificationsBox4, {})]
831
- })
832
- });
833
- };
834
-
835
- // src/Auth.tsx
836
- import { assign, createMachine } from "xstate";
837
- import { confirmResetPassword, confirmSignUp, resendSignUpCode, resetPassword, signIn, signUp } from "aws-amplify/auth";
838
- import { useMachine } from "@xstate/react";
839
- import { useNotifications as useNotifications4 } from "@ttoss/react-notifications";
840
- import { jsx as jsx9 } from "react/jsx-runtime";
841
- var authMachine = createMachine({
842
- predictableActionArguments: true,
843
- initial: "signIn",
844
- states: {
845
- signIn: {
846
- on: {
847
- SIGN_UP: {
848
- target: "signUp"
849
- },
850
- SIGN_UP_RESEND_CONFIRMATION: {
851
- actions: ["assignEmail"],
852
- target: "signUpConfirm"
853
- },
854
- FORGOT_PASSWORD: {
855
- target: "forgotPassword"
856
- }
857
- }
858
- },
859
- signUp: {
860
- on: {
861
- SIGN_UP_CONFIRM: {
862
- actions: ["assignEmail"],
863
- target: "signUpConfirm"
864
- },
865
- RETURN_TO_SIGN_IN: {
866
- target: "signIn"
867
- }
868
- }
869
- },
870
- signUpConfirm: {
871
- on: {
872
- SIGN_UP_CONFIRMED: {
873
- actions: ["assignEmail"],
874
- target: "signIn"
875
- }
876
- }
877
- },
878
- forgotPassword: {
879
- on: {
880
- RETURN_TO_SIGN_IN: {
881
- target: "signIn"
882
- },
883
- SIGN_UP: {
884
- target: "signUp"
885
- },
886
- FORGOT_PASSWORD_RESET_PASSWORD: {
887
- actions: ["assignEmail"],
888
- target: "forgotPasswordResetPassword"
889
- }
890
- }
891
- },
892
- forgotPasswordResetPassword: {
893
- on: {
894
- FORGOT_PASSWORD_CONFIRMED: {
895
- actions: ["assignEmail"],
896
- target: "signIn"
897
- },
898
- RETURN_TO_SIGN_IN: {
899
- target: "signIn"
900
- }
901
- }
902
- }
903
- }
904
- }, {
905
- actions: {
906
- assignEmail: assign({
907
- email: (_, event) => {
908
- if ("email" in event) {
909
- return event.email;
910
- }
911
- return void 0;
912
- }
913
- })
914
- }
915
- });
916
- var AuthLogic = () => {
917
- const {
918
- isAuthenticated
919
- } = useAuth();
920
- const [state, send] = useMachine(authMachine);
921
- const {
922
- setLoading,
923
- setNotifications
924
- } = useNotifications4();
925
- const onSignIn = React6.useCallback(async ({
926
- email,
927
- password
928
- }) => {
929
- try {
930
- setLoading(true);
931
- await signIn({
932
- username: email,
933
- password
934
- });
935
- } catch (error) {
936
- switch (error.code) {
937
- case "UserNotConfirmedException":
938
- await resendSignUpCode({
939
- username: email
940
- });
941
- send({
942
- type: "SIGN_UP_RESEND_CONFIRMATION",
943
- email
944
- });
945
- break;
946
- default:
947
- }
948
- setNotifications({
949
- type: "error",
950
- message: error.message
951
- });
952
- } finally {
953
- setLoading(false);
954
- }
955
- }, [send, setLoading, setNotifications]);
956
- const onSignUp = React6.useCallback(async ({
957
- email,
958
- password
959
- }) => {
960
- try {
961
- setLoading(true);
962
- await signUp({
963
- username: email,
964
- password,
965
- options: {
966
- userAttributes: {
967
- email
968
- }
969
- }
970
- });
971
- send({
972
- type: "SIGN_UP_CONFIRM",
973
- email
974
- });
975
- } catch (error) {
976
- setNotifications({
977
- type: "error",
978
- message: error.message
979
- });
980
- } finally {
981
- setLoading(false);
982
- }
983
- }, [send, setLoading, setNotifications]);
984
- const onConfirmSignUp = React6.useCallback(async ({
985
- email,
986
- code
987
- }) => {
988
- try {
989
- setLoading(true);
990
- await confirmSignUp({
991
- confirmationCode: code,
992
- username: email
993
- });
994
- send({
995
- type: "SIGN_UP_CONFIRMED",
996
- email
997
- });
998
- } catch (error) {
999
- setNotifications({
1000
- type: "error",
1001
- message: error.message
1002
- });
1003
- } finally {
1004
- setLoading(false);
1005
- }
1006
- }, [send, setLoading, setNotifications]);
1007
- const onReturnToSignIn = React6.useCallback(() => {
1008
- send({
1009
- type: "RETURN_TO_SIGN_IN"
1010
- });
1011
- }, [send]);
1012
- const onForgotPassword = React6.useCallback(async ({
1013
- email
1014
- }) => {
1015
- try {
1016
- setLoading(true);
1017
- await resetPassword({
1018
- username: email
1019
- });
1020
- send({
1021
- type: "FORGOT_PASSWORD_RESET_PASSWORD",
1022
- email
1023
- });
1024
- } catch (error) {
1025
- setNotifications({
1026
- type: "error",
1027
- message: error.message
1028
- });
1029
- } finally {
1030
- setLoading(false);
1031
- }
1032
- }, [send, setLoading, setNotifications]);
1033
- const onForgotPasswordResetPassword = React6.useCallback(async ({
1034
- email,
1035
- code,
1036
- newPassword
1037
- }) => {
1038
- try {
1039
- setLoading(true);
1040
- await confirmResetPassword({
1041
- confirmationCode: code,
1042
- username: email,
1043
- newPassword
1044
- });
1045
- send({
1046
- type: "FORGOT_PASSWORD_CONFIRMED",
1047
- email
1048
- });
1049
- } catch (error) {
1050
- setNotifications({
1051
- type: "error",
1052
- message: error.message
1053
- });
1054
- } finally {
1055
- setLoading(false);
1056
- }
1057
- }, [send, setLoading, setNotifications]);
1058
- if (isAuthenticated) {
1059
- return null;
1060
- }
1061
- if (state.matches("signUp")) {
1062
- return /* @__PURE__ */jsx9(AuthSignUp, {
1063
- onSignUp,
1064
- onReturnToSignIn
1065
- });
1066
- }
1067
- if (state.matches("signUpConfirm")) {
1068
- return /* @__PURE__ */jsx9(AuthConfirmSignUp, {
1069
- onConfirmSignUp,
1070
- email: state.context.email
1071
- });
1072
- }
1073
- if (state.matches("forgotPassword")) {
1074
- return /* @__PURE__ */jsx9(AuthForgotPassword, {
1075
- onForgotPassword,
1076
- onCancel: onReturnToSignIn,
1077
- onSignUp: () => {
1078
- return send("SIGN_UP");
1079
- }
1080
- });
1081
- }
1082
- if (state.matches("forgotPasswordResetPassword")) {
1083
- return /* @__PURE__ */jsx9(AuthForgotPasswordResetPassword, {
1084
- email: state.context.email,
1085
- onForgotPasswordResetPassword,
1086
- onCancel: onReturnToSignIn
1087
- });
1088
- }
1089
- return /* @__PURE__ */jsx9(AuthSignIn, {
1090
- onSignIn,
1091
- onSignUp: () => {
1092
- return send("SIGN_UP");
1093
- },
1094
- onForgotPassword: () => {
1095
- return send("FORGOT_PASSWORD");
1096
- },
1097
- defaultValues: {
1098
- email: state.context.email
1099
- }
1100
- });
1101
- };
1102
- var Auth = ({
1103
- logo,
1104
- fullScreen = true
1105
- }) => {
1106
- const withLogoNode = React6.useMemo(() => {
1107
- return /* @__PURE__ */jsx9(LogoProvider, {
1108
- logo,
1109
- children: /* @__PURE__ */jsx9(AuthLogic, {})
1110
- });
1111
- }, [logo]);
1112
- if (fullScreen) {
1113
- return /* @__PURE__ */jsx9(AuthFullScreen, {
1114
- children: withLogoNode
1115
- });
1116
- }
1117
- return withLogoNode;
1118
- };
1119
- export { Auth, AuthProvider, useAuth };
package/dist/index.d.ts DELETED
@@ -1,58 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import * as React from 'react';
3
-
4
- type User = {
5
- id: string;
6
- email: string;
7
- emailVerified: string;
8
- } | null;
9
- type Tokens = {
10
- idToken: string;
11
- accessToken: string;
12
- refreshToken: string;
13
- } | null;
14
- declare const AuthProvider: ({ children }: {
15
- children: React.ReactNode;
16
- }) => react_jsx_runtime.JSX.Element | null;
17
- declare const useAuth: () => {
18
- signOut: () => Promise<any>;
19
- isAuthenticated: boolean;
20
- user: User;
21
- tokens: Tokens;
22
- };
23
-
24
- type LogoContextProps = {
25
- logo?: React.ReactNode;
26
- children?: React.ReactNode;
27
- };
28
-
29
- type AuthProps = LogoContextProps & {
30
- fullScreen?: boolean;
31
- };
32
- declare const Auth: ({ logo, fullScreen }: AuthProps) => react_jsx_runtime.JSX.Element;
33
-
34
- type OnSignInInput = {
35
- email: string;
36
- password: string;
37
- };
38
- type OnSignIn = (input: OnSignInInput) => void;
39
- type OnSignUpInput = {
40
- email: string;
41
- password: string;
42
- confirmPassword: string;
43
- };
44
- type OnSignUp = (input: OnSignUpInput) => void;
45
- type OnConfirmSignUp = (input: {
46
- email: string;
47
- code: string;
48
- }) => void;
49
- type OnForgotPassword = (input: {
50
- email: string;
51
- }) => void;
52
- type OnForgotPasswordResetPassword = (input: {
53
- email: string;
54
- code: string;
55
- newPassword: string;
56
- }) => void;
57
-
58
- export { Auth, AuthProvider, type OnConfirmSignUp, type OnForgotPassword, type OnForgotPasswordResetPassword, type OnSignIn, type OnSignInInput, type OnSignUp, type OnSignUpInput, useAuth };
@@ -1,228 +0,0 @@
1
- {
2
- "/J+02x": [
3
- {
4
- "type": 0,
5
- "value": "Log in"
6
- }
7
- ],
8
- "0XOzcH": [
9
- {
10
- "type": 0,
11
- "value": "Required field"
12
- }
13
- ],
14
- "42HafR": [
15
- {
16
- "type": 0,
17
- "value": "Code"
18
- }
19
- ],
20
- "5E12mO": [
21
- {
22
- "type": 0,
23
- "value": "Email"
24
- }
25
- ],
26
- "5oOshZ": [
27
- {
28
- "type": 0,
29
- "value": "Enter your email address"
30
- }
31
- ],
32
- "6PdOcy": [
33
- {
34
- "type": 0,
35
- "value": "Cancel"
36
- }
37
- ],
38
- "8GMUPk": [
39
- {
40
- "type": 0,
41
- "value": "I'm already registered"
42
- }
43
- ],
44
- "9cApwd": [
45
- {
46
- "type": 0,
47
- "value": "Please, insert a valid e-mail"
48
- }
49
- ],
50
- "BtK6KR": [
51
- {
52
- "type": 0,
53
- "value": "Forgot password?"
54
- }
55
- ],
56
- "D1C6fR": [
57
- {
58
- "type": 0,
59
- "value": "Field must be at least "
60
- },
61
- {
62
- "type": 1,
63
- "value": "min"
64
- },
65
- {
66
- "type": 0,
67
- "value": " characters"
68
- }
69
- ],
70
- "EZ3YF2": [
71
- {
72
- "type": 0,
73
- "value": "Sign up"
74
- }
75
- ],
76
- "F2iS37": [
77
- {
78
- "type": 0,
79
- "value": "Log in"
80
- }
81
- ],
82
- "KY2T6J": [
83
- {
84
- "type": 0,
85
- "value": "Code"
86
- }
87
- ],
88
- "MfWGyg": [
89
- {
90
- "type": 0,
91
- "value": "Field is required"
92
- }
93
- ],
94
- "NJ57Qj": [
95
- {
96
- "type": 0,
97
- "value": "Confirm password field is required"
98
- }
99
- ],
100
- "OhDL0i": [
101
- {
102
- "type": 0,
103
- "value": "Invalid email"
104
- }
105
- ],
106
- "PylVqx": [
107
- {
108
- "type": 0,
109
- "value": "Password"
110
- }
111
- ],
112
- "S3pjKw": [
113
- {
114
- "type": 0,
115
- "value": "Minimum "
116
- },
117
- {
118
- "type": 1,
119
- "value": "value"
120
- },
121
- {
122
- "type": 0,
123
- "value": " characters"
124
- }
125
- ],
126
- "S4bbEj": [
127
- {
128
- "type": 0,
129
- "value": "Recovering Password"
130
- }
131
- ],
132
- "SnONhb": [
133
- {
134
- "type": 0,
135
- "value": "Please, insert a valid e-mail"
136
- }
137
- ],
138
- "TZ4WUk": [
139
- {
140
- "type": 0,
141
- "value": "Password requires "
142
- },
143
- {
144
- "type": 1,
145
- "value": "value"
146
- },
147
- {
148
- "type": 0,
149
- "value": " characters"
150
- }
151
- ],
152
- "UNttd+": [
153
- {
154
- "type": 0,
155
- "value": "Confirm"
156
- }
157
- ],
158
- "URJDrG": [
159
- {
160
- "type": 0,
161
- "value": "Sign up"
162
- }
163
- ],
164
- "WU/CqP": [
165
- {
166
- "type": 0,
167
- "value": "Passwords are not the same"
168
- }
169
- ],
170
- "XreZg+": [
171
- {
172
- "type": 0,
173
- "value": "Registered Email"
174
- }
175
- ],
176
- "ZhaPt0": [
177
- {
178
- "type": 0,
179
- "value": "Invalid Value for Field of type "
180
- },
181
- {
182
- "type": 1,
183
- "value": "type"
184
- }
185
- ],
186
- "cGR2eI": [
187
- {
188
- "type": 0,
189
- "value": "Confirmation"
190
- }
191
- ],
192
- "d1YCuH": [
193
- {
194
- "type": 0,
195
- "value": "Enter your email address"
196
- }
197
- ],
198
- "kdFYba": [
199
- {
200
- "type": 0,
201
- "value": "Password field is required"
202
- }
203
- ],
204
- "lY+cuM": [
205
- {
206
- "type": 0,
207
- "value": "Confirm password"
208
- }
209
- ],
210
- "lZvoYL": [
211
- {
212
- "type": 0,
213
- "value": "Sign up now"
214
- }
215
- ],
216
- "mZzmNV": [
217
- {
218
- "type": 0,
219
- "value": "Recover Password"
220
- }
221
- ],
222
- "oayEC3": [
223
- {
224
- "type": 0,
225
- "value": "Sign up"
226
- }
227
- ]
228
- }