@ttoss/react-auth 1.1.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.
@@ -0,0 +1,97 @@
1
+ import { AuthCard } from './AuthCard';
2
+ import { Form, FormFieldInput, useForm, yup, yupResolver } from '@ttoss/forms';
3
+ import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
4
+ import { useI18n } from '@ttoss/react-i18n';
5
+ import type { OnSignUp, OnSignUpInput } from './types';
6
+
7
+ export type AuthSignUpProps = {
8
+ onSignUp: OnSignUp;
9
+ onReturnToSignIn: () => void;
10
+ };
11
+
12
+ export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
13
+ const { intl } = useI18n();
14
+
15
+ const schema = yup.object().shape({
16
+ email: yup
17
+ .string()
18
+ .required(
19
+ intl.formatMessage({
20
+ description: 'Email is a required field.',
21
+ defaultMessage: 'Email field is required',
22
+ })
23
+ )
24
+ .email(
25
+ intl.formatMessage({
26
+ description: 'Invalid email.',
27
+ defaultMessage: 'Invalid email',
28
+ })
29
+ ),
30
+ password: yup
31
+ .string()
32
+ .required(
33
+ intl.formatMessage({
34
+ description: 'Password is required.',
35
+ defaultMessage: 'Password field is required',
36
+ })
37
+ )
38
+ .min(
39
+ PASSWORD_MINIMUM_LENGTH,
40
+ intl.formatMessage(
41
+ {
42
+ description: 'Password must be at least {value} characters long.',
43
+ defaultMessage: 'Password requires {value} characters',
44
+ },
45
+ { value: PASSWORD_MINIMUM_LENGTH }
46
+ )
47
+ )
48
+ .trim(),
49
+ });
50
+
51
+ const formMethods = useForm<OnSignUpInput>({
52
+ resolver: yupResolver(schema),
53
+ });
54
+
55
+ const onSubmitForm = (data: OnSignUpInput) => {
56
+ return onSignUp(data);
57
+ };
58
+
59
+ return (
60
+ <Form {...formMethods} onSubmit={onSubmitForm}>
61
+ <AuthCard
62
+ buttonLabel={intl.formatMessage({
63
+ description: 'Create account.',
64
+ defaultMessage: 'Create account',
65
+ })}
66
+ title={intl.formatMessage({
67
+ description: 'Title on sign up.',
68
+ defaultMessage: 'Register',
69
+ })}
70
+ links={[
71
+ {
72
+ label: intl.formatMessage({
73
+ description: 'Link to sign in on sign up.',
74
+ defaultMessage: 'Do you already have an account? Sign in',
75
+ }),
76
+ onClick: onReturnToSignIn,
77
+ },
78
+ ]}
79
+ >
80
+ <FormFieldInput
81
+ name="email"
82
+ label={intl.formatMessage({
83
+ description: 'Email label.',
84
+ defaultMessage: 'Email',
85
+ })}
86
+ />
87
+ <FormFieldInput
88
+ name="password"
89
+ label={intl.formatMessage({
90
+ description: 'Password label.',
91
+ defaultMessage: 'Password',
92
+ })}
93
+ />
94
+ </AuthCard>
95
+ </Form>
96
+ );
97
+ };
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { default as AuthProvider, useAuth } from './AuthProvider';
2
+ export { Auth } from './Auth';
3
+ export { AuthContainer } from './AuthContainer';
4
+ export * from './types';
package/src/types.ts ADDED
@@ -0,0 +1,15 @@
1
+ export type OnSignInInput = {
2
+ email: string;
3
+ password: string;
4
+ };
5
+
6
+ export type OnSignIn = (input: OnSignInInput) => void;
7
+
8
+ export type OnSignUpInput = {
9
+ email: string;
10
+ password: string;
11
+ };
12
+
13
+ export type OnSignUp = (input: OnSignUpInput) => void;
14
+
15
+ export type OnConfirmSignUp = (input: { email: string; code: string }) => void;