@ttoss/react-auth 2.3.5 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +237 -194
- package/dist/index.d.ts +45 -30
- package/i18n/compiled/en.json +6 -0
- package/i18n/lang/en.json +3 -0
- package/package.json +10 -10
package/dist/esm/index.js
CHANGED
|
@@ -1,98 +1,24 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
|
|
3
|
-
// src/AuthProvider.tsx
|
|
4
|
-
import * as React from "react";
|
|
5
|
-
import { Hub } from "aws-amplify/utils";
|
|
6
|
-
import { signOut as awsSignOut, fetchAuthSession, fetchUserAttributes, getCurrentUser } from "aws-amplify/auth";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
var signOut = () => {
|
|
9
|
-
return awsSignOut();
|
|
10
|
-
};
|
|
11
|
-
var AuthContext = React.createContext({
|
|
12
|
-
signOut,
|
|
13
|
-
isAuthenticated: false,
|
|
14
|
-
user: null,
|
|
15
|
-
tokens: null
|
|
16
|
-
});
|
|
17
|
-
var AuthProvider = ({
|
|
18
|
-
children
|
|
19
|
-
}) => {
|
|
20
|
-
const [{
|
|
21
|
-
user,
|
|
22
|
-
tokens,
|
|
23
|
-
isAuthenticated
|
|
24
|
-
}, setAuthState] = React.useState({
|
|
25
|
-
user: null,
|
|
26
|
-
tokens: null,
|
|
27
|
-
isAuthenticated: void 0
|
|
28
|
-
});
|
|
29
|
-
React.useEffect(() => {
|
|
30
|
-
const updateUser = () => {
|
|
31
|
-
getCurrentUser().then(async ({
|
|
32
|
-
userId
|
|
33
|
-
}) => {
|
|
34
|
-
const [session, user2] = await Promise.all([fetchAuthSession(), fetchUserAttributes()]);
|
|
35
|
-
const idToken = session.tokens?.idToken?.toString() ?? "";
|
|
36
|
-
const accessToken = session.tokens?.accessToken.toString() ?? "";
|
|
37
|
-
setAuthState({
|
|
38
|
-
user: {
|
|
39
|
-
id: userId,
|
|
40
|
-
email: user2.email ?? "",
|
|
41
|
-
emailVerified: user2.email_verified ?? ""
|
|
42
|
-
},
|
|
43
|
-
tokens: {
|
|
44
|
-
idToken,
|
|
45
|
-
accessToken,
|
|
46
|
-
refreshToken: ""
|
|
47
|
-
},
|
|
48
|
-
isAuthenticated: true
|
|
49
|
-
});
|
|
50
|
-
}).catch(e => {
|
|
51
|
-
console.error(e);
|
|
52
|
-
setAuthState({
|
|
53
|
-
user: null,
|
|
54
|
-
tokens: null,
|
|
55
|
-
isAuthenticated: false
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
const updateUserListener = Hub.listen("auth", updateUser);
|
|
60
|
-
updateUser();
|
|
61
|
-
return () => {
|
|
62
|
-
updateUserListener();
|
|
63
|
-
};
|
|
64
|
-
}, []);
|
|
65
|
-
if (isAuthenticated === void 0) {
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
return /* @__PURE__ */jsx(AuthContext.Provider, {
|
|
69
|
-
value: {
|
|
70
|
-
signOut,
|
|
71
|
-
isAuthenticated,
|
|
72
|
-
user,
|
|
73
|
-
tokens
|
|
74
|
-
},
|
|
75
|
-
children
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
var useAuth = () => {
|
|
79
|
-
return React.useContext(AuthContext);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
3
|
// src/Auth.tsx
|
|
4
|
+
import { useNotifications as useNotifications4 } from "@ttoss/react-notifications";
|
|
5
|
+
import { Flex as Flex5 } from "@ttoss/ui";
|
|
6
|
+
import { useMachine } from "@xstate/react";
|
|
7
|
+
import { confirmResetPassword, confirmSignUp, resendSignUpCode, resetPassword, signIn, signUp } from "aws-amplify/auth";
|
|
83
8
|
import * as React6 from "react";
|
|
9
|
+
import { assign, createMachine } from "xstate";
|
|
84
10
|
|
|
85
11
|
// src/AuthCard.tsx
|
|
86
|
-
import * as React2 from "react";
|
|
87
|
-
import { Box, Button, Flex, Heading } from "@ttoss/ui";
|
|
88
12
|
import { useNotifications } from "@ttoss/react-notifications";
|
|
89
|
-
import {
|
|
90
|
-
|
|
13
|
+
import { Box, Button, Flex, Heading } from "@ttoss/ui";
|
|
14
|
+
import * as React from "react";
|
|
15
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var LogoContext = React.createContext({});
|
|
91
17
|
var LogoProvider = ({
|
|
92
18
|
children,
|
|
93
19
|
...values
|
|
94
20
|
}) => {
|
|
95
|
-
return /* @__PURE__ */
|
|
21
|
+
return /* @__PURE__ */jsx(LogoContext.Provider, {
|
|
96
22
|
value: values,
|
|
97
23
|
children
|
|
98
24
|
});
|
|
@@ -106,7 +32,7 @@ var AuthCard = ({
|
|
|
106
32
|
}) => {
|
|
107
33
|
const {
|
|
108
34
|
logo
|
|
109
|
-
} =
|
|
35
|
+
} = React.useContext(LogoContext);
|
|
110
36
|
const {
|
|
111
37
|
isLoading
|
|
112
38
|
} = useNotifications();
|
|
@@ -119,7 +45,7 @@ var AuthCard = ({
|
|
|
119
45
|
paddingY: "3xl",
|
|
120
46
|
backgroundColor: "surface"
|
|
121
47
|
},
|
|
122
|
-
children: [logo && /* @__PURE__ */
|
|
48
|
+
children: [logo && /* @__PURE__ */jsx(Flex, {
|
|
123
49
|
sx: {
|
|
124
50
|
width: "100%",
|
|
125
51
|
maxHeight: "90px",
|
|
@@ -131,7 +57,7 @@ var AuthCard = ({
|
|
|
131
57
|
sx: {
|
|
132
58
|
flexDirection: "column"
|
|
133
59
|
},
|
|
134
|
-
children: [/* @__PURE__ */
|
|
60
|
+
children: [/* @__PURE__ */jsx(Heading, {
|
|
135
61
|
as: "h2",
|
|
136
62
|
variant: "h2",
|
|
137
63
|
sx: {
|
|
@@ -145,7 +71,7 @@ var AuthCard = ({
|
|
|
145
71
|
gap: "xl",
|
|
146
72
|
marginTop: "2xl"
|
|
147
73
|
},
|
|
148
|
-
children: [/* @__PURE__ */
|
|
74
|
+
children: [/* @__PURE__ */jsx(Button, {
|
|
149
75
|
type: "submit",
|
|
150
76
|
"aria-label": "submit-button",
|
|
151
77
|
variant: "accent",
|
|
@@ -165,7 +91,7 @@ var AuthCard = ({
|
|
|
165
91
|
// src/AuthConfirmSignUp.tsx
|
|
166
92
|
import { Form, FormFieldInput, useForm, yup, yupResolver } from "@ttoss/forms";
|
|
167
93
|
import { useI18n } from "@ttoss/react-i18n";
|
|
168
|
-
import { jsx as
|
|
94
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
169
95
|
var AuthConfirmSignUp = ({
|
|
170
96
|
email,
|
|
171
97
|
onConfirmSignUp
|
|
@@ -199,7 +125,7 @@ var AuthConfirmSignUp = ({
|
|
|
199
125
|
const formMethods = useForm({
|
|
200
126
|
resolver: yupResolver(schema)
|
|
201
127
|
});
|
|
202
|
-
return /* @__PURE__ */
|
|
128
|
+
return /* @__PURE__ */jsx2(Form, {
|
|
203
129
|
...formMethods,
|
|
204
130
|
onSubmit: ({
|
|
205
131
|
code
|
|
@@ -209,7 +135,7 @@ var AuthConfirmSignUp = ({
|
|
|
209
135
|
email
|
|
210
136
|
});
|
|
211
137
|
},
|
|
212
|
-
children: /* @__PURE__ */
|
|
138
|
+
children: /* @__PURE__ */jsx2(AuthCard, {
|
|
213
139
|
buttonLabel: intl.formatMessage({
|
|
214
140
|
id: "UNttd+",
|
|
215
141
|
defaultMessage: [{
|
|
@@ -225,7 +151,7 @@ var AuthConfirmSignUp = ({
|
|
|
225
151
|
"value": "Confirmation"
|
|
226
152
|
}]
|
|
227
153
|
}),
|
|
228
|
-
children: /* @__PURE__ */
|
|
154
|
+
children: /* @__PURE__ */jsx2(FormFieldInput, {
|
|
229
155
|
name: "code",
|
|
230
156
|
label: intl.formatMessage({
|
|
231
157
|
id: "KY2T6J",
|
|
@@ -240,11 +166,11 @@ var AuthConfirmSignUp = ({
|
|
|
240
166
|
};
|
|
241
167
|
|
|
242
168
|
// src/AuthForgotPassword.tsx
|
|
243
|
-
import { Button as Button2, Link, Text } from "@ttoss/ui";
|
|
244
169
|
import { Form as Form2, FormFieldInput as FormFieldInput2, useForm as useForm2, yup as yup2, yupResolver as yupResolver2 } from "@ttoss/forms";
|
|
245
|
-
import { NotificationsBox } from "@ttoss/react-notifications";
|
|
246
170
|
import { useI18n as useI18n2 } from "@ttoss/react-i18n";
|
|
247
|
-
import {
|
|
171
|
+
import { NotificationsBox } from "@ttoss/react-notifications";
|
|
172
|
+
import { Button as Button2, Link, Text } from "@ttoss/ui";
|
|
173
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
248
174
|
var AuthForgotPassword = ({
|
|
249
175
|
onForgotPassword,
|
|
250
176
|
onCancel,
|
|
@@ -272,7 +198,7 @@ var AuthForgotPassword = ({
|
|
|
272
198
|
resolver: yupResolver2(schema),
|
|
273
199
|
mode: "onBlur"
|
|
274
200
|
});
|
|
275
|
-
return /* @__PURE__ */
|
|
201
|
+
return /* @__PURE__ */jsx3(Form2, {
|
|
276
202
|
...formMethods,
|
|
277
203
|
sx: {
|
|
278
204
|
maxWidth: "390px"
|
|
@@ -300,7 +226,7 @@ var AuthForgotPassword = ({
|
|
|
300
226
|
"value": "Recovering Password"
|
|
301
227
|
}]
|
|
302
228
|
}),
|
|
303
|
-
extraButton: /* @__PURE__ */
|
|
229
|
+
extraButton: /* @__PURE__ */jsx3(Button2, {
|
|
304
230
|
sx: {
|
|
305
231
|
textAlign: "center",
|
|
306
232
|
display: "initial"
|
|
@@ -315,7 +241,7 @@ var AuthForgotPassword = ({
|
|
|
315
241
|
}]
|
|
316
242
|
})
|
|
317
243
|
}),
|
|
318
|
-
children: [/* @__PURE__ */
|
|
244
|
+
children: [/* @__PURE__ */jsx3(FormFieldInput2, {
|
|
319
245
|
name: "email",
|
|
320
246
|
label: intl.formatMessage({
|
|
321
247
|
id: "XreZg+",
|
|
@@ -324,7 +250,7 @@ var AuthForgotPassword = ({
|
|
|
324
250
|
"value": "Registered Email"
|
|
325
251
|
}]
|
|
326
252
|
})
|
|
327
|
-
}), /* @__PURE__ */
|
|
253
|
+
}), /* @__PURE__ */jsx3(NotificationsBox, {}), /* @__PURE__ */jsx3(Text, {
|
|
328
254
|
sx: {
|
|
329
255
|
marginTop: "xl",
|
|
330
256
|
cursor: "pointer"
|
|
@@ -343,18 +269,16 @@ var AuthForgotPassword = ({
|
|
|
343
269
|
});
|
|
344
270
|
};
|
|
345
271
|
|
|
346
|
-
// src/AuthForgotPasswordResetPassword.tsx
|
|
347
|
-
import * as React3 from "react";
|
|
348
|
-
import { Button as Button3 } from "@ttoss/ui";
|
|
349
|
-
import { Form as Form3, FormFieldInput as FormFieldInput3, FormFieldPassword, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
|
|
350
|
-
import { NotificationsBox as NotificationsBox2 } from "@ttoss/react-notifications";
|
|
351
|
-
|
|
352
272
|
// ../cloud-auth/src/config.ts
|
|
353
273
|
var PASSWORD_MINIMUM_LENGTH = 8;
|
|
354
274
|
|
|
355
275
|
// src/AuthForgotPasswordResetPassword.tsx
|
|
276
|
+
import { Form as Form3, FormFieldInput as FormFieldInput3, FormFieldPassword, useForm as useForm3, yup as yup3, yupResolver as yupResolver3 } from "@ttoss/forms";
|
|
356
277
|
import { useI18n as useI18n3 } from "@ttoss/react-i18n";
|
|
357
|
-
import {
|
|
278
|
+
import { NotificationsBox as NotificationsBox2 } from "@ttoss/react-notifications";
|
|
279
|
+
import { Button as Button3 } from "@ttoss/ui";
|
|
280
|
+
import * as React2 from "react";
|
|
281
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
358
282
|
var AuthForgotPasswordResetPassword = ({
|
|
359
283
|
email,
|
|
360
284
|
onForgotPasswordResetPassword,
|
|
@@ -363,7 +287,7 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
363
287
|
const {
|
|
364
288
|
intl
|
|
365
289
|
} = useI18n3();
|
|
366
|
-
const schema =
|
|
290
|
+
const schema = React2.useMemo(() => {
|
|
367
291
|
return yup3.object().shape({
|
|
368
292
|
code: yup3.string().required(intl.formatMessage({
|
|
369
293
|
id: "0XOzcH",
|
|
@@ -426,7 +350,7 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
426
350
|
resolver: yupResolver3(schema),
|
|
427
351
|
mode: "onBlur"
|
|
428
352
|
});
|
|
429
|
-
return /* @__PURE__ */
|
|
353
|
+
return /* @__PURE__ */jsx4(Form3, {
|
|
430
354
|
...formMethods,
|
|
431
355
|
sx: {
|
|
432
356
|
maxWidth: "390px"
|
|
@@ -457,7 +381,7 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
457
381
|
"value": "Recovering Password"
|
|
458
382
|
}]
|
|
459
383
|
}),
|
|
460
|
-
extraButton: /* @__PURE__ */
|
|
384
|
+
extraButton: /* @__PURE__ */jsx4(Button3, {
|
|
461
385
|
sx: {
|
|
462
386
|
textAlign: "center",
|
|
463
387
|
display: "initial"
|
|
@@ -472,7 +396,7 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
472
396
|
}]
|
|
473
397
|
})
|
|
474
398
|
}),
|
|
475
|
-
children: [/* @__PURE__ */
|
|
399
|
+
children: [/* @__PURE__ */jsx4(FormFieldInput3, {
|
|
476
400
|
name: "code",
|
|
477
401
|
label: intl.formatMessage({
|
|
478
402
|
id: "42HafR",
|
|
@@ -481,7 +405,7 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
481
405
|
"value": "Code"
|
|
482
406
|
}]
|
|
483
407
|
})
|
|
484
|
-
}), /* @__PURE__ */
|
|
408
|
+
}), /* @__PURE__ */jsx4(FormFieldPassword, {
|
|
485
409
|
name: "password",
|
|
486
410
|
label: intl.formatMessage({
|
|
487
411
|
id: "PylVqx",
|
|
@@ -490,7 +414,7 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
490
414
|
"value": "Password"
|
|
491
415
|
}]
|
|
492
416
|
})
|
|
493
|
-
}), /* @__PURE__ */
|
|
417
|
+
}), /* @__PURE__ */jsx4(FormFieldPassword, {
|
|
494
418
|
name: "confirmPassword",
|
|
495
419
|
label: intl.formatMessage({
|
|
496
420
|
id: "lY+cuM",
|
|
@@ -499,18 +423,18 @@ var AuthForgotPasswordResetPassword = ({
|
|
|
499
423
|
"value": "Confirm password"
|
|
500
424
|
}]
|
|
501
425
|
})
|
|
502
|
-
}), /* @__PURE__ */
|
|
426
|
+
}), /* @__PURE__ */jsx4(NotificationsBox2, {})]
|
|
503
427
|
})
|
|
504
428
|
});
|
|
505
429
|
};
|
|
506
430
|
|
|
507
431
|
// src/AuthFullScreen.tsx
|
|
508
432
|
import { Flex as Flex2 } from "@ttoss/ui";
|
|
509
|
-
import { jsx as
|
|
433
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
510
434
|
var AuthFullScreen = ({
|
|
511
435
|
children
|
|
512
436
|
}) => {
|
|
513
|
-
return /* @__PURE__ */
|
|
437
|
+
return /* @__PURE__ */jsx5(Flex2, {
|
|
514
438
|
sx: {
|
|
515
439
|
height: "100vh",
|
|
516
440
|
width: "100vw",
|
|
@@ -525,12 +449,91 @@ var AuthFullScreen = ({
|
|
|
525
449
|
});
|
|
526
450
|
};
|
|
527
451
|
|
|
452
|
+
// src/AuthProvider.tsx
|
|
453
|
+
import { fetchAuthSession, fetchUserAttributes, getCurrentUser, signOut as awsSignOut } from "aws-amplify/auth";
|
|
454
|
+
import { Hub } from "aws-amplify/utils";
|
|
455
|
+
import * as React3 from "react";
|
|
456
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
457
|
+
var signOut = () => {
|
|
458
|
+
return awsSignOut();
|
|
459
|
+
};
|
|
460
|
+
var AuthContext = React3.createContext({
|
|
461
|
+
signOut,
|
|
462
|
+
isAuthenticated: false,
|
|
463
|
+
user: null,
|
|
464
|
+
tokens: null
|
|
465
|
+
});
|
|
466
|
+
var AuthProvider = ({
|
|
467
|
+
children
|
|
468
|
+
}) => {
|
|
469
|
+
const [{
|
|
470
|
+
user,
|
|
471
|
+
tokens,
|
|
472
|
+
isAuthenticated
|
|
473
|
+
}, setAuthState] = React3.useState({
|
|
474
|
+
user: null,
|
|
475
|
+
tokens: null,
|
|
476
|
+
isAuthenticated: void 0
|
|
477
|
+
});
|
|
478
|
+
React3.useEffect(() => {
|
|
479
|
+
const updateUser = () => {
|
|
480
|
+
getCurrentUser().then(async ({
|
|
481
|
+
userId
|
|
482
|
+
}) => {
|
|
483
|
+
const [session, user2] = await Promise.all([fetchAuthSession(), fetchUserAttributes()]);
|
|
484
|
+
const idToken = session.tokens?.idToken?.toString() ?? "";
|
|
485
|
+
const accessToken = session.tokens?.accessToken.toString() ?? "";
|
|
486
|
+
setAuthState({
|
|
487
|
+
user: {
|
|
488
|
+
id: userId,
|
|
489
|
+
email: user2.email ?? "",
|
|
490
|
+
emailVerified: user2.email_verified ?? ""
|
|
491
|
+
},
|
|
492
|
+
tokens: {
|
|
493
|
+
idToken,
|
|
494
|
+
accessToken,
|
|
495
|
+
refreshToken: ""
|
|
496
|
+
},
|
|
497
|
+
isAuthenticated: true
|
|
498
|
+
});
|
|
499
|
+
}).catch(e => {
|
|
500
|
+
console.error(e);
|
|
501
|
+
setAuthState({
|
|
502
|
+
user: null,
|
|
503
|
+
tokens: null,
|
|
504
|
+
isAuthenticated: false
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
const updateUserListener = Hub.listen("auth", updateUser);
|
|
509
|
+
updateUser();
|
|
510
|
+
return () => {
|
|
511
|
+
updateUserListener();
|
|
512
|
+
};
|
|
513
|
+
}, []);
|
|
514
|
+
if (isAuthenticated === void 0) {
|
|
515
|
+
return null;
|
|
516
|
+
}
|
|
517
|
+
return /* @__PURE__ */jsx6(AuthContext.Provider, {
|
|
518
|
+
value: {
|
|
519
|
+
signOut,
|
|
520
|
+
isAuthenticated,
|
|
521
|
+
user,
|
|
522
|
+
tokens
|
|
523
|
+
},
|
|
524
|
+
children
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
var useAuth = () => {
|
|
528
|
+
return React3.useContext(AuthContext);
|
|
529
|
+
};
|
|
530
|
+
|
|
528
531
|
// src/AuthSignIn.tsx
|
|
529
|
-
import * as React4 from "react";
|
|
530
|
-
import { Button as Button4, Flex as Flex3, Link as Link2, Text as Text2 } from "@ttoss/ui";
|
|
531
532
|
import { Form as Form4, FormFieldInput as FormFieldInput4, FormFieldPassword as FormFieldPassword2, useForm as useForm4, yup as yup4, yupResolver as yupResolver4 } from "@ttoss/forms";
|
|
532
|
-
import { NotificationsBox as NotificationsBox3, useNotifications as useNotifications2 } from "@ttoss/react-notifications";
|
|
533
533
|
import { useI18n as useI18n4 } from "@ttoss/react-i18n";
|
|
534
|
+
import { NotificationsBox as NotificationsBox3, useNotifications as useNotifications2 } from "@ttoss/react-notifications";
|
|
535
|
+
import { Button as Button4, Flex as Flex3, Link as Link2, Text as Text2 } from "@ttoss/ui";
|
|
536
|
+
import * as React4 from "react";
|
|
534
537
|
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
535
538
|
var AuthSignIn = ({
|
|
536
539
|
onSignIn,
|
|
@@ -682,16 +685,13 @@ var AuthSignIn = ({
|
|
|
682
685
|
};
|
|
683
686
|
|
|
684
687
|
// src/AuthSignUp.tsx
|
|
685
|
-
import
|
|
686
|
-
import { Flex as Flex4, Link as Link3, Text as Text3 } from "@ttoss/ui";
|
|
687
|
-
import { Form as Form5, FormFieldInput as FormFieldInput5, FormFieldPassword as FormFieldPassword3, useForm as useForm5, yup as yup5, yupResolver as yupResolver5 } from "@ttoss/forms";
|
|
688
|
-
import { NotificationsBox as NotificationsBox4, useNotifications as useNotifications3 } from "@ttoss/react-notifications";
|
|
688
|
+
import { Form as Form5, FormFieldCheckbox, FormFieldInput as FormFieldInput5, FormFieldPassword as FormFieldPassword3, useForm as useForm5, yup as yup5, yupResolver as yupResolver5 } from "@ttoss/forms";
|
|
689
689
|
import { useI18n as useI18n5 } from "@ttoss/react-i18n";
|
|
690
|
-
import {
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
690
|
+
import { NotificationsBox as NotificationsBox4, useNotifications as useNotifications3 } from "@ttoss/react-notifications";
|
|
691
|
+
import { Flex as Flex4, Link as Link3, Text as Text3 } from "@ttoss/ui";
|
|
692
|
+
import * as React5 from "react";
|
|
693
|
+
import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
694
|
+
var AuthSignUp = props => {
|
|
695
695
|
const {
|
|
696
696
|
intl
|
|
697
697
|
} = useI18n5();
|
|
@@ -701,61 +701,106 @@ var AuthSignUp = ({
|
|
|
701
701
|
React5.useEffect(() => {
|
|
702
702
|
setNotifications(void 0);
|
|
703
703
|
}, [setNotifications]);
|
|
704
|
-
const schema =
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
704
|
+
const schema = React5.useMemo(() => {
|
|
705
|
+
return yup5.object().shape({
|
|
706
|
+
email: yup5.string().required(intl.formatMessage({
|
|
707
|
+
id: "d1YCuH",
|
|
708
|
+
defaultMessage: [{
|
|
709
|
+
"type": 0,
|
|
710
|
+
"value": "Enter your email address"
|
|
711
|
+
}]
|
|
712
|
+
})).email(intl.formatMessage({
|
|
713
|
+
id: "OhDL0i",
|
|
714
|
+
defaultMessage: [{
|
|
715
|
+
"type": 0,
|
|
716
|
+
"value": "Invalid email"
|
|
717
|
+
}]
|
|
718
|
+
})),
|
|
719
|
+
password: yup5.string().required(intl.formatMessage({
|
|
720
|
+
id: "kdFYba",
|
|
721
|
+
defaultMessage: [{
|
|
722
|
+
"type": 0,
|
|
723
|
+
"value": "Password field is required"
|
|
724
|
+
}]
|
|
725
|
+
})).min(PASSWORD_MINIMUM_LENGTH, intl.formatMessage({
|
|
726
|
+
id: "TZ4WUk",
|
|
727
|
+
defaultMessage: [{
|
|
728
|
+
"type": 0,
|
|
729
|
+
"value": "Password requires "
|
|
730
|
+
}, {
|
|
731
|
+
"type": 1,
|
|
732
|
+
"value": "value"
|
|
733
|
+
}, {
|
|
734
|
+
"type": 0,
|
|
735
|
+
"value": " characters"
|
|
736
|
+
}]
|
|
732
737
|
}, {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
"
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
738
|
+
value: PASSWORD_MINIMUM_LENGTH
|
|
739
|
+
})).trim(),
|
|
740
|
+
confirmPassword: yup5.string().required(intl.formatMessage({
|
|
741
|
+
id: "NJ57Qj",
|
|
742
|
+
defaultMessage: [{
|
|
743
|
+
"type": 0,
|
|
744
|
+
"value": "Confirm password field is required"
|
|
745
|
+
}]
|
|
746
|
+
})).oneOf([yup5.ref("password")], intl.formatMessage({
|
|
747
|
+
id: "WU/CqP",
|
|
748
|
+
defaultMessage: [{
|
|
749
|
+
"type": 0,
|
|
750
|
+
"value": "Passwords are not the same"
|
|
751
|
+
}]
|
|
752
|
+
})),
|
|
753
|
+
signUpTerms: yup5.boolean().oneOf([props.signUpTerms?.isRequired], "Voc\xEA deve aceitar os Termos e Condi\xE7\xF5es.")
|
|
754
|
+
});
|
|
755
|
+
}, [intl, props.signUpTerms?.isRequired]);
|
|
756
|
+
const signUpTermsLabel = React5.useMemo(() => {
|
|
757
|
+
if (!props.signUpTerms) {
|
|
758
|
+
return null;
|
|
759
|
+
}
|
|
760
|
+
const signUpTermsFirstMessage = intl.formatMessage({
|
|
761
|
+
id: "Co3exe",
|
|
747
762
|
defaultMessage: [{
|
|
748
763
|
"type": 0,
|
|
749
|
-
"value": "
|
|
764
|
+
"value": "By signing up, you agree to the following Terms and Conditions."
|
|
750
765
|
}]
|
|
751
|
-
})
|
|
752
|
-
|
|
766
|
+
});
|
|
767
|
+
const termsLinks = props.signUpTerms.termsAndConditions.map((term, index, termsAndConditions) => {
|
|
768
|
+
const finalPunctuation = index === termsAndConditions.length - 1 ? "." : ", ";
|
|
769
|
+
return /* @__PURE__ */jsxs5(React5.Fragment, {
|
|
770
|
+
children: [/* @__PURE__ */jsx8(Link3, {
|
|
771
|
+
href: term.url,
|
|
772
|
+
target: "_blank",
|
|
773
|
+
rel: "noreferrer",
|
|
774
|
+
children: term.label
|
|
775
|
+
}, index), finalPunctuation]
|
|
776
|
+
}, index);
|
|
777
|
+
});
|
|
778
|
+
const label = /* @__PURE__ */jsxs5(Text3, {
|
|
779
|
+
children: [signUpTermsFirstMessage, " ", termsLinks]
|
|
780
|
+
});
|
|
781
|
+
return label;
|
|
782
|
+
}, [intl, props.signUpTerms]);
|
|
783
|
+
const signUpTermsNode = React5.useMemo(() => {
|
|
784
|
+
if (!props.signUpTerms) {
|
|
785
|
+
return null;
|
|
786
|
+
}
|
|
787
|
+
if (props.signUpTerms.isRequired) {
|
|
788
|
+
return /* @__PURE__ */jsx8(FormFieldCheckbox, {
|
|
789
|
+
name: "signUpTerms",
|
|
790
|
+
label: signUpTermsLabel
|
|
791
|
+
});
|
|
792
|
+
} else {
|
|
793
|
+
return /* @__PURE__ */jsx8(Fragment2, {
|
|
794
|
+
children: signUpTermsLabel
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}, [props.signUpTerms, signUpTermsLabel]);
|
|
753
798
|
const formMethods = useForm5({
|
|
754
799
|
mode: "all",
|
|
755
800
|
resolver: yupResolver5(schema)
|
|
756
801
|
});
|
|
757
802
|
const onSubmitForm = data => {
|
|
758
|
-
return onSignUp(data);
|
|
803
|
+
return props.onSignUp(data);
|
|
759
804
|
};
|
|
760
805
|
return /* @__PURE__ */jsx8(Form5, {
|
|
761
806
|
sx: {
|
|
@@ -784,7 +829,7 @@ var AuthSignUp = ({
|
|
|
784
829
|
sx: {
|
|
785
830
|
cursor: "pointer"
|
|
786
831
|
},
|
|
787
|
-
onClick: onReturnToSignIn,
|
|
832
|
+
onClick: props.onReturnToSignIn,
|
|
788
833
|
as: Link3,
|
|
789
834
|
children: intl.formatMessage({
|
|
790
835
|
id: "8GMUPk",
|
|
@@ -826,18 +871,13 @@ var AuthSignUp = ({
|
|
|
826
871
|
"value": "Confirm password"
|
|
827
872
|
}]
|
|
828
873
|
})
|
|
829
|
-
})]
|
|
874
|
+
}), signUpTermsNode]
|
|
830
875
|
}), /* @__PURE__ */jsx8(NotificationsBox4, {})]
|
|
831
876
|
})
|
|
832
877
|
});
|
|
833
878
|
};
|
|
834
879
|
|
|
835
880
|
// src/Auth.tsx
|
|
836
|
-
import { Flex as Flex5 } from "@ttoss/ui";
|
|
837
|
-
import { assign, createMachine } from "xstate";
|
|
838
|
-
import { confirmResetPassword, confirmSignUp, resendSignUpCode, resetPassword, signIn, signUp } from "aws-amplify/auth";
|
|
839
|
-
import { useMachine } from "@xstate/react";
|
|
840
|
-
import { useNotifications as useNotifications4 } from "@ttoss/react-notifications";
|
|
841
881
|
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
842
882
|
var authMachine = createMachine({
|
|
843
883
|
predictableActionArguments: true,
|
|
@@ -914,7 +954,7 @@ var authMachine = createMachine({
|
|
|
914
954
|
})
|
|
915
955
|
}
|
|
916
956
|
});
|
|
917
|
-
var AuthLogic =
|
|
957
|
+
var AuthLogic = props => {
|
|
918
958
|
const {
|
|
919
959
|
isAuthenticated
|
|
920
960
|
} = useAuth();
|
|
@@ -1068,7 +1108,8 @@ var AuthLogic = () => {
|
|
|
1068
1108
|
if (state.matches("signUp")) {
|
|
1069
1109
|
return /* @__PURE__ */jsx9(AuthSignUp, {
|
|
1070
1110
|
onSignUp,
|
|
1071
|
-
onReturnToSignIn
|
|
1111
|
+
onReturnToSignIn,
|
|
1112
|
+
signUpTerms: props.signUpTerms
|
|
1072
1113
|
});
|
|
1073
1114
|
}
|
|
1074
1115
|
if (state.matches("signUpConfirm")) {
|
|
@@ -1106,26 +1147,28 @@ var AuthLogic = () => {
|
|
|
1106
1147
|
}
|
|
1107
1148
|
});
|
|
1108
1149
|
};
|
|
1109
|
-
var Auth =
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
}
|
|
1150
|
+
var Auth = props => {
|
|
1151
|
+
const {
|
|
1152
|
+
layout = {
|
|
1153
|
+
fullScreen: true
|
|
1154
|
+
}
|
|
1155
|
+
} = props;
|
|
1115
1156
|
const withLogoNode = React6.useMemo(() => {
|
|
1116
1157
|
return /* @__PURE__ */jsx9(LogoProvider, {
|
|
1117
|
-
logo,
|
|
1118
|
-
children: /* @__PURE__ */jsx9(AuthLogic, {
|
|
1158
|
+
logo: props.logo,
|
|
1159
|
+
children: /* @__PURE__ */jsx9(AuthLogic, {
|
|
1160
|
+
signUpTerms: props.signUpTerms
|
|
1161
|
+
})
|
|
1119
1162
|
});
|
|
1120
|
-
}, [logo]);
|
|
1163
|
+
}, [props.logo, props.signUpTerms]);
|
|
1121
1164
|
if (layout.fullScreen) {
|
|
1122
|
-
if (layout.
|
|
1165
|
+
if (layout.sideContentPosition) {
|
|
1123
1166
|
return /* @__PURE__ */jsx9(AuthFullScreen, {
|
|
1124
1167
|
children: /* @__PURE__ */jsxs6(Flex5, {
|
|
1125
1168
|
sx: {
|
|
1126
1169
|
width: "100%",
|
|
1127
1170
|
height: "100%",
|
|
1128
|
-
flexDirection: layout.
|
|
1171
|
+
flexDirection: layout.sideContentPosition === "left" ? "row" : "row-reverse"
|
|
1129
1172
|
},
|
|
1130
1173
|
children: [/* @__PURE__ */jsx9(Flex5, {
|
|
1131
1174
|
sx: {
|
|
@@ -1135,7 +1178,7 @@ var Auth = ({
|
|
|
1135
1178
|
justifyContent: "center",
|
|
1136
1179
|
alignItems: "center"
|
|
1137
1180
|
},
|
|
1138
|
-
children: layout.
|
|
1181
|
+
children: layout.sideContent
|
|
1139
1182
|
}), /* @__PURE__ */jsx9(Flex5, {
|
|
1140
1183
|
sx: {
|
|
1141
1184
|
width: "100%",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,41 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
|
-
type User = {
|
|
5
|
-
id: string;
|
|
6
|
-
email: string;
|
|
7
|
-
emailVerified: string;
|
|
8
|
-
} | null;
|
|
9
|
-
type Tokens = {
|
|
10
|
-
idToken: string;
|
|
11
|
-
accessToken: string;
|
|
12
|
-
refreshToken: string;
|
|
13
|
-
} | null;
|
|
14
|
-
declare const AuthProvider: ({ children }: {
|
|
15
|
-
children: React.ReactNode;
|
|
16
|
-
}) => react_jsx_runtime.JSX.Element | null;
|
|
17
|
-
declare const useAuth: () => {
|
|
18
|
-
signOut: () => Promise<any>;
|
|
19
|
-
isAuthenticated: boolean;
|
|
20
|
-
user: User;
|
|
21
|
-
tokens: Tokens;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
4
|
type LogoContextProps = {
|
|
25
5
|
logo?: React.ReactNode;
|
|
26
6
|
children?: React.ReactNode;
|
|
27
7
|
};
|
|
28
8
|
|
|
29
|
-
type AuthLayout = {
|
|
30
|
-
fullScreen?: boolean;
|
|
31
|
-
sideImage?: React.ReactNode;
|
|
32
|
-
sideImagePosition?: 'left' | 'right';
|
|
33
|
-
};
|
|
34
|
-
type AuthProps = LogoContextProps & {
|
|
35
|
-
layout?: AuthLayout;
|
|
36
|
-
};
|
|
37
|
-
declare const Auth: ({ logo, layout }: AuthProps) => react_jsx_runtime.JSX.Element;
|
|
38
|
-
|
|
39
9
|
type OnSignInInput = {
|
|
40
10
|
email: string;
|
|
41
11
|
password: string;
|
|
@@ -60,4 +30,49 @@ type OnForgotPasswordResetPassword = (input: {
|
|
|
60
30
|
newPassword: string;
|
|
61
31
|
}) => void;
|
|
62
32
|
|
|
33
|
+
type AuthSignUpProps = {
|
|
34
|
+
onSignUp: OnSignUp;
|
|
35
|
+
onReturnToSignIn: () => void;
|
|
36
|
+
signUpTerms?: {
|
|
37
|
+
isRequired: boolean;
|
|
38
|
+
termsAndConditions: {
|
|
39
|
+
label: string;
|
|
40
|
+
url: string;
|
|
41
|
+
}[];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
type AuthLogicProps = {
|
|
46
|
+
signUpTerms?: AuthSignUpProps['signUpTerms'];
|
|
47
|
+
};
|
|
48
|
+
type AuthLayout = {
|
|
49
|
+
fullScreen?: boolean;
|
|
50
|
+
sideContent?: React.ReactNode;
|
|
51
|
+
sideContentPosition?: 'left' | 'right';
|
|
52
|
+
};
|
|
53
|
+
type AuthProps = LogoContextProps & AuthLogicProps & {
|
|
54
|
+
layout?: AuthLayout;
|
|
55
|
+
};
|
|
56
|
+
declare const Auth: (props: AuthProps) => react_jsx_runtime.JSX.Element;
|
|
57
|
+
|
|
58
|
+
type User = {
|
|
59
|
+
id: string;
|
|
60
|
+
email: string;
|
|
61
|
+
emailVerified: string;
|
|
62
|
+
} | null;
|
|
63
|
+
type Tokens = {
|
|
64
|
+
idToken: string;
|
|
65
|
+
accessToken: string;
|
|
66
|
+
refreshToken: string;
|
|
67
|
+
} | null;
|
|
68
|
+
declare const AuthProvider: ({ children }: {
|
|
69
|
+
children: React.ReactNode;
|
|
70
|
+
}) => react_jsx_runtime.JSX.Element | null;
|
|
71
|
+
declare const useAuth: () => {
|
|
72
|
+
signOut: () => Promise<any>;
|
|
73
|
+
isAuthenticated: boolean;
|
|
74
|
+
user: User;
|
|
75
|
+
tokens: Tokens;
|
|
76
|
+
};
|
|
77
|
+
|
|
63
78
|
export { Auth, type AuthProps, AuthProvider, type OnConfirmSignUp, type OnForgotPassword, type OnForgotPasswordResetPassword, type OnSignIn, type OnSignInInput, type OnSignUp, type OnSignUpInput, useAuth };
|
package/i18n/compiled/en.json
CHANGED
package/i18n/lang/en.json
CHANGED
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"defaultMessage": "Forgot password?",
|
|
36
36
|
"description": "Forgot password?"
|
|
37
37
|
},
|
|
38
|
+
"Co3exe": {
|
|
39
|
+
"defaultMessage": "By signing up, you agree to the following Terms and Conditions."
|
|
40
|
+
},
|
|
38
41
|
"EZ3YF2": {
|
|
39
42
|
"defaultMessage": "Sign up",
|
|
40
43
|
"description": "Sign up"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/react-auth",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "ttoss authentication module for React apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "ttoss",
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@xstate/react": "^3.2.2",
|
|
29
29
|
"xstate": "^4.38.3",
|
|
30
|
-
"@ttoss/forms": "^0.
|
|
30
|
+
"@ttoss/forms": "^0.27.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"aws-amplify": "^6.0.0",
|
|
34
34
|
"react": ">=16.8.0",
|
|
35
|
-
"@ttoss/react-i18n": "^2.0.
|
|
36
|
-
"@ttoss/
|
|
37
|
-
"@ttoss/
|
|
35
|
+
"@ttoss/react-i18n": "^2.0.9",
|
|
36
|
+
"@ttoss/react-notifications": "^1.24.65",
|
|
37
|
+
"@ttoss/ui": "^5.0.15"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@jest/globals": "^29.7.0",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"jest": "^29.7.0",
|
|
44
44
|
"react": "^19.0.0",
|
|
45
45
|
"tsup": "^8.3.5",
|
|
46
|
-
"@ttoss/cloud-auth": "^0.12.26",
|
|
47
46
|
"@ttoss/config": "^1.35.2",
|
|
48
|
-
"@ttoss/
|
|
47
|
+
"@ttoss/cloud-auth": "^0.12.27",
|
|
49
48
|
"@ttoss/i18n-cli": "^0.7.26",
|
|
50
|
-
"@ttoss/
|
|
51
|
-
"@ttoss/react-
|
|
52
|
-
"@ttoss/
|
|
49
|
+
"@ttoss/react-i18n": "^2.0.9",
|
|
50
|
+
"@ttoss/react-notifications": "^1.24.65",
|
|
51
|
+
"@ttoss/test-utils": "^2.1.22",
|
|
52
|
+
"@ttoss/ui": "^5.0.15"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
55
55
|
"React",
|