@umituz/react-native-auth 1.11.0 → 2.0.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.
Files changed (136) hide show
  1. package/README.md +0 -0
  2. package/lib/__tests__/services/AuthCoreService.test.d.ts +4 -0
  3. package/lib/__tests__/services/AuthCoreService.test.js +198 -0
  4. package/lib/__tests__/services/AuthPackage.test.d.ts +4 -0
  5. package/lib/__tests__/services/AuthPackage.test.js +177 -0
  6. package/lib/__tests__/services/GuestModeService.test.d.ts +4 -0
  7. package/lib/__tests__/services/GuestModeService.test.js +141 -0
  8. package/lib/__tests__/utils/AuthValidation.test.d.ts +4 -0
  9. package/lib/__tests__/utils/AuthValidation.test.js +222 -0
  10. package/lib/application/ports/IAuthProvider.d.ts +42 -0
  11. package/lib/application/ports/IAuthProvider.js +5 -0
  12. package/lib/application/ports/IAuthService.d.ts +48 -0
  13. package/lib/application/ports/IAuthService.js +5 -0
  14. package/lib/domain/entities/AuthUser.d.ts +12 -0
  15. package/lib/domain/entities/AuthUser.js +5 -0
  16. package/lib/domain/errors/AuthError.d.ts +36 -0
  17. package/lib/domain/errors/AuthError.js +76 -0
  18. package/lib/domain/value-objects/AuthConfig.d.ts +16 -0
  19. package/lib/domain/value-objects/AuthConfig.js +14 -0
  20. package/lib/index.d.ts +45 -0
  21. package/lib/index.js +59 -0
  22. package/lib/infrastructure/adapters/StorageProviderAdapter.d.ts +16 -0
  23. package/lib/infrastructure/adapters/StorageProviderAdapter.js +72 -0
  24. package/lib/infrastructure/adapters/UIProviderAdapter.d.ts +18 -0
  25. package/lib/infrastructure/adapters/UIProviderAdapter.js +28 -0
  26. package/lib/infrastructure/providers/FirebaseAuthProvider.d.ts +19 -0
  27. package/lib/infrastructure/providers/FirebaseAuthProvider.js +94 -0
  28. package/lib/infrastructure/services/AuthCoreService.d.ts +22 -0
  29. package/lib/infrastructure/services/AuthCoreService.js +102 -0
  30. package/lib/infrastructure/services/AuthEventService.d.ts +28 -0
  31. package/lib/infrastructure/services/AuthEventService.js +88 -0
  32. package/lib/infrastructure/services/AuthPackage.d.ts +62 -0
  33. package/lib/infrastructure/services/AuthPackage.js +91 -0
  34. package/lib/infrastructure/services/AuthService.d.ts +42 -0
  35. package/lib/infrastructure/services/AuthService.js +123 -0
  36. package/lib/infrastructure/services/GuestModeService.d.ts +23 -0
  37. package/lib/infrastructure/services/GuestModeService.js +69 -0
  38. package/lib/infrastructure/storage/GuestModeStorage.d.ts +16 -0
  39. package/lib/infrastructure/storage/GuestModeStorage.js +73 -0
  40. package/lib/infrastructure/utils/AuthErrorMapper.d.ts +8 -0
  41. package/lib/infrastructure/utils/AuthErrorMapper.js +51 -0
  42. package/lib/infrastructure/utils/AuthEventEmitter.d.ts +12 -0
  43. package/lib/infrastructure/utils/AuthEventEmitter.js +25 -0
  44. package/lib/infrastructure/utils/AuthValidation.d.ts +49 -0
  45. package/lib/infrastructure/utils/AuthValidation.js +133 -0
  46. package/lib/infrastructure/utils/UserMapper.d.ts +15 -0
  47. package/lib/infrastructure/utils/UserMapper.js +16 -0
  48. package/lib/presentation/components/AuthContainer.d.ts +10 -0
  49. package/lib/presentation/components/AuthContainer.js +27 -0
  50. package/lib/presentation/components/AuthDivider.d.ts +6 -0
  51. package/lib/presentation/components/AuthDivider.js +36 -0
  52. package/lib/presentation/components/AuthErrorDisplay.d.ts +10 -0
  53. package/lib/presentation/components/AuthErrorDisplay.js +24 -0
  54. package/lib/presentation/components/AuthFormCard.d.ts +10 -0
  55. package/lib/presentation/components/AuthFormCard.js +19 -0
  56. package/lib/presentation/components/AuthGradientBackground.d.ts +6 -0
  57. package/lib/presentation/components/AuthGradientBackground.js +8 -0
  58. package/lib/presentation/components/AuthHeader.d.ts +11 -0
  59. package/lib/presentation/components/AuthHeader.js +38 -0
  60. package/lib/presentation/components/AuthLegalLinks.d.ts +28 -0
  61. package/lib/presentation/components/AuthLegalLinks.js +54 -0
  62. package/lib/presentation/components/AuthLink.d.ts +13 -0
  63. package/lib/presentation/components/AuthLink.js +27 -0
  64. package/lib/presentation/components/LoginForm.d.ts +10 -0
  65. package/lib/presentation/components/LoginForm.js +27 -0
  66. package/lib/presentation/components/PasswordMatchIndicator.d.ts +9 -0
  67. package/lib/presentation/components/PasswordMatchIndicator.js +30 -0
  68. package/lib/presentation/components/PasswordStrengthIndicator.d.ts +11 -0
  69. package/lib/presentation/components/PasswordStrengthIndicator.js +60 -0
  70. package/lib/presentation/components/RegisterForm.d.ts +14 -0
  71. package/lib/presentation/components/RegisterForm.js +30 -0
  72. package/lib/presentation/hooks/useAuth.d.ts +44 -0
  73. package/lib/presentation/hooks/useAuth.js +38 -0
  74. package/lib/presentation/hooks/useAuthActions.d.ts +15 -0
  75. package/lib/presentation/hooks/useAuthActions.js +162 -0
  76. package/lib/presentation/hooks/useAuthState.d.ts +19 -0
  77. package/lib/presentation/hooks/useAuthState.js +79 -0
  78. package/lib/presentation/hooks/useLoginForm.d.ts +21 -0
  79. package/lib/presentation/hooks/useLoginForm.js +131 -0
  80. package/lib/presentation/hooks/useRegisterForm.d.ts +31 -0
  81. package/lib/presentation/hooks/useRegisterForm.js +136 -0
  82. package/lib/presentation/navigation/AuthNavigator.d.ts +28 -0
  83. package/lib/presentation/navigation/AuthNavigator.js +37 -0
  84. package/lib/presentation/screens/LoginScreen.d.ts +6 -0
  85. package/lib/presentation/screens/LoginScreen.js +15 -0
  86. package/lib/presentation/screens/RegisterScreen.d.ts +12 -0
  87. package/lib/presentation/screens/RegisterScreen.js +15 -0
  88. package/lib/presentation/utils/getAuthErrorMessage.d.ts +8 -0
  89. package/lib/presentation/utils/getAuthErrorMessage.js +69 -0
  90. package/package.json +12 -4
  91. package/src/__tests__/services/AuthCoreService.test.ts +247 -0
  92. package/src/__tests__/services/AuthPackage.test.ts +226 -0
  93. package/src/__tests__/services/GuestModeService.test.ts +194 -0
  94. package/src/__tests__/utils/AuthValidation.test.ts +270 -0
  95. package/src/application/ports/IAuthProvider.ts +0 -0
  96. package/src/application/ports/IAuthService.ts +0 -0
  97. package/src/domain/entities/AuthUser.ts +0 -0
  98. package/src/domain/errors/AuthError.ts +0 -0
  99. package/src/domain/value-objects/AuthConfig.ts +0 -0
  100. package/src/index.ts +4 -0
  101. package/src/infrastructure/adapters/StorageProviderAdapter.ts +73 -0
  102. package/src/infrastructure/adapters/UIProviderAdapter.ts +39 -0
  103. package/src/infrastructure/providers/FirebaseAuthProvider.ts +10 -2
  104. package/src/infrastructure/services/AuthCoreService.ts +138 -0
  105. package/src/infrastructure/services/AuthEventService.ts +115 -0
  106. package/src/infrastructure/services/AuthPackage.ts +148 -0
  107. package/src/infrastructure/services/AuthService.ts +62 -128
  108. package/src/infrastructure/services/GuestModeService.ts +86 -0
  109. package/src/infrastructure/storage/GuestModeStorage.ts +40 -14
  110. package/src/infrastructure/utils/AuthErrorMapper.ts +7 -3
  111. package/src/infrastructure/utils/AuthEventEmitter.ts +0 -0
  112. package/src/infrastructure/utils/AuthValidation.ts +47 -17
  113. package/src/infrastructure/utils/UserMapper.ts +0 -0
  114. package/src/presentation/components/AuthContainer.tsx +0 -0
  115. package/src/presentation/components/AuthDivider.tsx +0 -0
  116. package/src/presentation/components/AuthErrorDisplay.tsx +0 -0
  117. package/src/presentation/components/AuthFormCard.tsx +0 -0
  118. package/src/presentation/components/AuthGradientBackground.tsx +0 -0
  119. package/src/presentation/components/AuthHeader.tsx +0 -0
  120. package/src/presentation/components/AuthLegalLinks.tsx +0 -0
  121. package/src/presentation/components/AuthLink.tsx +0 -0
  122. package/src/presentation/components/LoginForm.tsx +0 -0
  123. package/src/presentation/components/PasswordMatchIndicator.tsx +50 -0
  124. package/src/presentation/components/PasswordStrengthIndicator.tsx +118 -0
  125. package/src/presentation/components/RegisterForm.tsx +10 -0
  126. package/src/presentation/hooks/useAuth.ts +0 -0
  127. package/src/presentation/hooks/useAuthActions.ts +8 -11
  128. package/src/presentation/hooks/useAuthState.ts +10 -0
  129. package/src/presentation/hooks/useLoginForm.ts +0 -0
  130. package/src/presentation/hooks/useRegisterForm.ts +40 -18
  131. package/src/presentation/navigation/AuthNavigator.tsx +2 -2
  132. package/src/presentation/screens/LoginScreen.tsx +3 -6
  133. package/src/presentation/screens/RegisterScreen.tsx +3 -6
  134. package/src/presentation/utils/getAuthErrorMessage.ts +0 -0
  135. package/src/types/external.d.ts +68 -0
  136. package/LICENSE +0 -22
@@ -3,7 +3,7 @@
3
3
  * Single Responsibility: Handle register form logic
4
4
  */
5
5
 
6
- import { useState, useCallback } from "react";
6
+ import { useState, useCallback, useMemo } from "react";
7
7
  import { useLocalization } from "@umituz/react-native-localization";
8
8
  import { batchValidate } from "@umituz/react-native-validation";
9
9
  import {
@@ -14,6 +14,7 @@ import {
14
14
  import { DEFAULT_PASSWORD_CONFIG } from "../../domain/value-objects/AuthConfig";
15
15
  import { useAuth } from "./useAuth";
16
16
  import { getAuthErrorLocalizationKey } from "../utils/getAuthErrorMessage";
17
+ import type { PasswordRequirements } from "../../infrastructure/utils/AuthValidation";
17
18
 
18
19
  export interface UseRegisterFormResult {
19
20
  displayName: string;
@@ -28,6 +29,8 @@ export interface UseRegisterFormResult {
28
29
  };
29
30
  localError: string | null;
30
31
  loading: boolean;
32
+ passwordRequirements: PasswordRequirements;
33
+ passwordsMatch: boolean;
31
34
  handleDisplayNameChange: (text: string) => void;
32
35
  handleEmailChange: (text: string) => void;
33
36
  handlePasswordChange: (text: string) => void;
@@ -55,6 +58,24 @@ export function useRegisterForm(): UseRegisterFormResult {
55
58
  confirmPassword?: string;
56
59
  }>({});
57
60
 
61
+ const passwordRequirements = useMemo((): PasswordRequirements => {
62
+ if (!password) {
63
+ return {
64
+ hasMinLength: false,
65
+ hasUppercase: false,
66
+ hasLowercase: false,
67
+ hasNumber: false,
68
+ hasSpecialChar: false,
69
+ };
70
+ }
71
+ const result = validatePasswordForRegister(password, DEFAULT_PASSWORD_CONFIG);
72
+ return result.requirements;
73
+ }, [password]);
74
+
75
+ const passwordsMatch = useMemo(() => {
76
+ return password.length > 0 && password === confirmPassword;
77
+ }, [password, confirmPassword]);
78
+
58
79
  const handleDisplayNameChange = useCallback((text: string) => {
59
80
  setDisplayName(text);
60
81
  setFieldErrors((prev) => {
@@ -110,23 +131,22 @@ export function useRegisterForm(): UseRegisterFormResult {
110
131
  setLocalError(null);
111
132
  setFieldErrors({});
112
133
 
113
- const validationResult = batchValidate([
114
- {
115
- field: "email",
116
- validator: () => validateEmail(email.trim()),
117
- },
118
- {
119
- field: "password",
120
- validator: () => validatePasswordForRegister(password, DEFAULT_PASSWORD_CONFIG),
121
- },
122
- {
123
- field: "confirmPassword",
124
- validator: () => validatePasswordConfirmation(password, confirmPassword),
125
- },
126
- ]);
127
-
128
- if (!validationResult.isValid) {
129
- setFieldErrors(validationResult.errors);
134
+ // Manual validation since batchValidate is not available
135
+ const emailResult = validateEmail(email.trim());
136
+ if (!emailResult.isValid) {
137
+ setFieldErrors((prev) => ({ ...prev, email: emailResult.error }));
138
+ return;
139
+ }
140
+
141
+ const passwordResult = validatePasswordForRegister(password, DEFAULT_PASSWORD_CONFIG);
142
+ if (!passwordResult.isValid) {
143
+ setFieldErrors((prev) => ({ ...prev, password: passwordResult.error }));
144
+ return;
145
+ }
146
+
147
+ const confirmResult = validatePasswordConfirmation(password, confirmPassword);
148
+ if (!confirmResult.isValid) {
149
+ setFieldErrors((prev) => ({ ...prev, confirmPassword: confirmResult.error }));
130
150
  return;
131
151
  }
132
152
 
@@ -153,6 +173,8 @@ export function useRegisterForm(): UseRegisterFormResult {
153
173
  fieldErrors,
154
174
  localError,
155
175
  loading,
176
+ passwordRequirements,
177
+ passwordsMatch,
156
178
  handleDisplayNameChange,
157
179
  handleEmailChange,
158
180
  handlePasswordChange,
@@ -16,7 +16,7 @@ export type AuthStackParamList = {
16
16
  Register: undefined;
17
17
  };
18
18
 
19
- const AuthStack = createStackNavigator<AuthStackParamList>();
19
+ const AuthStack = createStackNavigator();
20
20
 
21
21
  const SHOW_REGISTER_KEY = "auth_show_register";
22
22
 
@@ -76,7 +76,7 @@ export const AuthNavigator: React.FC<AuthNavigatorProps> = ({
76
76
  >
77
77
  <AuthStack.Screen name="Login" component={LoginScreen} />
78
78
  <AuthStack.Screen name="Register">
79
- {(props) => (
79
+ {(props: any) => (
80
80
  <RegisterScreen
81
81
  {...props}
82
82
  termsUrl={termsUrl}
@@ -13,17 +13,14 @@ import { AuthHeader } from "../components/AuthHeader";
13
13
  import { AuthFormCard } from "../components/AuthFormCard";
14
14
  import { LoginForm } from "../components/LoginForm";
15
15
 
16
- type LoginScreenNavigationProp = StackNavigationProp<
17
- AuthStackParamList,
18
- "Login"
19
- >;
16
+ type LoginScreenNavigationProp = any;
20
17
 
21
18
  export const LoginScreen: React.FC = () => {
22
19
  const { t } = useLocalization();
23
- const navigation = useNavigation<LoginScreenNavigationProp>();
20
+ const navigation = useNavigation();
24
21
 
25
22
  const handleNavigateToRegister = () => {
26
- navigation.navigate("Register");
23
+ navigation.navigate("Register" as any);
27
24
  };
28
25
 
29
26
  return (
@@ -13,10 +13,7 @@ import { AuthHeader } from "../components/AuthHeader";
13
13
  import { AuthFormCard } from "../components/AuthFormCard";
14
14
  import { RegisterForm } from "../components/RegisterForm";
15
15
 
16
- type RegisterScreenNavigationProp = StackNavigationProp<
17
- AuthStackParamList,
18
- "Register"
19
- >;
16
+ type RegisterScreenNavigationProp = any;
20
17
 
21
18
  export interface RegisterScreenProps {
22
19
  termsUrl?: string;
@@ -32,10 +29,10 @@ export const RegisterScreen: React.FC<RegisterScreenProps> = ({
32
29
  onPrivacyPress,
33
30
  }) => {
34
31
  const { t } = useLocalization();
35
- const navigation = useNavigation<RegisterScreenNavigationProp>();
32
+ const navigation = useNavigation();
36
33
 
37
34
  const handleNavigateToLogin = () => {
38
- navigation.navigate("Login");
35
+ navigation.navigate("Login" as any);
39
36
  };
40
37
 
41
38
  return (
File without changes
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Type declarations for external dependencies
3
+ * These are optional dependencies that should be provided by the consuming application
4
+ */
5
+
6
+ declare module '@umituz/react-native-design-system-theme' {
7
+ export function useAppDesignTokens(): any;
8
+ export const defaultTheme: any;
9
+ }
10
+
11
+ declare module '@umituz/react-native-design-system-atoms' {
12
+ export const AtomicInput: any;
13
+ export const AtomicButton: any;
14
+ export const AtomicText: any;
15
+ export const AtomicView: any;
16
+ }
17
+
18
+ declare module '@umituz/react-native-localization' {
19
+ export function useTranslation(): {
20
+ t: (key: string, params?: Record<string, any>) => string;
21
+ };
22
+ export function useLocalization(): {
23
+ t: (key: string, params?: Record<string, any>) => string;
24
+ };
25
+ }
26
+
27
+ declare module '@umituz/react-native-firebase-auth' {
28
+ export function useFirebaseAuth(): any;
29
+ }
30
+
31
+ declare module '@umituz/react-native-validation' {
32
+ export function useValidation(): any;
33
+ export function batchValidate(): any;
34
+ }
35
+
36
+ declare module '@umituz/react-native-storage' {
37
+ export const storageRepository: {
38
+ getString: (key: string, defaultValue?: string) => Promise<{ value: string } | null>;
39
+ setString: (key: string, value: string) => Promise<void>;
40
+ removeItem: (key: string) => Promise<void>;
41
+ };
42
+ export function unwrap(result: any, defaultValue: any): any;
43
+ }
44
+
45
+ declare module 'react-native-safe-area-context' {
46
+ export function useSafeAreaInsets(): {
47
+ top: number;
48
+ bottom: number;
49
+ left: number;
50
+ right: number;
51
+ };
52
+ }
53
+
54
+ declare module 'expo-linear-gradient' {
55
+ import { ComponentType } from 'react';
56
+ export const LinearGradient: ComponentType<any>;
57
+ }
58
+
59
+ declare module '@react-navigation/stack' {
60
+ import { ComponentType } from 'react';
61
+ export const createStackNavigator: any;
62
+ export type StackNavigationProp<any> = any;
63
+ }
64
+
65
+ declare module '@react-navigation/native' {
66
+ export function useNavigation(): any;
67
+ export function useFocusEffect(effect: () => void | (() => void)): void;
68
+ }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Ümit UZ
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-