@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.
- package/dist/esm/index.js +530 -425
- package/dist/index.js +548 -432
- 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 = ({
|
|
17
|
-
|
|
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(({
|
|
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__ */
|
|
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 = ({
|
|
72
|
-
|
|
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 {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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: {
|
|
126
|
+
sx: {
|
|
127
|
+
alignSelf: "center",
|
|
128
|
+
marginY: 4,
|
|
129
|
+
fontSize: 5
|
|
130
|
+
},
|
|
89
131
|
children: title
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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(
|
|
115
|
-
return link && /* @__PURE__ */
|
|
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 {
|
|
174
|
+
const {
|
|
175
|
+
intl
|
|
176
|
+
} = useI18n();
|
|
131
177
|
const schema = yup.object().shape({
|
|
132
|
-
code: yup.string().required(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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__ */
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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 = ({
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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": [":", [{
|
|
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": [":", [{
|
|
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": [":", [{
|
|
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(
|
|
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
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
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
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
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 {
|
|
518
|
+
const {
|
|
519
|
+
intl
|
|
520
|
+
} = useI18n2();
|
|
468
521
|
const schema = yup2.object().shape({
|
|
469
|
-
email: yup2.string().required(
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
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 =
|
|
561
|
+
const onSubmitForm = data => {
|
|
501
562
|
return onSignIn(data);
|
|
502
563
|
};
|
|
503
|
-
return /* @__PURE__ */
|
|
504
|
-
|
|
505
|
-
|
|
564
|
+
return /* @__PURE__ */jsx5(Form2, {
|
|
565
|
+
...formMethods,
|
|
566
|
+
onSubmit: onSubmitForm,
|
|
567
|
+
children: /* @__PURE__ */jsxs2(AuthCard, {
|
|
506
568
|
title: intl.formatMessage({
|
|
507
|
-
|
|
508
|
-
defaultMessage:
|
|
569
|
+
id: "R1rFNQ",
|
|
570
|
+
defaultMessage: [{
|
|
571
|
+
"type": 0,
|
|
572
|
+
"value": "Login"
|
|
573
|
+
}]
|
|
509
574
|
}),
|
|
510
575
|
buttonLabel: intl.formatMessage({
|
|
511
|
-
|
|
512
|
-
defaultMessage:
|
|
576
|
+
id: "0cVgsc",
|
|
577
|
+
defaultMessage: [{
|
|
578
|
+
"type": 0,
|
|
579
|
+
"value": "Login"
|
|
580
|
+
}]
|
|
513
581
|
}),
|
|
514
|
-
links: [
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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 = ({
|
|
561
|
-
|
|
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
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
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 =
|
|
674
|
+
const onSubmitForm = data => {
|
|
594
675
|
return onSignUp(data);
|
|
595
676
|
};
|
|
596
|
-
return /* @__PURE__ */
|
|
597
|
-
|
|
598
|
-
|
|
677
|
+
return /* @__PURE__ */jsx6(Form3, {
|
|
678
|
+
...formMethods,
|
|
679
|
+
onSubmit: onSubmitForm,
|
|
680
|
+
children: /* @__PURE__ */jsxs3(AuthCard, {
|
|
599
681
|
buttonLabel: intl.formatMessage({
|
|
600
|
-
|
|
601
|
-
defaultMessage:
|
|
682
|
+
id: "Pdio77",
|
|
683
|
+
defaultMessage: [{
|
|
684
|
+
"type": 0,
|
|
685
|
+
"value": "Create account"
|
|
686
|
+
}]
|
|
602
687
|
}),
|
|
603
688
|
title: intl.formatMessage({
|
|
604
|
-
|
|
605
|
-
defaultMessage:
|
|
689
|
+
id: "EXZxA0",
|
|
690
|
+
defaultMessage: [{
|
|
691
|
+
"type": 0,
|
|
692
|
+
"value": "Register"
|
|
693
|
+
}]
|
|
606
694
|
}),
|
|
607
|
-
links: [
|
|
608
|
-
{
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
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
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
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
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
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
|
-
|
|
682
|
-
|
|
683
|
-
|
|
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 {
|
|
778
|
+
const {
|
|
779
|
+
isAuthenticated
|
|
780
|
+
} = useAuth();
|
|
692
781
|
const [state, send] = useMachine(authMachine);
|
|
693
|
-
const {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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
|
-
|
|
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({
|
|
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__ */
|
|
852
|
+
return /* @__PURE__ */jsx7(AuthSignUp, {
|
|
853
|
+
onSignUp,
|
|
854
|
+
onReturnToSignIn
|
|
855
|
+
});
|
|
751
856
|
}
|
|
752
857
|
if (state.matches("signUpConfirm")) {
|
|
753
|
-
return /* @__PURE__ */
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
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__ */
|
|
762
|
-
|
|
763
|
-
{
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
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 = ({
|
|
873
|
+
var Auth2 = ({
|
|
874
|
+
logo,
|
|
875
|
+
fullScreen = true
|
|
876
|
+
}) => {
|
|
773
877
|
const withLogoNode = React3.useMemo(() => {
|
|
774
|
-
return /* @__PURE__ */
|
|
878
|
+
return /* @__PURE__ */jsx7(LogoProvider, {
|
|
879
|
+
logo,
|
|
880
|
+
children: /* @__PURE__ */jsx7(AuthLogic, {})
|
|
881
|
+
});
|
|
775
882
|
}, [logo]);
|
|
776
883
|
if (fullScreen) {
|
|
777
|
-
return /* @__PURE__ */
|
|
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 };
|