@ttoss/react-auth 1.3.2 → 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/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
2
2
  "use strict";
3
+
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,26 +8,32 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getProtoOf = Object.getPrototypeOf;
8
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
10
  var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
12
15
  };
13
16
  var __copyProps = (to, from, except, desc) => {
14
17
  if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
18
22
  }
19
23
  return to;
20
24
  };
21
25
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
31
+ value: mod,
32
+ enumerable: true
33
+ }) : target, mod));
34
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
35
+ value: true
36
+ }), mod);
30
37
 
31
38
  // src/index.ts
32
39
  var src_exports = {};
@@ -50,15 +57,24 @@ var AuthContext = React.createContext({
50
57
  user: null,
51
58
  tokens: null
52
59
  });
53
- var AuthProvider = ({ children }) => {
54
- const [{ user, tokens, isAuthenticated }, setAuthState] = React.useState({
60
+ var AuthProvider = ({
61
+ children
62
+ }) => {
63
+ const [{
64
+ user,
65
+ tokens,
66
+ isAuthenticated
67
+ }, setAuthState] = React.useState({
55
68
  user: null,
56
69
  tokens: null,
57
70
  isAuthenticated: void 0
58
71
  });
59
72
  React.useEffect(() => {
60
73
  const updateUser = () => {
61
- import_aws_amplify.Auth.currentAuthenticatedUser().then(({ attributes, signInUserSession }) => {
74
+ import_aws_amplify.Auth.currentAuthenticatedUser().then(({
75
+ attributes,
76
+ signInUserSession
77
+ }) => {
62
78
  setAuthState({
63
79
  user: {
64
80
  id: attributes.sub,
@@ -89,7 +105,15 @@ var AuthProvider = ({ children }) => {
89
105
  if (isAuthenticated === void 0) {
90
106
  return null;
91
107
  }
92
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AuthContext.Provider, { value: { signOut, isAuthenticated, user, tokens }, children });
108
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(AuthContext.Provider, {
109
+ value: {
110
+ signOut,
111
+ isAuthenticated,
112
+ user,
113
+ tokens
114
+ },
115
+ children
116
+ });
93
117
  };
94
118
  var useAuth = () => {
95
119
  return React.useContext(AuthContext);
@@ -105,8 +129,14 @@ var import_ui = require("@ttoss/ui");
105
129
  var import_react_notifications = require("@ttoss/react-notifications");
106
130
  var import_jsx_runtime2 = require("react/jsx-runtime");
107
131
  var LogoContext = React2.createContext({});
108
- var LogoProvider = ({ children, ...values }) => {
109
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LogoContext.Provider, { value: values, children });
132
+ var LogoProvider = ({
133
+ children,
134
+ ...values
135
+ }) => {
136
+ return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(LogoContext.Provider, {
137
+ value: values,
138
+ children
139
+ });
110
140
  };
111
141
  var AuthCard = ({
112
142
  children,
@@ -114,33 +144,51 @@ var AuthCard = ({
114
144
  buttonLabel,
115
145
  links = []
116
146
  }) => {
117
- const { logo } = React2.useContext(LogoContext);
118
- const { isLoading } = (0, import_react_notifications.useNotifications)();
119
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Card, { sx: { maxWidth: "564px" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_ui.Flex, { sx: { flexDirection: "column", gap: 3 }, children: [
120
- logo && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Flex, { sx: { width: "100%", justifyContent: "center" }, children: logo }),
121
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
122
- import_ui.Text,
123
- {
147
+ const {
148
+ logo
149
+ } = React2.useContext(LogoContext);
150
+ const {
151
+ isLoading
152
+ } = (0, import_react_notifications.useNotifications)();
153
+ return /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Card, {
154
+ sx: {
155
+ maxWidth: "564px"
156
+ },
157
+ children: /* @__PURE__ */(0, import_jsx_runtime2.jsxs)(import_ui.Flex, {
158
+ sx: {
159
+ flexDirection: "column",
160
+ gap: 3
161
+ },
162
+ children: [logo && /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Flex, {
163
+ sx: {
164
+ width: "100%",
165
+ justifyContent: "center"
166
+ },
167
+ children: logo
168
+ }), /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Text, {
124
169
  variant: "title",
125
- sx: { alignSelf: "center", marginY: 4, fontSize: 5 },
170
+ sx: {
171
+ alignSelf: "center",
172
+ marginY: 4,
173
+ fontSize: 5
174
+ },
126
175
  children: title
127
- }
128
- ),
129
- children,
130
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Flex, { sx: { justifyContent: "space-between", marginTop: 3 }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
131
- import_ui.Button,
132
- {
133
- type: "submit",
134
- "aria-label": "submit-login",
135
- variant: "cta",
136
- disabled: isLoading,
137
- sx: { width: "100%" },
138
- children: buttonLabel
139
- }
140
- ) }),
141
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
142
- import_ui.Flex,
143
- {
176
+ }), children, /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Flex, {
177
+ sx: {
178
+ justifyContent: "space-between",
179
+ marginTop: 3
180
+ },
181
+ children: /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Button, {
182
+ type: "submit",
183
+ "aria-label": "submit-login",
184
+ variant: "cta",
185
+ disabled: isLoading,
186
+ sx: {
187
+ width: "100%"
188
+ },
189
+ children: buttonLabel
190
+ })
191
+ }), /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Flex, {
144
192
  sx: {
145
193
  justifyContent: "space-between",
146
194
  flexDirection: "column",
@@ -148,12 +196,15 @@ var AuthCard = ({
148
196
  marginTop: 4,
149
197
  color: "text"
150
198
  },
151
- children: links.map((link) => {
152
- return link && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_ui.Link, { onClick: link.onClick, children: link.label }, link.label);
199
+ children: links.map(link => {
200
+ return link && /* @__PURE__ */(0, import_jsx_runtime2.jsx)(import_ui.Link, {
201
+ onClick: link.onClick,
202
+ children: link.label
203
+ }, link.label);
153
204
  })
154
- }
155
- )
156
- ] }) });
205
+ })]
206
+ })
207
+ });
157
208
  };
158
209
 
159
210
  // src/AuthConfirmSignUp.tsx
@@ -164,81 +215,93 @@ var AuthConfirmSignUp = ({
164
215
  email,
165
216
  onConfirmSignUp
166
217
  }) => {
167
- const { intl } = (0, import_react_i18n.useI18n)();
218
+ const {
219
+ intl
220
+ } = (0, import_react_i18n.useI18n)();
168
221
  const schema = import_forms.yup.object().shape({
169
- code: import_forms.yup.string().required(
170
- intl.formatMessage({
171
- description: "Required field.",
172
- defaultMessage: "Required field"
173
- })
174
- ).max(
175
- 6,
176
- intl.formatMessage(
177
- {
178
- description: "Minimum {value} characters.",
179
- defaultMessage: "Minimum {value} characters"
180
- },
181
- { value: 6 }
182
- )
183
- )
222
+ code: import_forms.yup.string().required(intl.formatMessage({
223
+ id: "0XOzcH",
224
+ defaultMessage: [{
225
+ "type": 0,
226
+ "value": "Required field"
227
+ }]
228
+ })).max(6, intl.formatMessage({
229
+ id: "S3pjKw",
230
+ defaultMessage: [{
231
+ "type": 0,
232
+ "value": "Minimum "
233
+ }, {
234
+ "type": 1,
235
+ "value": "value"
236
+ }, {
237
+ "type": 0,
238
+ "value": " characters"
239
+ }]
240
+ }, {
241
+ value: 6
242
+ }))
184
243
  }).required();
185
244
  const formMethods = (0, import_forms.useForm)({
186
245
  resolver: (0, import_forms.yupResolver)(schema)
187
246
  });
188
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
189
- import_forms.Form,
190
- {
191
- ...formMethods,
192
- onSubmit: ({ code }) => {
193
- return onConfirmSignUp({ code, email });
194
- },
195
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
196
- AuthCard,
197
- {
198
- buttonLabel: intl.formatMessage({
199
- description: "Confirm",
200
- defaultMessage: "Confirm"
201
- }),
202
- title: intl.formatMessage({
203
- description: "Confirmation",
204
- defaultMessage: "Confirmation"
205
- }),
206
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
207
- import_forms.FormFieldInput,
208
- {
209
- name: "code",
210
- label: intl.formatMessage({
211
- description: "Sign up confirmation code",
212
- defaultMessage: "Code"
213
- })
214
- }
215
- )
216
- }
217
- )
218
- }
219
- );
247
+ return /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_forms.Form, {
248
+ ...formMethods,
249
+ onSubmit: ({
250
+ code
251
+ }) => {
252
+ return onConfirmSignUp({
253
+ code,
254
+ email
255
+ });
256
+ },
257
+ children: /* @__PURE__ */(0, import_jsx_runtime3.jsx)(AuthCard, {
258
+ buttonLabel: intl.formatMessage({
259
+ id: "UNttd+",
260
+ defaultMessage: [{
261
+ "type": 0,
262
+ "value": "Confirm"
263
+ }]
264
+ }),
265
+ title: intl.formatMessage({
266
+ id: "cGR2eI",
267
+ defaultMessage: [{
268
+ "type": 0,
269
+ "value": "Confirmation"
270
+ }]
271
+ }),
272
+ children: /* @__PURE__ */(0, import_jsx_runtime3.jsx)(import_forms.FormFieldInput, {
273
+ name: "code",
274
+ label: intl.formatMessage({
275
+ id: "KY2T6J",
276
+ defaultMessage: [{
277
+ "type": 0,
278
+ "value": "Code"
279
+ }]
280
+ })
281
+ })
282
+ })
283
+ });
220
284
  };
221
285
 
222
286
  // src/AuthFullScreen.tsx
223
287
  var import_ui2 = require("@ttoss/ui");
224
288
  var import_jsx_runtime4 = require("react/jsx-runtime");
225
- var AuthFullScreen = ({ children }) => {
226
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
227
- import_ui2.Flex,
228
- {
229
- sx: {
230
- height: "100vh",
231
- width: "100vw",
232
- justifyContent: "center",
233
- alignItems: "center",
234
- margin: 0,
235
- backgroundPosition: "center",
236
- backgroundRepeat: "no-repeat",
237
- backgroundSize: "cover"
238
- },
239
- children
240
- }
241
- );
289
+ var AuthFullScreen = ({
290
+ children
291
+ }) => {
292
+ return /* @__PURE__ */(0, import_jsx_runtime4.jsx)(import_ui2.Flex, {
293
+ sx: {
294
+ height: "100vh",
295
+ width: "100vw",
296
+ justifyContent: "center",
297
+ alignItems: "center",
298
+ margin: 0,
299
+ backgroundPosition: "center",
300
+ backgroundRepeat: "no-repeat",
301
+ backgroundSize: "cover"
302
+ },
303
+ children
304
+ });
242
305
  };
243
306
 
244
307
  // src/AuthSignIn.tsx
@@ -308,7 +371,9 @@ var createAuthTemplate = ({
308
371
  },
309
372
  Export: {
310
373
  Name: {
311
- "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "Region"]]
374
+ "Fn::Join": [":", [{
375
+ Ref: "AWS::StackName"
376
+ }, "Region"]]
312
377
  }
313
378
  }
314
379
  },
@@ -319,7 +384,9 @@ var createAuthTemplate = ({
319
384
  },
320
385
  Export: {
321
386
  Name: {
322
- "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "UserPoolId"]]
387
+ "Fn::Join": [":", [{
388
+ Ref: "AWS::StackName"
389
+ }, "UserPoolId"]]
323
390
  }
324
391
  }
325
392
  },
@@ -330,14 +397,16 @@ var createAuthTemplate = ({
330
397
  },
331
398
  Export: {
332
399
  Name: {
333
- "Fn::Join": [":", [{ Ref: "AWS::StackName" }, "AppClientId"]]
400
+ "Fn::Join": [":", [{
401
+ Ref: "AWS::StackName"
402
+ }, "AppClientId"]]
334
403
  }
335
404
  }
336
405
  }
337
406
  }
338
407
  };
339
408
  if (schema) {
340
- const Schema = schema.map((attribute) => {
409
+ const Schema = schema.map(attribute => {
341
410
  let NumberAttributeConstraints = void 0;
342
411
  if (attribute.numberAttributeConstraints) {
343
412
  NumberAttributeConstraints = {
@@ -369,16 +438,14 @@ var createAuthTemplate = ({
369
438
  Type: "AWS::Cognito::IdentityPool",
370
439
  Properties: {
371
440
  AllowUnauthenticatedIdentities: true,
372
- CognitoIdentityProviders: [
373
- {
374
- ClientId: {
375
- Ref: CognitoUserPoolClientLogicalId
376
- },
377
- ProviderName: {
378
- "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
379
- }
441
+ CognitoIdentityProviders: [{
442
+ ClientId: {
443
+ Ref: CognitoUserPoolClientLogicalId
444
+ },
445
+ ProviderName: {
446
+ "Fn::GetAtt": [CognitoUserPoolLogicalId, "ProviderName"]
380
447
  }
381
- ]
448
+ }]
382
449
  }
383
450
  };
384
451
  template.Resources[IdentityPoolAuthenticatedIAMRoleLogicalId] = {
@@ -386,35 +453,31 @@ var createAuthTemplate = ({
386
453
  Properties: {
387
454
  AssumeRolePolicyDocument: {
388
455
  Version: "2012-10-17",
389
- Statement: [
390
- {
391
- Effect: "Allow",
392
- Principal: {
393
- Federated: "cognito-identity.amazonaws.com"
394
- },
395
- Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
396
- Condition: {
397
- StringEquals: {
398
- "cognito-identity.amazonaws.com:aud": {
399
- Ref: CognitoIdentityPoolLogicalId
400
- }
401
- },
402
- "ForAnyValue:StringLike": {
403
- "cognito-identity.amazonaws.com:amr": "authenticated"
456
+ Statement: [{
457
+ Effect: "Allow",
458
+ Principal: {
459
+ Federated: "cognito-identity.amazonaws.com"
460
+ },
461
+ Action: ["sts:AssumeRoleWithWebIdentity", "sts:TagSession"],
462
+ Condition: {
463
+ StringEquals: {
464
+ "cognito-identity.amazonaws.com:aud": {
465
+ Ref: CognitoIdentityPoolLogicalId
404
466
  }
467
+ },
468
+ "ForAnyValue:StringLike": {
469
+ "cognito-identity.amazonaws.com:amr": "authenticated"
405
470
  }
406
471
  }
407
- ]
472
+ }]
408
473
  },
409
- Policies: identityPool.authenticatedPolicies || [
410
- {
411
- PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
412
- PolicyDocument: {
413
- Version: "2012-10-17",
414
- Statement: [DenyStatement]
415
- }
474
+ Policies: identityPool.authenticatedPolicies || [{
475
+ PolicyName: "IdentityPoolAuthenticatedIAMRolePolicyName",
476
+ PolicyDocument: {
477
+ Version: "2012-10-17",
478
+ Statement: [DenyStatement]
416
479
  }
417
- ]
480
+ }]
418
481
  }
419
482
  };
420
483
  template.Resources[IdentityPoolUnauthenticatedIAMRoleLogicalId] = {
@@ -422,35 +485,31 @@ var createAuthTemplate = ({
422
485
  Properties: {
423
486
  AssumeRolePolicyDocument: {
424
487
  Version: "2012-10-17",
425
- Statement: [
426
- {
427
- Effect: "Allow",
428
- Principal: {
429
- Federated: "cognito-identity.amazonaws.com"
430
- },
431
- Action: "sts:AssumeRoleWithWebIdentity",
432
- Condition: {
433
- StringEquals: {
434
- "cognito-identity.amazonaws.com:aud": {
435
- Ref: CognitoIdentityPoolLogicalId
436
- }
437
- },
438
- "ForAnyValue:StringLike": {
439
- "cognito-identity.amazonaws.com:amr": "unauthenticated"
488
+ Statement: [{
489
+ Effect: "Allow",
490
+ Principal: {
491
+ Federated: "cognito-identity.amazonaws.com"
492
+ },
493
+ Action: "sts:AssumeRoleWithWebIdentity",
494
+ Condition: {
495
+ StringEquals: {
496
+ "cognito-identity.amazonaws.com:aud": {
497
+ Ref: CognitoIdentityPoolLogicalId
440
498
  }
499
+ },
500
+ "ForAnyValue:StringLike": {
501
+ "cognito-identity.amazonaws.com:amr": "unauthenticated"
441
502
  }
442
503
  }
443
- ]
504
+ }]
444
505
  },
445
- Policies: identityPool.authenticatedPolicies || [
446
- {
447
- PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
448
- PolicyDocument: {
449
- Version: "2012-10-17",
450
- Statement: [DenyStatement]
451
- }
506
+ Policies: identityPool.authenticatedPolicies || [{
507
+ PolicyName: "IdentityPoolUnauthenticatedIAMRolePolicyName",
508
+ PolicyDocument: {
509
+ Version: "2012-10-17",
510
+ Statement: [DenyStatement]
452
511
  }
453
- ]
512
+ }]
454
513
  }
455
514
  };
456
515
  template.Resources.CognitoIdentityPoolRoleAttachment = {
@@ -479,10 +538,9 @@ var createAuthTemplate = ({
479
538
  },
480
539
  Export: {
481
540
  Name: {
482
- "Fn::Join": [
483
- ":",
484
- [{ Ref: "AWS::StackName" }, "CognitoIdentityPoolId"]
485
- ]
541
+ "Fn::Join": [":", [{
542
+ Ref: "AWS::StackName"
543
+ }, "CognitoIdentityPoolId"]]
486
544
  }
487
545
  }
488
546
  };
@@ -501,179 +559,214 @@ var AuthSignIn = ({
501
559
  onSignUp,
502
560
  defaultValues
503
561
  }) => {
504
- const { intl } = (0, import_react_i18n2.useI18n)();
562
+ const {
563
+ intl
564
+ } = (0, import_react_i18n2.useI18n)();
505
565
  const schema = import_forms2.yup.object().shape({
506
- email: import_forms2.yup.string().required(
507
- intl.formatMessage({
508
- description: "Email is a required field.",
509
- defaultMessage: "Email field is required"
510
- })
511
- ).email(
512
- intl.formatMessage({
513
- description: "Invalid email.",
514
- defaultMessage: "Invalid email"
515
- })
516
- ),
517
- password: import_forms2.yup.string().required(
518
- intl.formatMessage({
519
- description: "Password is required.",
520
- defaultMessage: "Password field is required"
521
- })
522
- ).min(
523
- PASSWORD_MINIMUM_LENGTH,
524
- intl.formatMessage(
525
- {
526
- description: "Password must be at least {value} characters long.",
527
- defaultMessage: "Password requires {value} characters"
528
- },
529
- { value: PASSWORD_MINIMUM_LENGTH }
530
- )
531
- ).trim()
566
+ email: import_forms2.yup.string().required(intl.formatMessage({
567
+ id: "r+QgO+",
568
+ defaultMessage: [{
569
+ "type": 0,
570
+ "value": "Email field is required"
571
+ }]
572
+ })).email(intl.formatMessage({
573
+ id: "OhDL0i",
574
+ defaultMessage: [{
575
+ "type": 0,
576
+ "value": "Invalid email"
577
+ }]
578
+ })),
579
+ password: import_forms2.yup.string().required(intl.formatMessage({
580
+ id: "kdFYba",
581
+ defaultMessage: [{
582
+ "type": 0,
583
+ "value": "Password field is required"
584
+ }]
585
+ })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
586
+ id: "TZ4WUk",
587
+ defaultMessage: [{
588
+ "type": 0,
589
+ "value": "Password requires "
590
+ }, {
591
+ "type": 1,
592
+ "value": "value"
593
+ }, {
594
+ "type": 0,
595
+ "value": " characters"
596
+ }]
597
+ }, {
598
+ value: PASSWORD_MINIMUM_LENGTH
599
+ })).trim()
532
600
  });
533
601
  const formMethods = (0, import_forms2.useForm)({
534
602
  defaultValues,
535
603
  resolver: (0, import_forms2.yupResolver)(schema)
536
604
  });
537
- const onSubmitForm = (data) => {
605
+ const onSubmitForm = data => {
538
606
  return onSignIn(data);
539
607
  };
540
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_forms2.Form, { ...formMethods, onSubmit: onSubmitForm, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
541
- AuthCard,
542
- {
608
+ return /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_forms2.Form, {
609
+ ...formMethods,
610
+ onSubmit: onSubmitForm,
611
+ children: /* @__PURE__ */(0, import_jsx_runtime5.jsxs)(AuthCard, {
543
612
  title: intl.formatMessage({
544
- description: "Sign in title.",
545
- defaultMessage: "Login"
613
+ id: "R1rFNQ",
614
+ defaultMessage: [{
615
+ "type": 0,
616
+ "value": "Login"
617
+ }]
546
618
  }),
547
619
  buttonLabel: intl.formatMessage({
548
- description: "Button label.",
549
- defaultMessage: "Login"
620
+ id: "0cVgsc",
621
+ defaultMessage: [{
622
+ "type": 0,
623
+ "value": "Login"
624
+ }]
550
625
  }),
551
- links: [
552
- {
553
- onClick: onSignUp,
554
- label: intl.formatMessage({
555
- description: "Link to retrieve password.",
556
- defaultMessage: "Do you forgot your password?"
557
- })
558
- },
559
- {
560
- onClick: onSignUp,
561
- label: intl.formatMessage({
562
- description: "Link to sign up.",
563
- defaultMessage: "Don't have an account? Sign up"
564
- })
565
- }
566
- ],
567
- children: [
568
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
569
- import_forms2.FormFieldInput,
570
- {
571
- name: "email",
572
- label: intl.formatMessage({
573
- description: "Email label.",
574
- defaultMessage: "Email"
575
- })
576
- }
577
- ),
578
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
579
- import_forms2.FormFieldInput,
580
- {
581
- name: "password",
582
- label: intl.formatMessage({
583
- description: "Password label.",
584
- defaultMessage: "Password"
585
- })
586
- }
587
- )
588
- ]
589
- }
590
- ) });
626
+ links: [{
627
+ onClick: onSignUp,
628
+ label: intl.formatMessage({
629
+ id: "z5s0vm",
630
+ defaultMessage: [{
631
+ "type": 0,
632
+ "value": "Do you forgot your password?"
633
+ }]
634
+ })
635
+ }, {
636
+ onClick: onSignUp,
637
+ label: intl.formatMessage({
638
+ id: "XC1w2U",
639
+ defaultMessage: [{
640
+ "type": 0,
641
+ "value": "Don't have an account? Sign up"
642
+ }]
643
+ })
644
+ }],
645
+ children: [/* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_forms2.FormFieldInput, {
646
+ name: "email",
647
+ label: intl.formatMessage({
648
+ id: "5E12mO",
649
+ defaultMessage: [{
650
+ "type": 0,
651
+ "value": "Email"
652
+ }]
653
+ })
654
+ }), /* @__PURE__ */(0, import_jsx_runtime5.jsx)(import_forms2.FormFieldInput, {
655
+ name: "password",
656
+ label: intl.formatMessage({
657
+ id: "PylVqx",
658
+ defaultMessage: [{
659
+ "type": 0,
660
+ "value": "Password"
661
+ }]
662
+ })
663
+ })]
664
+ })
665
+ });
591
666
  };
592
667
 
593
668
  // src/AuthSignUp.tsx
594
669
  var import_forms3 = require("@ttoss/forms");
595
670
  var import_react_i18n3 = require("@ttoss/react-i18n");
596
671
  var import_jsx_runtime6 = require("react/jsx-runtime");
597
- var AuthSignUp = ({ onSignUp, onReturnToSignIn }) => {
598
- const { intl } = (0, import_react_i18n3.useI18n)();
672
+ var AuthSignUp = ({
673
+ onSignUp,
674
+ onReturnToSignIn
675
+ }) => {
676
+ const {
677
+ intl
678
+ } = (0, import_react_i18n3.useI18n)();
599
679
  const schema = import_forms3.yup.object().shape({
600
- email: import_forms3.yup.string().required(
601
- intl.formatMessage({
602
- description: "Email is a required field.",
603
- defaultMessage: "Email field is required"
604
- })
605
- ).email(
606
- intl.formatMessage({
607
- description: "Invalid email.",
608
- defaultMessage: "Invalid email"
609
- })
610
- ),
611
- password: import_forms3.yup.string().required(
612
- intl.formatMessage({
613
- description: "Password is required.",
614
- defaultMessage: "Password field is required"
615
- })
616
- ).min(
617
- PASSWORD_MINIMUM_LENGTH,
618
- intl.formatMessage(
619
- {
620
- description: "Password must be at least {value} characters long.",
621
- defaultMessage: "Password requires {value} characters"
622
- },
623
- { value: PASSWORD_MINIMUM_LENGTH }
624
- )
625
- ).trim()
680
+ email: import_forms3.yup.string().required(intl.formatMessage({
681
+ id: "r+QgO+",
682
+ defaultMessage: [{
683
+ "type": 0,
684
+ "value": "Email field is required"
685
+ }]
686
+ })).email(intl.formatMessage({
687
+ id: "OhDL0i",
688
+ defaultMessage: [{
689
+ "type": 0,
690
+ "value": "Invalid email"
691
+ }]
692
+ })),
693
+ password: import_forms3.yup.string().required(intl.formatMessage({
694
+ id: "kdFYba",
695
+ defaultMessage: [{
696
+ "type": 0,
697
+ "value": "Password field is required"
698
+ }]
699
+ })).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
700
+ id: "TZ4WUk",
701
+ defaultMessage: [{
702
+ "type": 0,
703
+ "value": "Password requires "
704
+ }, {
705
+ "type": 1,
706
+ "value": "value"
707
+ }, {
708
+ "type": 0,
709
+ "value": " characters"
710
+ }]
711
+ }, {
712
+ value: PASSWORD_MINIMUM_LENGTH
713
+ })).trim()
626
714
  });
627
715
  const formMethods = (0, import_forms3.useForm)({
628
716
  resolver: (0, import_forms3.yupResolver)(schema)
629
717
  });
630
- const onSubmitForm = (data) => {
718
+ const onSubmitForm = data => {
631
719
  return onSignUp(data);
632
720
  };
633
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_forms3.Form, { ...formMethods, onSubmit: onSubmitForm, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
634
- AuthCard,
635
- {
721
+ return /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.Form, {
722
+ ...formMethods,
723
+ onSubmit: onSubmitForm,
724
+ children: /* @__PURE__ */(0, import_jsx_runtime6.jsxs)(AuthCard, {
636
725
  buttonLabel: intl.formatMessage({
637
- description: "Create account.",
638
- defaultMessage: "Create account"
726
+ id: "Pdio77",
727
+ defaultMessage: [{
728
+ "type": 0,
729
+ "value": "Create account"
730
+ }]
639
731
  }),
640
732
  title: intl.formatMessage({
641
- description: "Title on sign up.",
642
- defaultMessage: "Register"
733
+ id: "EXZxA0",
734
+ defaultMessage: [{
735
+ "type": 0,
736
+ "value": "Register"
737
+ }]
643
738
  }),
644
- links: [
645
- {
646
- label: intl.formatMessage({
647
- description: "Link to sign in on sign up.",
648
- defaultMessage: "Do you already have an account? Sign in"
649
- }),
650
- onClick: onReturnToSignIn
651
- }
652
- ],
653
- children: [
654
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
655
- import_forms3.FormFieldInput,
656
- {
657
- name: "email",
658
- label: intl.formatMessage({
659
- description: "Email label.",
660
- defaultMessage: "Email"
661
- })
662
- }
663
- ),
664
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
665
- import_forms3.FormFieldInput,
666
- {
667
- name: "password",
668
- label: intl.formatMessage({
669
- description: "Password label.",
670
- defaultMessage: "Password"
671
- })
672
- }
673
- )
674
- ]
675
- }
676
- ) });
739
+ links: [{
740
+ label: intl.formatMessage({
741
+ id: "LU2ddR",
742
+ defaultMessage: [{
743
+ "type": 0,
744
+ "value": "Do you already have an account? Sign in"
745
+ }]
746
+ }),
747
+ onClick: onReturnToSignIn
748
+ }],
749
+ children: [/* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldInput, {
750
+ name: "email",
751
+ label: intl.formatMessage({
752
+ id: "5E12mO",
753
+ defaultMessage: [{
754
+ "type": 0,
755
+ "value": "Email"
756
+ }]
757
+ })
758
+ }), /* @__PURE__ */(0, import_jsx_runtime6.jsx)(import_forms3.FormFieldInput, {
759
+ name: "password",
760
+ label: intl.formatMessage({
761
+ id: "PylVqx",
762
+ defaultMessage: [{
763
+ "type": 0,
764
+ "value": "Password"
765
+ }]
766
+ })
767
+ })]
768
+ })
769
+ });
677
770
  };
678
771
 
679
772
  // src/Auth.tsx
@@ -681,137 +774,160 @@ var import_xstate = require("xstate");
681
774
  var import_react = require("@xstate/react");
682
775
  var import_react_notifications2 = require("@ttoss/react-notifications");
683
776
  var import_jsx_runtime7 = require("react/jsx-runtime");
684
- var authMachine = (0, import_xstate.createMachine)(
685
- {
686
- predictableActionArguments: true,
687
- initial: "signIn",
688
- states: {
689
- signIn: {
690
- on: {
691
- SIGN_UP: { target: "signUp" },
692
- SIGN_UP_RESEND_CONFIRMATION: {
693
- actions: ["assignEmail"],
694
- target: "signUpConfirm"
695
- }
696
- }
697
- },
698
- signUp: {
699
- on: {
700
- SIGN_UP_CONFIRM: {
701
- actions: ["assignEmail"],
702
- target: "signUpConfirm"
703
- },
704
- RETURN_TO_SIGN_IN: { target: "signIn" }
777
+ var authMachine = (0, import_xstate.createMachine)({
778
+ predictableActionArguments: true,
779
+ initial: "signIn",
780
+ states: {
781
+ signIn: {
782
+ on: {
783
+ SIGN_UP: {
784
+ target: "signUp"
785
+ },
786
+ SIGN_UP_RESEND_CONFIRMATION: {
787
+ actions: ["assignEmail"],
788
+ target: "signUpConfirm"
705
789
  }
706
- },
707
- signUpConfirm: {
708
- on: {
709
- SIGN_UP_CONFIRMED: {
710
- actions: ["assignEmail"],
711
- target: "signIn"
712
- }
790
+ }
791
+ },
792
+ signUp: {
793
+ on: {
794
+ SIGN_UP_CONFIRM: {
795
+ actions: ["assignEmail"],
796
+ target: "signUpConfirm"
797
+ },
798
+ RETURN_TO_SIGN_IN: {
799
+ target: "signIn"
713
800
  }
714
801
  }
715
- }
716
- },
717
- {
718
- actions: {
719
- assignEmail: (0, import_xstate.assign)({
720
- email: (_, event) => {
721
- return event.email;
802
+ },
803
+ signUpConfirm: {
804
+ on: {
805
+ SIGN_UP_CONFIRMED: {
806
+ actions: ["assignEmail"],
807
+ target: "signIn"
722
808
  }
723
- })
809
+ }
724
810
  }
725
811
  }
726
- );
812
+ }, {
813
+ actions: {
814
+ assignEmail: (0, import_xstate.assign)({
815
+ email: (_, event) => {
816
+ return event.email;
817
+ }
818
+ })
819
+ }
820
+ });
727
821
  var AuthLogic = () => {
728
- const { isAuthenticated } = useAuth();
822
+ const {
823
+ isAuthenticated
824
+ } = useAuth();
729
825
  const [state, send] = (0, import_react.useMachine)(authMachine);
730
- const { setLoading } = (0, import_react_notifications2.useNotifications)();
731
- const onSignIn = React3.useCallback(
732
- async ({ email, password }) => {
733
- try {
734
- setLoading(true);
735
- await import_aws_amplify2.Auth.signIn(email, password);
736
- } catch (error) {
737
- switch (error.code) {
738
- case "UserNotConfirmedException":
739
- await import_aws_amplify2.Auth.resendSignUp(email);
740
- send({ type: "SIGN_UP_RESEND_CONFIRMATION", email });
741
- break;
742
- default:
743
- }
744
- } finally {
745
- setLoading(false);
746
- }
747
- },
748
- [send, setLoading]
749
- );
750
- const onSignUp = React3.useCallback(
751
- async ({ email, password }) => {
752
- try {
753
- setLoading(true);
754
- await import_aws_amplify2.Auth.signUp({
755
- username: email,
756
- password,
757
- attributes: { email }
758
- });
759
- send({ type: "SIGN_UP_CONFIRM", email });
760
- } catch (error) {
761
- } finally {
762
- setLoading(false);
763
- }
764
- },
765
- [send, setLoading]
766
- );
767
- const onConfirmSignUp = React3.useCallback(
768
- async ({ email, code }) => {
769
- try {
770
- setLoading(true);
771
- await import_aws_amplify2.Auth.confirmSignUp(email, code);
772
- send({ type: "SIGN_UP_CONFIRMED", email });
773
- } catch (error) {
774
- } finally {
775
- setLoading(false);
826
+ const {
827
+ setLoading
828
+ } = (0, import_react_notifications2.useNotifications)();
829
+ const onSignIn = React3.useCallback(async ({
830
+ email,
831
+ password
832
+ }) => {
833
+ try {
834
+ setLoading(true);
835
+ await import_aws_amplify2.Auth.signIn(email, password);
836
+ } catch (error) {
837
+ switch (error.code) {
838
+ case "UserNotConfirmedException":
839
+ await import_aws_amplify2.Auth.resendSignUp(email);
840
+ send({
841
+ type: "SIGN_UP_RESEND_CONFIRMATION",
842
+ email
843
+ });
844
+ break;
845
+ default:
776
846
  }
777
- },
778
- [send, setLoading]
779
- );
847
+ } finally {
848
+ setLoading(false);
849
+ }
850
+ }, [send, setLoading]);
851
+ const onSignUp = React3.useCallback(async ({
852
+ email,
853
+ password
854
+ }) => {
855
+ try {
856
+ setLoading(true);
857
+ await import_aws_amplify2.Auth.signUp({
858
+ username: email,
859
+ password,
860
+ attributes: {
861
+ email
862
+ }
863
+ });
864
+ send({
865
+ type: "SIGN_UP_CONFIRM",
866
+ email
867
+ });
868
+ } catch (error) {} finally {
869
+ setLoading(false);
870
+ }
871
+ }, [send, setLoading]);
872
+ const onConfirmSignUp = React3.useCallback(async ({
873
+ email,
874
+ code
875
+ }) => {
876
+ try {
877
+ setLoading(true);
878
+ await import_aws_amplify2.Auth.confirmSignUp(email, code);
879
+ send({
880
+ type: "SIGN_UP_CONFIRMED",
881
+ email
882
+ });
883
+ } catch (error) {} finally {
884
+ setLoading(false);
885
+ }
886
+ }, [send, setLoading]);
780
887
  const onReturnToSignIn = React3.useCallback(() => {
781
- send({ type: "RETURN_TO_SIGN_IN" });
888
+ send({
889
+ type: "RETURN_TO_SIGN_IN"
890
+ });
782
891
  }, [send]);
783
892
  if (isAuthenticated) {
784
893
  return null;
785
894
  }
786
895
  if (state.matches("signUp")) {
787
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthSignUp, { onSignUp, onReturnToSignIn });
896
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(AuthSignUp, {
897
+ onSignUp,
898
+ onReturnToSignIn
899
+ });
788
900
  }
789
901
  if (state.matches("signUpConfirm")) {
790
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
791
- AuthConfirmSignUp,
792
- {
793
- onConfirmSignUp,
794
- email: state.context.email
795
- }
796
- );
902
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(AuthConfirmSignUp, {
903
+ onConfirmSignUp,
904
+ email: state.context.email
905
+ });
797
906
  }
798
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
799
- AuthSignIn,
800
- {
801
- onSignIn,
802
- onSignUp: () => {
803
- return send("SIGN_UP");
804
- },
805
- defaultValues: { email: state.context.email }
907
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(AuthSignIn, {
908
+ onSignIn,
909
+ onSignUp: () => {
910
+ return send("SIGN_UP");
911
+ },
912
+ defaultValues: {
913
+ email: state.context.email
806
914
  }
807
- );
915
+ });
808
916
  };
809
- var Auth2 = ({ logo, fullScreen = true }) => {
917
+ var Auth2 = ({
918
+ logo,
919
+ fullScreen = true
920
+ }) => {
810
921
  const withLogoNode = React3.useMemo(() => {
811
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(LogoProvider, { logo, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthLogic, {}) });
922
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(LogoProvider, {
923
+ logo,
924
+ children: /* @__PURE__ */(0, import_jsx_runtime7.jsx)(AuthLogic, {})
925
+ });
812
926
  }, [logo]);
813
927
  if (fullScreen) {
814
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthFullScreen, { children: withLogoNode });
928
+ return /* @__PURE__ */(0, import_jsx_runtime7.jsx)(AuthFullScreen, {
929
+ children: withLogoNode
930
+ });
815
931
  }
816
932
  return withLogoNode;
817
933
  };
@@ -820,4 +936,4 @@ var Auth2 = ({ logo, fullScreen = true }) => {
820
936
  Auth,
821
937
  AuthProvider,
822
938
  useAuth
823
- });
939
+ });