@ttoss/react-auth 1.3.1 → 1.3.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.
Files changed (3) hide show
  1. package/dist/esm/index.js +530 -425
  2. package/dist/index.js +548 -432
  3. package/package.json +10 -10
package/dist/esm/index.js CHANGED
@@ -7,21 +7,30 @@ import { jsx } from "react/jsx-runtime";
7
7
  var signOut = () => {
8
8
  return Auth.signOut();
9
9
  };
10
- var AuthContext = React.createContext({
10
+ var AuthContext = /*#__PURE__*/React.createContext({
11
11
  signOut,
12
12
  isAuthenticated: false,
13
13
  user: null,
14
14
  tokens: null
15
15
  });
16
- var AuthProvider = ({ children }) => {
17
- const [{ user, tokens, isAuthenticated }, setAuthState] = React.useState({
16
+ var AuthProvider = ({
17
+ children
18
+ }) => {
19
+ const [{
20
+ user,
21
+ tokens,
22
+ isAuthenticated
23
+ }, setAuthState] = React.useState({
18
24
  user: null,
19
25
  tokens: null,
20
26
  isAuthenticated: void 0
21
27
  });
22
28
  React.useEffect(() => {
23
29
  const updateUser = () => {
24
- Auth.currentAuthenticatedUser().then(({ attributes, signInUserSession }) => {
30
+ Auth.currentAuthenticatedUser().then(({
31
+ attributes,
32
+ signInUserSession
33
+ }) => {
25
34
  setAuthState({
26
35
  user: {
27
36
  id: attributes.sub,
@@ -52,7 +61,15 @@ var AuthProvider = ({ children }) => {
52
61
  if (isAuthenticated === void 0) {
53
62
  return null;
54
63
  }
55
- return /* @__PURE__ */ jsx(AuthContext.Provider, { value: { signOut, isAuthenticated, user, tokens }, children });
64
+ return /* @__PURE__ */jsx(AuthContext.Provider, {
65
+ value: {
66
+ signOut,
67
+ isAuthenticated,
68
+ user,
69
+ tokens
70
+ },
71
+ children
72
+ });
56
73
  };
57
74
  var useAuth = () => {
58
75
  return React.useContext(AuthContext);
@@ -67,9 +84,15 @@ import * as React2 from "react";
67
84
  import { Button, Card, Flex, Link, Text } from "@ttoss/ui";
68
85
  import { useNotifications } from "@ttoss/react-notifications";
69
86
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
70
- var LogoContext = React2.createContext({});
71
- var LogoProvider = ({ children, ...values }) => {
72
- return /* @__PURE__ */ jsx2(LogoContext.Provider, { value: values, children });
87
+ var LogoContext = /*#__PURE__*/React2.createContext({});
88
+ var LogoProvider = ({
89
+ children,
90
+ ...values
91
+ }) => {
92
+ return /* @__PURE__ */jsx2(LogoContext.Provider, {
93
+ value: values,
94
+ children
95
+ });
73
96
  };
74
97
  var AuthCard = ({
75
98
  children,
@@ -77,33 +100,51 @@ var AuthCard = ({
77
100
  buttonLabel,
78
101
  links = []
79
102
  }) => {
80
- const { logo } = React2.useContext(LogoContext);
81
- const { isLoading } = useNotifications();
82
- return /* @__PURE__ */ jsx2(Card, { sx: { maxWidth: "564px" }, children: /* @__PURE__ */ jsxs(Flex, { sx: { flexDirection: "column", gap: 3 }, children: [
83
- logo && /* @__PURE__ */ jsx2(Flex, { sx: { width: "100%", justifyContent: "center" }, children: logo }),
84
- /* @__PURE__ */ jsx2(
85
- Text,
86
- {
103
+ const {
104
+ logo
105
+ } = React2.useContext(LogoContext);
106
+ const {
107
+ isLoading
108
+ } = useNotifications();
109
+ return /* @__PURE__ */jsx2(Card, {
110
+ sx: {
111
+ maxWidth: "564px"
112
+ },
113
+ children: /* @__PURE__ */jsxs(Flex, {
114
+ sx: {
115
+ flexDirection: "column",
116
+ gap: 3
117
+ },
118
+ children: [logo && /* @__PURE__ */jsx2(Flex, {
119
+ sx: {
120
+ width: "100%",
121
+ justifyContent: "center"
122
+ },
123
+ children: logo
124
+ }), /* @__PURE__ */jsx2(Text, {
87
125
  variant: "title",
88
- sx: { alignSelf: "center", marginY: 4, fontSize: 5 },
126
+ sx: {
127
+ alignSelf: "center",
128
+ marginY: 4,
129
+ fontSize: 5
130
+ },
89
131
  children: title
90
- }
91
- ),
92
- children,
93
- /* @__PURE__ */ jsx2(Flex, { sx: { justifyContent: "space-between", marginTop: 3 }, children: /* @__PURE__ */ jsx2(
94
- Button,
95
- {
96
- type: "submit",
97
- "aria-label": "submit-login",
98
- variant: "cta",
99
- disabled: isLoading,
100
- sx: { width: "100%" },
101
- children: buttonLabel
102
- }
103
- ) }),
104
- /* @__PURE__ */ jsx2(
105
- Flex,
106
- {
132
+ }), children, /* @__PURE__ */jsx2(Flex, {
133
+ sx: {
134
+ justifyContent: "space-between",
135
+ marginTop: 3
136
+ },
137
+ children: /* @__PURE__ */jsx2(Button, {
138
+ type: "submit",
139
+ "aria-label": "submit-login",
140
+ variant: "cta",
141
+ disabled: isLoading,
142
+ sx: {
143
+ width: "100%"
144
+ },
145
+ children: buttonLabel
146
+ })
147
+ }), /* @__PURE__ */jsx2(Flex, {
107
148
  sx: {
108
149
  justifyContent: "space-between",
109
150
  flexDirection: "column",
@@ -111,12 +152,15 @@ var AuthCard = ({
111
152
  marginTop: 4,
112
153
  color: "text"
113
154
  },
114
- children: links.map((link) => {
115
- return link && /* @__PURE__ */ jsx2(Link, { onClick: link.onClick, children: link.label }, link.label);
155
+ children: links.map(link => {
156
+ return link && /* @__PURE__ */jsx2(Link, {
157
+ onClick: link.onClick,
158
+ children: link.label
159
+ }, link.label);
116
160
  })
117
- }
118
- )
119
- ] }) });
161
+ })]
162
+ })
163
+ });
120
164
  };
121
165
 
122
166
  // src/AuthConfirmSignUp.tsx
@@ -127,81 +171,93 @@ var AuthConfirmSignUp = ({
127
171
  email,
128
172
  onConfirmSignUp
129
173
  }) => {
130
- const { intl } = useI18n();
174
+ const {
175
+ intl
176
+ } = useI18n();
131
177
  const schema = yup.object().shape({
132
- code: yup.string().required(
133
- intl.formatMessage({
134
- description: "Required field.",
135
- defaultMessage: "Required field"
136
- })
137
- ).max(
138
- 6,
139
- intl.formatMessage(
140
- {
141
- description: "Minimum {value} characters.",
142
- defaultMessage: "Minimum {value} characters"
143
- },
144
- { value: 6 }
145
- )
146
- )
178
+ code: yup.string().required(intl.formatMessage({
179
+ id: "0XOzcH",
180
+ defaultMessage: [{
181
+ "type": 0,
182
+ "value": "Required field"
183
+ }]
184
+ })).max(6, intl.formatMessage({
185
+ id: "S3pjKw",
186
+ defaultMessage: [{
187
+ "type": 0,
188
+ "value": "Minimum "
189
+ }, {
190
+ "type": 1,
191
+ "value": "value"
192
+ }, {
193
+ "type": 0,
194
+ "value": " characters"
195
+ }]
196
+ }, {
197
+ value: 6
198
+ }))
147
199
  }).required();
148
200
  const formMethods = useForm({
149
201
  resolver: yupResolver(schema)
150
202
  });
151
- return /* @__PURE__ */ jsx3(
152
- Form,
153
- {
154
- ...formMethods,
155
- onSubmit: ({ code }) => {
156
- return onConfirmSignUp({ code, email });
157
- },
158
- children: /* @__PURE__ */ jsx3(
159
- AuthCard,
160
- {
161
- buttonLabel: intl.formatMessage({
162
- description: "Confirm",
163
- defaultMessage: "Confirm"
164
- }),
165
- title: intl.formatMessage({
166
- description: "Confirmation",
167
- defaultMessage: "Confirmation"
168
- }),
169
- children: /* @__PURE__ */ jsx3(
170
- FormFieldInput,
171
- {
172
- name: "code",
173
- label: intl.formatMessage({
174
- description: "Sign up confirmation code",
175
- defaultMessage: "Code"
176
- })
177
- }
178
- )
179
- }
180
- )
181
- }
182
- );
203
+ return /* @__PURE__ */jsx3(Form, {
204
+ ...formMethods,
205
+ onSubmit: ({
206
+ code
207
+ }) => {
208
+ return onConfirmSignUp({
209
+ code,
210
+ email
211
+ });
212
+ },
213
+ children: /* @__PURE__ */jsx3(AuthCard, {
214
+ buttonLabel: intl.formatMessage({
215
+ id: "UNttd+",
216
+ defaultMessage: [{
217
+ "type": 0,
218
+ "value": "Confirm"
219
+ }]
220
+ }),
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
+ });
183
240
  };
184
241
 
185
242
  // src/AuthFullScreen.tsx
186
243
  import { Flex as Flex2 } from "@ttoss/ui";
187
244
  import { jsx as jsx4 } from "react/jsx-runtime";
188
- var AuthFullScreen = ({ children }) => {
189
- return /* @__PURE__ */ jsx4(
190
- Flex2,
191
- {
192
- sx: {
193
- height: "100vh",
194
- width: "100vw",
195
- justifyContent: "center",
196
- alignItems: "center",
197
- margin: 0,
198
- backgroundPosition: "center",
199
- backgroundRepeat: "no-repeat",
200
- backgroundSize: "cover"
201
- },
202
- children
203
- }
204
- );
245
+ var AuthFullScreen = ({
246
+ children
247
+ }) => {
248
+ return /* @__PURE__ */jsx4(Flex2, {
249
+ sx: {
250
+ height: "100vh",
251
+ width: "100vw",
252
+ justifyContent: "center",
253
+ alignItems: "center",
254
+ margin: 0,
255
+ backgroundPosition: "center",
256
+ backgroundRepeat: "no-repeat",
257
+ backgroundSize: "cover"
258
+ },
259
+ children
260
+ });
205
261
  };
206
262
 
207
263
  // src/AuthSignIn.tsx
@@ -271,7 +327,9 @@ var createAuthTemplate = ({
271
327
  },
272
328
  Export: {
273
329
  Name: {
274
- "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "Region"]]
330
+ "Fn::Join": [":", [{
331
+ Ref: "AWS::StackName"
332
+ }, "Region"]]
275
333
  }
276
334
  }
277
335
  },
@@ -282,7 +340,9 @@ var createAuthTemplate = ({
282
340
  },
283
341
  Export: {
284
342
  Name: {
285
- "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "UserPoolId"]]
343
+ "Fn::Join": [":", [{
344
+ Ref: "AWS::StackName"
345
+ }, "UserPoolId"]]
286
346
  }
287
347
  }
288
348
  },
@@ -293,14 +353,16 @@ var createAuthTemplate = ({
293
353
  },
294
354
  Export: {
295
355
  Name: {
296
- "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "AppClientId"]]
356
+ "Fn::Join": [":", [{
357
+ Ref: "AWS::StackName"
358
+ }, "AppClientId"]]
297
359
  }
298
360
  }
299
361
  }
300
362
  }
301
363
  };
302
364
  if (schema) {
303
- const Schema = schema.map((attribute) => {
365
+ const Schema = schema.map(attribute => {
304
366
  let NumberAttributeConstraints = void 0;
305
367
  if (attribute.numberAttributeConstraints) {
306
368
  NumberAttributeConstraints = {
@@ -332,16 +394,14 @@ var createAuthTemplate = ({
332
394
  Type: "AWS::Cognito::IdentityPool",
333
395
  Properties: {
334
396
  AllowUnauthenticatedIdentities: true,
335
- CognitoIdentityProviders: [
336
- {
337
- ClientId: {
338
- Ref: CognitoUserPoolClientLogicalId
339
- },
340
- ProviderName: {
341
- "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
342
- }
397
+ CognitoIdentityProviders: [{
398
+ ClientId: {
399
+ Ref: CognitoUserPoolClientLogicalId
400
+ },
401
+ ProviderName: {
402
+ "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
343
403
  }
344
- ]
404
+ }]
345
405
  }
346
406
  };
347
407
  template.Resources[IdentityPoolAuthenticatedIAMRoleLogicalId] = {
@@ -349,35 +409,31 @@ var createAuthTemplate = ({
349
409
  Properties: {
350
410
  AssumeRolePolicyDocument: {
351
411
  Version: "2012-10-17",
352
- Statement: [
353
- {
354
- Effect: "Allow",
355
- Principal: {
356
- Federated: "cognito-identity.amazonaws.com"
357
- },
358
- Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
359
- Condition: {
360
- StringEquals: {
361
- "cognito-identity.amazonaws.com:aud": {
362
- Ref: CognitoIdentityPoolLogicalId
363
- }
364
- },
365
- "ForAnyValue:StringLike": {
366
- "cognito-identity.amazonaws.com:amr": "authenticated"
412
+ Statement: [{
413
+ Effect: "Allow",
414
+ Principal: {
415
+ Federated: "cognito-identity.amazonaws.com"
416
+ },
417
+ Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
418
+ Condition: {
419
+ StringEquals: {
420
+ "cognito-identity.amazonaws.com:aud": {
421
+ Ref: CognitoIdentityPoolLogicalId
367
422
  }
423
+ },
424
+ "ForAnyValue:StringLike": {
425
+ "cognito-identity.amazonaws.com:amr": "authenticated"
368
426
  }
369
427
  }
370
- ]
428
+ }]
371
429
  },
372
- Policies: identityPool.authenticatedPolicies || [
373
- {
374
- PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
375
- PolicyDocument: {
376
- Version: "2012-10-17",
377
- Statement: [DenyStatement]
378
- }
430
+ Policies: identityPool.authenticatedPolicies || [{
431
+ PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
432
+ PolicyDocument: {
433
+ Version: "2012-10-17",
434
+ Statement: [DenyStatement]
379
435
  }
380
- ]
436
+ }]
381
437
  }
382
438
  };
383
439
  template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
@@ -385,35 +441,31 @@ var createAuthTemplate = ({
385
441
  Properties: {
386
442
  AssumeRolePolicyDocument: {
387
443
  Version: "2012-10-17",
388
- Statement: [
389
- {
390
- Effect: "Allow",
391
- Principal: {
392
- Federated: "cognito-identity.amazonaws.com"
393
- },
394
- Action: "sts:AssumeRoleWithWebIdentity",
395
- Condition: {
396
- StringEquals: {
397
- "cognito-identity.amazonaws.com:aud": {
398
- Ref: CognitoIdentityPoolLogicalId
399
- }
400
- },
401
- "ForAnyValue:StringLike": {
402
- "cognito-identity.amazonaws.com:amr": "unauthenticated"
444
+ Statement: [{
445
+ Effect: "Allow",
446
+ Principal: {
447
+ Federated: "cognito-identity.amazonaws.com"
448
+ },
449
+ Action: "sts:AssumeRoleWithWebIdentity",
450
+ Condition: {
451
+ StringEquals: {
452
+ "cognito-identity.amazonaws.com:aud": {
453
+ Ref: CognitoIdentityPoolLogicalId
403
454
  }
455
+ },
456
+ "ForAnyValue:StringLike": {
457
+ "cognito-identity.amazonaws.com:amr": "unauthenticated"
404
458
  }
405
459
  }
406
- ]
460
+ }]
407
461
  },
408
- Policies: identityPool.authenticatedPolicies || [
409
- {
410
- PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
411
- PolicyDocument: {
412
- Version: "2012-10-17",
413
- Statement: [DenyStatement]
414
- }
462
+ Policies: identityPool.authenticatedPolicies || [{
463
+ PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
464
+ PolicyDocument: {
465
+ Version: "2012-10-17",
466
+ Statement: [DenyStatement]
415
467
  }
416
- ]
468
+ }]
417
469
  }
418
470
  };
419
471
  template.Resources.CognitoIdentityPoolRoleAttachment = {
@@ -442,10 +494,9 @@ var createAuthTemplate = ({
442
494
  },
443
495
  Export: {
444
496
  Name: {
445
- "Fn::Join": [
446
- ":",
447
- [{ Ref: "AWS::StackName" }, "CognitoIdentityPoolId"]
448
- ]
497
+ "Fn::Join": [":", [{
498
+ Ref: "AWS::StackName"
499
+ }, "CognitoIdentityPoolId"]]
449
500
  }
450
501
  }
451
502
  };
@@ -464,179 +515,214 @@ var AuthSignIn = ({
464
515
  onSignUp,
465
516
  defaultValues
466
517
  }) => {
467
- const { intl } = useI18n2();
518
+ const {
519
+ intl
520
+ } = useI18n2();
468
521
  const schema = yup2.object().shape({
469
- email: yup2.string().required(
470
- intl.formatMessage({
471
- description: "Email is a required field.",
472
- defaultMessage: "Email field is required"
473
- })
474
- ).email(
475
- intl.formatMessage({
476
- description: "Invalid email.",
477
- defaultMessage: "Invalid email"
478
- })
479
- ),
480
- password: yup2.string().required(
481
- intl.formatMessage({
482
- description: "Password is required.",
483
- defaultMessage: "Password field is required"
484
- })
485
- ).min(
486
- PASSWORD_MINIMUM_LENGTH,
487
- intl.formatMessage(
488
- {
489
- description: "Password must be at least {value} characters long.",
490
- defaultMessage: "Password requires {value} characters"
491
- },
492
- { value: PASSWORD_MINIMUM_LENGTH }
493
- )
494
- ).trim()
522
+ email: yup2.string().required(intl.formatMessage({
523
+ id: "r+QgO+",
524
+ defaultMessage: [{
525
+ "type": 0,
526
+ "value": "Email field is required"
527
+ }]
528
+ })).email(intl.formatMessage({
529
+ id: "OhDL0i",
530
+ defaultMessage: [{
531
+ "type": 0,
532
+ "value": "Invalid email"
533
+ }]
534
+ })),
535
+ password: yup2.string().required(intl.formatMessage({
536
+ id: "kdFYba",
537
+ defaultMessage: [{
538
+ "type": 0,
539
+ "value": "Password field is required"
540
+ }]
541
+ })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
542
+ id: "TZ4WUk",
543
+ defaultMessage: [{
544
+ "type": 0,
545
+ "value": "Password requires "
546
+ }, {
547
+ "type": 1,
548
+ "value": "value"
549
+ }, {
550
+ "type": 0,
551
+ "value": " characters"
552
+ }]
553
+ }, {
554
+ value: PASSWORD_MINIMUM_LENGTH
555
+ })).trim()
495
556
  });
496
557
  const formMethods = useForm2({
497
558
  defaultValues,
498
559
  resolver: yupResolver2(schema)
499
560
  });
500
- const onSubmitForm = (data) => {
561
+ const onSubmitForm = data => {
501
562
  return onSignIn(data);
502
563
  };
503
- return /* @__PURE__ */ jsx5(Form2, { ...formMethods, onSubmit: onSubmitForm, children: /* @__PURE__ */ jsxs2(
504
- AuthCard,
505
- {
564
+ return /* @__PURE__ */jsx5(Form2, {
565
+ ...formMethods,
566
+ onSubmit: onSubmitForm,
567
+ children: /* @__PURE__ */jsxs2(AuthCard, {
506
568
  title: intl.formatMessage({
507
- description: "Sign in title.",
508
- defaultMessage: "Login"
569
+ id: "R1rFNQ",
570
+ defaultMessage: [{
571
+ "type": 0,
572
+ "value": "Login"
573
+ }]
509
574
  }),
510
575
  buttonLabel: intl.formatMessage({
511
- description: "Button label.",
512
- defaultMessage: "Login"
576
+ id: "0cVgsc",
577
+ defaultMessage: [{
578
+ "type": 0,
579
+ "value": "Login"
580
+ }]
513
581
  }),
514
- links: [
515
- {
516
- onClick: onSignUp,
517
- label: intl.formatMessage({
518
- description: "Link to retrieve password.",
519
- defaultMessage: "Do you forgot your password?"
520
- })
521
- },
522
- {
523
- onClick: onSignUp,
524
- label: intl.formatMessage({
525
- description: "Link to sign up.",
526
- defaultMessage: "Don't have an account? Sign up"
527
- })
528
- }
529
- ],
530
- children: [
531
- /* @__PURE__ */ jsx5(
532
- FormFieldInput2,
533
- {
534
- name: "email",
535
- label: intl.formatMessage({
536
- description: "Email label.",
537
- defaultMessage: "Email"
538
- })
539
- }
540
- ),
541
- /* @__PURE__ */ jsx5(
542
- FormFieldInput2,
543
- {
544
- name: "password",
545
- label: intl.formatMessage({
546
- description: "Password label.",
547
- defaultMessage: "Password"
548
- })
549
- }
550
- )
551
- ]
552
- }
553
- ) });
582
+ links: [{
583
+ onClick: onSignUp,
584
+ label: intl.formatMessage({
585
+ id: "z5s0vm",
586
+ defaultMessage: [{
587
+ "type": 0,
588
+ "value": "Do you forgot your password?"
589
+ }]
590
+ })
591
+ }, {
592
+ onClick: onSignUp,
593
+ label: intl.formatMessage({
594
+ id: "XC1w2U",
595
+ defaultMessage: [{
596
+ "type": 0,
597
+ "value": "Don't have an account? Sign up"
598
+ }]
599
+ })
600
+ }],
601
+ children: [/* @__PURE__ */jsx5(FormFieldInput2, {
602
+ name: "email",
603
+ label: intl.formatMessage({
604
+ id: "5E12mO",
605
+ defaultMessage: [{
606
+ "type": 0,
607
+ "value": "Email"
608
+ }]
609
+ })
610
+ }), /* @__PURE__ */jsx5(FormFieldInput2, {
611
+ name: "password",
612
+ label: intl.formatMessage({
613
+ id: "PylVqx",
614
+ defaultMessage: [{
615
+ "type": 0,
616
+ "value": "Password"
617
+ }]
618
+ })
619
+ })]
620
+ })
621
+ });
554
622
  };
555
623
 
556
624
  // src/AuthSignUp.tsx
557
625
  import { Form as Form3, FormFieldInput as FormFieldInput3, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
558
626
  import { useI18n as useI18n3 } from "@ttoss/react-i18n";
559
627
  import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
560
- var AuthSignUp = ({ onSignUp, onReturnToSignIn }) => {
561
- const { intl } = useI18n3();
628
+ var AuthSignUp = ({
629
+ onSignUp,
630
+ onReturnToSignIn
631
+ }) => {
632
+ const {
633
+ intl
634
+ } = useI18n3();
562
635
  const schema = yup3.object().shape({
563
- email: yup3.string().required(
564
- intl.formatMessage({
565
- description: "Email is a required field.",
566
- defaultMessage: "Email field is required"
567
- })
568
- ).email(
569
- intl.formatMessage({
570
- description: "Invalid email.",
571
- defaultMessage: "Invalid email"
572
- })
573
- ),
574
- password: yup3.string().required(
575
- intl.formatMessage({
576
- description: "Password is required.",
577
- defaultMessage: "Password field is required"
578
- })
579
- ).min(
580
- PASSWORD_MINIMUM_LENGTH,
581
- intl.formatMessage(
582
- {
583
- description: "Password must be at least {value} characters long.",
584
- defaultMessage: "Password requires {value} characters"
585
- },
586
- { value: PASSWORD_MINIMUM_LENGTH }
587
- )
588
- ).trim()
636
+ email: yup3.string().required(intl.formatMessage({
637
+ id: "r+QgO+",
638
+ defaultMessage: [{
639
+ "type": 0,
640
+ "value": "Email field is required"
641
+ }]
642
+ })).email(intl.formatMessage({
643
+ id: "OhDL0i",
644
+ defaultMessage: [{
645
+ "type": 0,
646
+ "value": "Invalid email"
647
+ }]
648
+ })),
649
+ password: yup3.string().required(intl.formatMessage({
650
+ id: "kdFYba",
651
+ defaultMessage: [{
652
+ "type": 0,
653
+ "value": "Password field is required"
654
+ }]
655
+ })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
656
+ id: "TZ4WUk",
657
+ defaultMessage: [{
658
+ "type": 0,
659
+ "value": "Password requires "
660
+ }, {
661
+ "type": 1,
662
+ "value": "value"
663
+ }, {
664
+ "type": 0,
665
+ "value": " characters"
666
+ }]
667
+ }, {
668
+ value: PASSWORD_MINIMUM_LENGTH
669
+ })).trim()
589
670
  });
590
671
  const formMethods = useForm3({
591
672
  resolver: yupResolver3(schema)
592
673
  });
593
- const onSubmitForm = (data) => {
674
+ const onSubmitForm = data => {
594
675
  return onSignUp(data);
595
676
  };
596
- return /* @__PURE__ */ jsx6(Form3, { ...formMethods, onSubmit: onSubmitForm, children: /* @__PURE__ */ jsxs3(
597
- AuthCard,
598
- {
677
+ return /* @__PURE__ */jsx6(Form3, {
678
+ ...formMethods,
679
+ onSubmit: onSubmitForm,
680
+ children: /* @__PURE__ */jsxs3(AuthCard, {
599
681
  buttonLabel: intl.formatMessage({
600
- description: "Create account.",
601
- defaultMessage: "Create account"
682
+ id: "Pdio77",
683
+ defaultMessage: [{
684
+ "type": 0,
685
+ "value": "Create account"
686
+ }]
602
687
  }),
603
688
  title: intl.formatMessage({
604
- description: "Title on sign up.",
605
- defaultMessage: "Register"
689
+ id: "EXZxA0",
690
+ defaultMessage: [{
691
+ "type": 0,
692
+ "value": "Register"
693
+ }]
606
694
  }),
607
- links: [
608
- {
609
- label: intl.formatMessage({
610
- description: "Link to sign in on sign up.",
611
- defaultMessage: "Do you already have an account? Sign in"
612
- }),
613
- onClick: onReturnToSignIn
614
- }
615
- ],
616
- children: [
617
- /* @__PURE__ */ jsx6(
618
- FormFieldInput3,
619
- {
620
- name: "email",
621
- label: intl.formatMessage({
622
- description: "Email label.",
623
- defaultMessage: "Email"
624
- })
625
- }
626
- ),
627
- /* @__PURE__ */ jsx6(
628
- FormFieldInput3,
629
- {
630
- name: "password",
631
- label: intl.formatMessage({
632
- description: "Password label.",
633
- defaultMessage: "Password"
634
- })
635
- }
636
- )
637
- ]
638
- }
639
- ) });
695
+ links: [{
696
+ label: intl.formatMessage({
697
+ id: "LU2ddR",
698
+ defaultMessage: [{
699
+ "type": 0,
700
+ "value": "Do you already have an account? Sign in"
701
+ }]
702
+ }),
703
+ onClick: onReturnToSignIn
704
+ }],
705
+ children: [/* @__PURE__ */jsx6(FormFieldInput3, {
706
+ name: "email",
707
+ label: intl.formatMessage({
708
+ id: "5E12mO",
709
+ defaultMessage: [{
710
+ "type": 0,
711
+ "value": "Email"
712
+ }]
713
+ })
714
+ }), /* @__PURE__ */jsx6(FormFieldInput3, {
715
+ name: "password",
716
+ label: intl.formatMessage({
717
+ id: "PylVqx",
718
+ defaultMessage: [{
719
+ "type": 0,
720
+ "value": "Password"
721
+ }]
722
+ })
723
+ })]
724
+ })
725
+ });
640
726
  };
641
727
 
642
728
  // src/Auth.tsx
@@ -644,142 +730,161 @@ import { assign, createMachine } from "xstate";
644
730
  import { useMachine } from "@xstate/react";
645
731
  import { useNotifications as useNotifications2 } from "@ttoss/react-notifications";
646
732
  import { jsx as jsx7 } from "react/jsx-runtime";
647
- var authMachine = createMachine(
648
- {
649
- predictableActionArguments: true,
650
- initial: "signIn",
651
- states: {
652
- signIn: {
653
- on: {
654
- SIGN_UP: { target: "signUp" },
655
- SIGN_UP_RESEND_CONFIRMATION: {
656
- actions: ["assignEmail"],
657
- target: "signUpConfirm"
658
- }
659
- }
660
- },
661
- signUp: {
662
- on: {
663
- SIGN_UP_CONFIRM: {
664
- actions: ["assignEmail"],
665
- target: "signUpConfirm"
666
- },
667
- RETURN_TO_SIGN_IN: { target: "signIn" }
733
+ var authMachine = createMachine({
734
+ predictableActionArguments: true,
735
+ initial: "signIn",
736
+ states: {
737
+ signIn: {
738
+ on: {
739
+ SIGN_UP: {
740
+ target: "signUp"
741
+ },
742
+ SIGN_UP_RESEND_CONFIRMATION: {
743
+ actions: ["assignEmail"],
744
+ target: "signUpConfirm"
668
745
  }
669
- },
670
- signUpConfirm: {
671
- on: {
672
- SIGN_UP_CONFIRMED: {
673
- actions: ["assignEmail"],
674
- target: "signIn"
675
- }
746
+ }
747
+ },
748
+ signUp: {
749
+ on: {
750
+ SIGN_UP_CONFIRM: {
751
+ actions: ["assignEmail"],
752
+ target: "signUpConfirm"
753
+ },
754
+ RETURN_TO_SIGN_IN: {
755
+ target: "signIn"
676
756
  }
677
757
  }
678
- }
679
- },
680
- {
681
- actions: {
682
- assignEmail: assign({
683
- email: (_, event) => {
684
- return event.email;
758
+ },
759
+ signUpConfirm: {
760
+ on: {
761
+ SIGN_UP_CONFIRMED: {
762
+ actions: ["assignEmail"],
763
+ target: "signIn"
685
764
  }
686
- })
765
+ }
687
766
  }
688
767
  }
689
- );
768
+ }, {
769
+ actions: {
770
+ assignEmail: assign({
771
+ email: (_, event) => {
772
+ return event.email;
773
+ }
774
+ })
775
+ }
776
+ });
690
777
  var AuthLogic = () => {
691
- const { isAuthenticated } = useAuth();
778
+ const {
779
+ isAuthenticated
780
+ } = useAuth();
692
781
  const [state, send] = useMachine(authMachine);
693
- const { setLoading } = useNotifications2();
694
- const onSignIn = React3.useCallback(
695
- async ({ email, password }) => {
696
- try {
697
- setLoading(true);
698
- await AmplifyAuth.signIn(email, password);
699
- } catch (error) {
700
- switch (error.code) {
701
- case "UserNotConfirmedException":
702
- await AmplifyAuth.resendSignUp(email);
703
- send({ type: "SIGN_UP_RESEND_CONFIRMATION", email });
704
- break;
705
- default:
706
- }
707
- } finally {
708
- setLoading(false);
709
- }
710
- },
711
- [send, setLoading]
712
- );
713
- const onSignUp = React3.useCallback(
714
- async ({ email, password }) => {
715
- try {
716
- setLoading(true);
717
- await AmplifyAuth.signUp({
718
- username: email,
719
- password,
720
- attributes: { email }
721
- });
722
- send({ type: "SIGN_UP_CONFIRM", email });
723
- } catch (error) {
724
- } finally {
725
- setLoading(false);
726
- }
727
- },
728
- [send, setLoading]
729
- );
730
- const onConfirmSignUp = React3.useCallback(
731
- async ({ email, code }) => {
732
- try {
733
- setLoading(true);
734
- await AmplifyAuth.confirmSignUp(email, code);
735
- send({ type: "SIGN_UP_CONFIRMED", email });
736
- } catch (error) {
737
- } finally {
738
- setLoading(false);
782
+ const {
783
+ setLoading
784
+ } = useNotifications2();
785
+ const onSignIn = React3.useCallback(async ({
786
+ email,
787
+ password
788
+ }) => {
789
+ try {
790
+ setLoading(true);
791
+ await AmplifyAuth.signIn(email, password);
792
+ } catch (error) {
793
+ switch (error.code) {
794
+ case "UserNotConfirmedException":
795
+ await AmplifyAuth.resendSignUp(email);
796
+ send({
797
+ type: "SIGN_UP_RESEND_CONFIRMATION",
798
+ email
799
+ });
800
+ break;
801
+ default:
739
802
  }
740
- },
741
- [send, setLoading]
742
- );
803
+ } finally {
804
+ setLoading(false);
805
+ }
806
+ }, [send, setLoading]);
807
+ const onSignUp = React3.useCallback(async ({
808
+ email,
809
+ password
810
+ }) => {
811
+ try {
812
+ setLoading(true);
813
+ await AmplifyAuth.signUp({
814
+ username: email,
815
+ password,
816
+ attributes: {
817
+ email
818
+ }
819
+ });
820
+ send({
821
+ type: "SIGN_UP_CONFIRM",
822
+ email
823
+ });
824
+ } catch (error) {} finally {
825
+ setLoading(false);
826
+ }
827
+ }, [send, setLoading]);
828
+ const onConfirmSignUp = React3.useCallback(async ({
829
+ email,
830
+ code
831
+ }) => {
832
+ try {
833
+ setLoading(true);
834
+ await AmplifyAuth.confirmSignUp(email, code);
835
+ send({
836
+ type: "SIGN_UP_CONFIRMED",
837
+ email
838
+ });
839
+ } catch (error) {} finally {
840
+ setLoading(false);
841
+ }
842
+ }, [send, setLoading]);
743
843
  const onReturnToSignIn = React3.useCallback(() => {
744
- send({ type: "RETURN_TO_SIGN_IN" });
844
+ send({
845
+ type: "RETURN_TO_SIGN_IN"
846
+ });
745
847
  }, [send]);
746
848
  if (isAuthenticated) {
747
849
  return null;
748
850
  }
749
851
  if (state.matches("signUp")) {
750
- return /* @__PURE__ */ jsx7(AuthSignUp, { onSignUp, onReturnToSignIn });
852
+ return /* @__PURE__ */jsx7(AuthSignUp, {
853
+ onSignUp,
854
+ onReturnToSignIn
855
+ });
751
856
  }
752
857
  if (state.matches("signUpConfirm")) {
753
- return /* @__PURE__ */ jsx7(
754
- AuthConfirmSignUp,
755
- {
756
- onConfirmSignUp,
757
- email: state.context.email
758
- }
759
- );
858
+ return /* @__PURE__ */jsx7(AuthConfirmSignUp, {
859
+ onConfirmSignUp,
860
+ email: state.context.email
861
+ });
760
862
  }
761
- return /* @__PURE__ */ jsx7(
762
- AuthSignIn,
763
- {
764
- onSignIn,
765
- onSignUp: () => {
766
- return send("SIGN_UP");
767
- },
768
- defaultValues: { email: state.context.email }
863
+ return /* @__PURE__ */jsx7(AuthSignIn, {
864
+ onSignIn,
865
+ onSignUp: () => {
866
+ return send("SIGN_UP");
867
+ },
868
+ defaultValues: {
869
+ email: state.context.email
769
870
  }
770
- );
871
+ });
771
872
  };
772
- var Auth2 = ({ logo, fullScreen = true }) => {
873
+ var Auth2 = ({
874
+ logo,
875
+ fullScreen = true
876
+ }) => {
773
877
  const withLogoNode = React3.useMemo(() => {
774
- return /* @__PURE__ */ jsx7(LogoProvider, { logo, children: /* @__PURE__ */ jsx7(AuthLogic, {}) });
878
+ return /* @__PURE__ */jsx7(LogoProvider, {
879
+ logo,
880
+ children: /* @__PURE__ */jsx7(AuthLogic, {})
881
+ });
775
882
  }, [logo]);
776
883
  if (fullScreen) {
777
- return /* @__PURE__ */ jsx7(AuthFullScreen, { children: withLogoNode });
884
+ return /* @__PURE__ */jsx7(AuthFullScreen, {
885
+ children: withLogoNode
886
+ });
778
887
  }
779
888
  return withLogoNode;
780
889
  };
781
- export {
782
- Auth2 as Auth,
783
- AuthProvider,
784
- useAuth
785
- };
890
+ export { Auth2 as Auth, AuthProvider, useAuth };