@umituz/react-native-auth 3.6.85 → 3.6.87
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/package.json +1 -1
- package/src/infrastructure/repositories/UserDocumentRepository.ts +85 -0
- package/src/infrastructure/services/AnonymousModeService.ts +5 -2
- package/src/infrastructure/services/AuthService.ts +13 -1
- package/src/infrastructure/utils/AuthValidation.ts +8 -4
- package/src/infrastructure/utils/UserMapper.ts +7 -3
- package/src/infrastructure/utils/error/errorCodeMapping.constants.ts +12 -109
- package/src/infrastructure/utils/error/mappings/actionCodeErrorMappings.ts +26 -0
- package/src/infrastructure/utils/error/mappings/authErrorMappings.ts +69 -0
- package/src/infrastructure/utils/error/mappings/configErrorMappings.ts +31 -0
- package/src/infrastructure/utils/error/mappings/errorMapping.types.ts +12 -0
- package/src/infrastructure/utils/error/mappings/networkErrorMappings.ts +22 -0
- package/src/infrastructure/utils/listener/anonymousHandler.ts +31 -0
- package/src/infrastructure/utils/listener/authStateHandler.ts +59 -0
- package/src/infrastructure/utils/listener/cleanupHandlers.ts +46 -0
- package/src/infrastructure/utils/listener/initializationHandlers.ts +26 -0
- package/src/infrastructure/utils/listener/listenerLifecycle.util.ts +19 -152
- package/src/infrastructure/utils/listener/listenerState.util.ts +21 -3
- package/src/infrastructure/utils/listener/setupListener.ts +63 -0
- package/src/presentation/hooks/registerForm/registerFormHandlers.ts +57 -0
- package/src/presentation/hooks/registerForm/registerFormSubmit.ts +64 -0
- package/src/presentation/hooks/registerForm/useRegisterForm.types.ts +39 -0
- package/src/presentation/hooks/useRegisterForm.ts +31 -109
- package/src/presentation/utils/form/formValidation.util.ts +23 -114
- package/src/presentation/utils/form/useFormField.hook.ts +2 -2
- package/src/presentation/utils/form/validation/formValidation.hook.ts +30 -0
- package/src/presentation/utils/form/validation/formValidation.types.ts +31 -0
- package/src/presentation/utils/form/validation/formValidation.utils.ts +17 -0
- package/src/presentation/utils/form/validation/formValidators.ts +86 -0
|
@@ -1,117 +1,26 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Form Validation
|
|
3
|
-
*
|
|
2
|
+
* Form Validation - Main Export
|
|
3
|
+
* Re-exports all form validation utilities
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
password: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export interface RegisterFormValues {
|
|
31
|
-
displayName?: string;
|
|
32
|
-
email: string;
|
|
33
|
-
password: string;
|
|
34
|
-
confirmPassword: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface ProfileFormValues {
|
|
38
|
-
displayName: string;
|
|
39
|
-
email: string;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function validateLoginForm(values: LoginFormValues, getErrorMessage: (key: string) => string): FormValidationResult {
|
|
43
|
-
const errors: FormValidationError[] = [];
|
|
44
|
-
|
|
45
|
-
const emailResult = validateEmail(values.email.trim());
|
|
46
|
-
if (!emailResult.isValid && emailResult.error) {
|
|
47
|
-
errors.push({ field: "email", message: getErrorMessage(emailResult.error) });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const passwordResult = validatePasswordForLogin(values.password);
|
|
51
|
-
if (!passwordResult.isValid && passwordResult.error) {
|
|
52
|
-
errors.push({ field: "password", message: getErrorMessage(passwordResult.error) });
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return { isValid: errors.length === 0, errors };
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function validateRegisterForm(
|
|
59
|
-
values: RegisterFormValues,
|
|
60
|
-
getErrorMessage: (key: string) => string,
|
|
61
|
-
passwordConfig: PasswordConfig
|
|
62
|
-
): FormValidationResult {
|
|
63
|
-
const errors: FormValidationError[] = [];
|
|
64
|
-
|
|
65
|
-
const emailResult = validateEmail(values.email.trim());
|
|
66
|
-
if (!emailResult.isValid && emailResult.error) {
|
|
67
|
-
errors.push({ field: "email", message: getErrorMessage(emailResult.error) });
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const passwordResult = validatePasswordForRegister(values.password, passwordConfig);
|
|
71
|
-
if (!passwordResult.isValid && passwordResult.error) {
|
|
72
|
-
errors.push({ field: "password", message: getErrorMessage(passwordResult.error) });
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const confirmResult = validatePasswordConfirmation(values.password, values.confirmPassword);
|
|
76
|
-
if (!confirmResult.isValid && confirmResult.error) {
|
|
77
|
-
errors.push({ field: "confirmPassword", message: getErrorMessage(confirmResult.error) });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return { isValid: errors.length === 0, errors };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function validateProfileForm(values: ProfileFormValues): FormValidationResult {
|
|
84
|
-
const errors: FormValidationError[] = [];
|
|
85
|
-
|
|
86
|
-
if (!values.displayName.trim()) {
|
|
87
|
-
errors.push({ field: "displayName", message: "Display name is required" });
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (values.email) {
|
|
91
|
-
const emailResult = validateEmail(values.email);
|
|
92
|
-
if (!emailResult.isValid && emailResult.error) {
|
|
93
|
-
errors.push({ field: "email", message: emailResult.error });
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return { isValid: errors.length === 0, errors };
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function errorsToFieldErrors(errors: FormValidationError[]): Record<string, string> {
|
|
101
|
-
const result: Record<string, string> = {};
|
|
102
|
-
for (const error of errors) {
|
|
103
|
-
result[error.field] = error.message;
|
|
104
|
-
}
|
|
105
|
-
return result;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function useFormValidation(getErrorMessage: (key: string) => string) {
|
|
109
|
-
const validateLogin = useCallback((values: LoginFormValues) => validateLoginForm(values, getErrorMessage), [getErrorMessage]);
|
|
110
|
-
const validateRegister = useCallback(
|
|
111
|
-
(values: RegisterFormValues, passwordConfig: PasswordConfig) => validateRegisterForm(values, getErrorMessage, passwordConfig),
|
|
112
|
-
[getErrorMessage]
|
|
113
|
-
);
|
|
114
|
-
const validateProfile = useCallback((values: ProfileFormValues) => validateProfileForm(values), []);
|
|
115
|
-
|
|
116
|
-
return { validateLogin, validateRegister, validateProfile, errorsToFieldErrors };
|
|
117
|
-
}
|
|
6
|
+
// Types
|
|
7
|
+
export type {
|
|
8
|
+
FormValidationError,
|
|
9
|
+
FormValidationResult,
|
|
10
|
+
LoginFormValues,
|
|
11
|
+
RegisterFormValues,
|
|
12
|
+
ProfileFormValues,
|
|
13
|
+
} from "./validation/formValidation.types";
|
|
14
|
+
|
|
15
|
+
// Validators
|
|
16
|
+
export {
|
|
17
|
+
validateLoginForm,
|
|
18
|
+
validateRegisterForm,
|
|
19
|
+
validateProfileForm,
|
|
20
|
+
} from "./validation/formValidators";
|
|
21
|
+
|
|
22
|
+
// Utilities
|
|
23
|
+
export { errorsToFieldErrors } from "./validation/formValidation.utils";
|
|
24
|
+
|
|
25
|
+
// Hook
|
|
26
|
+
export { useFormValidation } from "./validation/formValidation.hook";
|
|
@@ -43,11 +43,11 @@ export function useFormField(
|
|
|
43
43
|
const handleChange = useCallback(
|
|
44
44
|
(text: string) => {
|
|
45
45
|
setValue(text);
|
|
46
|
-
if (error
|
|
46
|
+
if (error) {
|
|
47
47
|
clearError();
|
|
48
48
|
}
|
|
49
49
|
},
|
|
50
|
-
[error,
|
|
50
|
+
[error, clearError]
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
return {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form Validation Hook
|
|
3
|
+
* React hook for form validation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { useCallback } from "react";
|
|
7
|
+
import type { PasswordConfig } from "../../../../domain/value-objects/AuthConfig";
|
|
8
|
+
import type { LoginFormValues, RegisterFormValues, ProfileFormValues } from "./formValidation.types";
|
|
9
|
+
import { validateLoginForm, validateRegisterForm, validateProfileForm } from "./formValidators";
|
|
10
|
+
import { errorsToFieldErrors } from "./formValidation.utils";
|
|
11
|
+
|
|
12
|
+
export function useFormValidation(getErrorMessage: (key: string) => string) {
|
|
13
|
+
const validateLogin = useCallback(
|
|
14
|
+
(values: LoginFormValues) => validateLoginForm(values, getErrorMessage),
|
|
15
|
+
[getErrorMessage]
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const validateRegister = useCallback(
|
|
19
|
+
(values: RegisterFormValues, passwordConfig: PasswordConfig) =>
|
|
20
|
+
validateRegisterForm(values, getErrorMessage, passwordConfig),
|
|
21
|
+
[getErrorMessage]
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const validateProfile = useCallback(
|
|
25
|
+
(values: ProfileFormValues) => validateProfileForm(values, getErrorMessage),
|
|
26
|
+
[getErrorMessage]
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return { validateLogin, validateRegister, validateProfile, errorsToFieldErrors };
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form Validation Types
|
|
3
|
+
* Type definitions for form validation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface FormValidationError {
|
|
7
|
+
field: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface FormValidationResult {
|
|
12
|
+
isValid: boolean;
|
|
13
|
+
errors: FormValidationError[];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface LoginFormValues {
|
|
17
|
+
email: string;
|
|
18
|
+
password: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface RegisterFormValues {
|
|
22
|
+
displayName?: string;
|
|
23
|
+
email: string;
|
|
24
|
+
password: string;
|
|
25
|
+
confirmPassword: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ProfileFormValues {
|
|
29
|
+
displayName: string;
|
|
30
|
+
email: string;
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form Validation Utilities
|
|
3
|
+
* Helper functions for form validation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { FormValidationError } from "./formValidation.types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Convert validation errors array to field errors object
|
|
10
|
+
*/
|
|
11
|
+
export function errorsToFieldErrors(errors: FormValidationError[]): Record<string, string> {
|
|
12
|
+
const result: Record<string, string> = {};
|
|
13
|
+
for (const error of errors) {
|
|
14
|
+
result[error.field] = error.message;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form Validators
|
|
3
|
+
* Validation functions for different auth forms
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
validateEmail,
|
|
8
|
+
validatePasswordForLogin,
|
|
9
|
+
validatePasswordForRegister,
|
|
10
|
+
validatePasswordConfirmation,
|
|
11
|
+
} from "../../../../infrastructure/utils/AuthValidation";
|
|
12
|
+
import type { PasswordConfig } from "../../../../domain/value-objects/AuthConfig";
|
|
13
|
+
import type {
|
|
14
|
+
FormValidationResult,
|
|
15
|
+
LoginFormValues,
|
|
16
|
+
RegisterFormValues,
|
|
17
|
+
ProfileFormValues,
|
|
18
|
+
FormValidationError,
|
|
19
|
+
} from "./formValidation.types";
|
|
20
|
+
|
|
21
|
+
export function validateLoginForm(
|
|
22
|
+
values: LoginFormValues,
|
|
23
|
+
getErrorMessage: (key: string) => string
|
|
24
|
+
): FormValidationResult {
|
|
25
|
+
const errors: FormValidationError[] = [];
|
|
26
|
+
|
|
27
|
+
const emailResult = validateEmail(values.email.trim());
|
|
28
|
+
if (!emailResult.isValid && emailResult.error) {
|
|
29
|
+
errors.push({ field: "email", message: getErrorMessage(emailResult.error) });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const passwordResult = validatePasswordForLogin(values.password);
|
|
33
|
+
if (!passwordResult.isValid && passwordResult.error) {
|
|
34
|
+
errors.push({ field: "password", message: getErrorMessage(passwordResult.error) });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return { isValid: errors.length === 0, errors };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function validateRegisterForm(
|
|
41
|
+
values: RegisterFormValues,
|
|
42
|
+
getErrorMessage: (key: string) => string,
|
|
43
|
+
passwordConfig: PasswordConfig
|
|
44
|
+
): FormValidationResult {
|
|
45
|
+
const errors: FormValidationError[] = [];
|
|
46
|
+
|
|
47
|
+
const emailResult = validateEmail(values.email.trim());
|
|
48
|
+
if (!emailResult.isValid && emailResult.error) {
|
|
49
|
+
errors.push({ field: "email", message: getErrorMessage(emailResult.error) });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const passwordResult = validatePasswordForRegister(values.password, passwordConfig);
|
|
53
|
+
if (!passwordResult.isValid && passwordResult.error) {
|
|
54
|
+
errors.push({ field: "password", message: getErrorMessage(passwordResult.error) });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const confirmResult = validatePasswordConfirmation(values.password, values.confirmPassword);
|
|
58
|
+
if (!confirmResult.isValid && confirmResult.error) {
|
|
59
|
+
errors.push({ field: "confirmPassword", message: getErrorMessage(confirmResult.error) });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { isValid: errors.length === 0, errors };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function validateProfileForm(
|
|
66
|
+
values: ProfileFormValues,
|
|
67
|
+
getErrorMessage: (key: string) => string
|
|
68
|
+
): FormValidationResult {
|
|
69
|
+
const errors: FormValidationError[] = [];
|
|
70
|
+
|
|
71
|
+
if (!values.displayName || !values.displayName.trim()) {
|
|
72
|
+
errors.push({
|
|
73
|
+
field: "displayName",
|
|
74
|
+
message: getErrorMessage("auth.validation.displayNameRequired"),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (values.email) {
|
|
79
|
+
const emailResult = validateEmail(values.email.trim());
|
|
80
|
+
if (!emailResult.isValid && emailResult.error) {
|
|
81
|
+
errors.push({ field: "email", message: getErrorMessage(emailResult.error) });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { isValid: errors.length === 0, errors };
|
|
86
|
+
}
|