@ttoss/react-auth 2.0.9 → 2.1.1

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.
@@ -1,159 +0,0 @@
1
- import * as React from 'react';
2
- import { AuthCard } from './AuthCard';
3
- import { Button, Flex, Link, Text } from '@ttoss/ui';
4
- import {
5
- Form,
6
- FormFieldInput,
7
- FormFieldPassword,
8
- useForm,
9
- yup,
10
- yupResolver,
11
- } from '@ttoss/forms';
12
- import { NotificationsBox, useNotifications } from '@ttoss/react-notifications';
13
- import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
14
- import { useI18n } from '@ttoss/react-i18n';
15
- import type { OnSignIn, OnSignInInput } from './types';
16
-
17
- export type AuthSignInProps = {
18
- onSignIn: OnSignIn;
19
- onSignUp: () => void;
20
- onForgotPassword: () => void;
21
- defaultValues?: Partial<OnSignInInput>;
22
- urlLogo?: string;
23
- };
24
-
25
- export const AuthSignIn = ({
26
- onSignIn,
27
- onSignUp,
28
- defaultValues,
29
- onForgotPassword,
30
- }: AuthSignInProps) => {
31
- const { intl } = useI18n();
32
- const { setNotifications } = useNotifications();
33
-
34
- React.useEffect(() => {
35
- setNotifications(undefined);
36
- }, [setNotifications]);
37
-
38
- const schema = yup.object().shape({
39
- email: yup
40
- .string()
41
- .required(
42
- intl.formatMessage({
43
- description: 'Email is a required field.',
44
- defaultMessage: 'Enter your email address',
45
- })
46
- )
47
- .email(
48
- intl.formatMessage({
49
- description: 'Invalid email.',
50
- defaultMessage: 'Please, insert a valid e-mail',
51
- })
52
- ),
53
- password: yup
54
- .string()
55
- .required(
56
- intl.formatMessage({
57
- description: 'Password is required.',
58
- defaultMessage: 'Password field is required',
59
- })
60
- )
61
- .min(
62
- PASSWORD_MINIMUM_LENGTH,
63
- intl.formatMessage(
64
- {
65
- description: 'Password must be at least {value} characters long.',
66
- defaultMessage: 'Password requires {value} characters',
67
- },
68
- { value: PASSWORD_MINIMUM_LENGTH }
69
- )
70
- )
71
- .trim(),
72
- // remember: yup.boolean(),
73
- });
74
-
75
- const formMethods = useForm<OnSignInInput>({
76
- defaultValues,
77
- mode: 'onBlur',
78
- resolver: yupResolver(schema),
79
- });
80
-
81
- const onSubmitForm = (data: OnSignInInput) => {
82
- return onSignIn(data);
83
- };
84
-
85
- return (
86
- <Form
87
- sx={{ maxWidth: '390px', width: '100%' }}
88
- {...formMethods}
89
- onSubmit={onSubmitForm}
90
- >
91
- <AuthCard
92
- title={intl.formatMessage({
93
- description: 'Sign in title.',
94
- defaultMessage: 'Log in',
95
- })}
96
- buttonLabel={intl.formatMessage({
97
- description: 'Button label.',
98
- defaultMessage: 'Log in',
99
- })}
100
- isValidForm={formMethods.formState.isValid}
101
- extraButton={
102
- <Button
103
- type="button"
104
- variant="secondary"
105
- sx={{ textAlign: 'center', display: 'initial' }}
106
- onClick={onSignUp}
107
- aria-label="sign-up"
108
- >
109
- {intl.formatMessage({
110
- description: 'Sign up',
111
- defaultMessage: 'Sign up',
112
- })}
113
- </Button>
114
- }
115
- >
116
- <Flex sx={{ flexDirection: 'column', gap: 'xl' }}>
117
- <FormFieldInput
118
- name="email"
119
- label={intl.formatMessage({
120
- description: 'Email label.',
121
- defaultMessage: 'Email',
122
- })}
123
- />
124
- <FormFieldPassword
125
- name="password"
126
- label={intl.formatMessage({
127
- description: 'Password label.',
128
- defaultMessage: 'Password',
129
- })}
130
- />
131
- </Flex>
132
-
133
- <Flex sx={{ justifyContent: 'space-between', marginTop: 'lg' }}>
134
- {/* TODO: temporally commented */}
135
- {/* <FormFieldCheckbox
136
- name="remember"
137
- label={intl.formatMessage({
138
- description: 'Remember',
139
- defaultMessage: 'Remember',
140
- })}
141
- /> */}
142
-
143
- <Text
144
- sx={{ marginLeft: 'auto', cursor: 'pointer' }}
145
- as={Link}
146
- onClick={onForgotPassword}
147
- >
148
- {intl.formatMessage({
149
- description: 'Forgot password?',
150
- defaultMessage: 'Forgot password?',
151
- })}
152
- </Text>
153
- </Flex>
154
-
155
- <NotificationsBox />
156
- </AuthCard>
157
- </Form>
158
- );
159
- };
@@ -1,143 +0,0 @@
1
- import * as React from 'react';
2
- import { AuthCard } from './AuthCard';
3
- import { Flex, Link, Text } from '@ttoss/ui';
4
- import {
5
- Form,
6
- FormFieldInput,
7
- FormFieldPassword,
8
- useForm,
9
- yup,
10
- yupResolver,
11
- } from '@ttoss/forms';
12
- import { NotificationsBox, useNotifications } from '@ttoss/react-notifications';
13
- import { PASSWORD_MINIMUM_LENGTH } from '@ttoss/cloud-auth';
14
- import { useI18n } from '@ttoss/react-i18n';
15
- import type { OnSignUp, OnSignUpInput } from './types';
16
-
17
- export type AuthSignUpProps = {
18
- onSignUp: OnSignUp;
19
- onReturnToSignIn: () => void;
20
- };
21
-
22
- export const AuthSignUp = ({ onSignUp, onReturnToSignIn }: AuthSignUpProps) => {
23
- const { intl } = useI18n();
24
- const { setNotifications } = useNotifications();
25
-
26
- React.useEffect(() => {
27
- setNotifications(undefined);
28
- }, [setNotifications]);
29
-
30
- const schema = yup.object().shape({
31
- email: yup
32
- .string()
33
- .required(
34
- intl.formatMessage({
35
- description: 'Email is a required field.',
36
- defaultMessage: 'Enter your email address',
37
- })
38
- )
39
- .email(
40
- intl.formatMessage({
41
- description: 'Invalid email.',
42
- defaultMessage: 'Invalid email',
43
- })
44
- ),
45
- password: yup
46
- .string()
47
- .required(
48
- intl.formatMessage({
49
- description: 'Password is required.',
50
- defaultMessage: 'Password field is required',
51
- })
52
- )
53
- .min(
54
- PASSWORD_MINIMUM_LENGTH,
55
- intl.formatMessage(
56
- {
57
- description: 'Password must be at least {value} characters long.',
58
- defaultMessage: 'Password requires {value} characters',
59
- },
60
- { value: PASSWORD_MINIMUM_LENGTH }
61
- )
62
- )
63
- .trim(),
64
- confirmPassword: yup
65
- .string()
66
- .required(
67
- intl.formatMessage({
68
- description: 'Confirm Password is required.',
69
- defaultMessage: 'Confirm password field is required',
70
- })
71
- )
72
- .oneOf(
73
- [yup.ref('password')],
74
- intl.formatMessage({
75
- description: 'Passwords are not the same',
76
- defaultMessage: 'Passwords are not the same',
77
- })
78
- ),
79
- });
80
-
81
- const formMethods = useForm<OnSignUpInput>({
82
- mode: 'all',
83
- resolver: yupResolver(schema),
84
- });
85
-
86
- const onSubmitForm = (data: OnSignUpInput) => {
87
- return onSignUp(data);
88
- };
89
-
90
- return (
91
- <Form
92
- sx={{ maxWidth: '390px', width: '100%' }}
93
- {...formMethods}
94
- onSubmit={onSubmitForm}
95
- >
96
- <AuthCard
97
- buttonLabel={intl.formatMessage({
98
- description: 'Create account.',
99
- defaultMessage: 'Sign up',
100
- })}
101
- title={intl.formatMessage({
102
- description: 'Title on sign up.',
103
- defaultMessage: 'Sign up',
104
- })}
105
- isValidForm={formMethods.formState.isValid}
106
- extraButton={
107
- <Text sx={{ cursor: 'pointer' }} onClick={onReturnToSignIn} as={Link}>
108
- {intl.formatMessage({
109
- description: 'Link to sign in on sign up.',
110
- defaultMessage: "I'm already registered",
111
- })}
112
- </Text>
113
- }
114
- >
115
- <Flex sx={{ flexDirection: 'column', gap: 'xl' }}>
116
- <FormFieldInput
117
- name="email"
118
- label={intl.formatMessage({
119
- description: 'Email label.',
120
- defaultMessage: 'Email',
121
- })}
122
- />
123
- <FormFieldPassword
124
- name="password"
125
- label={intl.formatMessage({
126
- description: 'Password label.',
127
- defaultMessage: 'Password',
128
- })}
129
- />
130
- <FormFieldPassword
131
- name="confirmPassword"
132
- label={intl.formatMessage({
133
- description: 'Confirm Password label.',
134
- defaultMessage: 'Confirm password',
135
- })}
136
- />
137
- </Flex>
138
-
139
- <NotificationsBox />
140
- </AuthCard>
141
- </Form>
142
- );
143
- };
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { AuthProvider, useAuth } from './AuthProvider';
2
- export { Auth } from './Auth';
3
- export * from './types';
package/src/types.ts DELETED
@@ -1,24 +0,0 @@
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
- confirmPassword: string;
12
- };
13
-
14
- export type OnSignUp = (input: OnSignUpInput) => void;
15
-
16
- export type OnConfirmSignUp = (input: { email: string; code: string }) => void;
17
-
18
- export type OnForgotPassword = (input: { email: string }) => void;
19
-
20
- export type OnForgotPasswordResetPassword = (input: {
21
- email: string;
22
- code: string;
23
- newPassword: string;
24
- }) => void;