@umituz/react-native-firebase 2.6.0 → 2.6.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 (39) hide show
  1. package/package.json +1 -1
  2. package/src/application/auth/index.ts +42 -0
  3. package/src/application/auth/ports/AuthPort.ts +164 -0
  4. package/src/application/auth/use-cases/SignInUseCase.ts +253 -0
  5. package/src/application/auth/use-cases/SignOutUseCase.ts +288 -0
  6. package/src/application/auth/use-cases/index.ts +26 -0
  7. package/src/domains/account-deletion/domain/index.ts +15 -0
  8. package/src/domains/account-deletion/domain/services/UserValidationService.ts +295 -0
  9. package/src/domains/account-deletion/index.ts +43 -6
  10. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +230 -0
  11. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler.ts +174 -0
  12. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository.ts +266 -0
  13. package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +33 -0
  14. package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +39 -227
  15. package/src/domains/auth/domain.ts +16 -0
  16. package/src/domains/auth/index.ts +7 -148
  17. package/src/domains/auth/infrastructure.ts +156 -0
  18. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService.ts +247 -0
  19. package/src/domains/auth/presentation/hooks/useGoogleOAuth.ts +49 -103
  20. package/src/domains/auth/presentation.ts +25 -0
  21. package/src/domains/firestore/domain/entities/Collection.ts +288 -0
  22. package/src/domains/firestore/domain/entities/Document.ts +233 -0
  23. package/src/domains/firestore/domain/index.ts +30 -0
  24. package/src/domains/firestore/domain/services/QueryService.ts +182 -0
  25. package/src/domains/firestore/domain/services/QueryServiceAnalysis.ts +169 -0
  26. package/src/domains/firestore/domain/services/QueryServiceHelpers.ts +151 -0
  27. package/src/domains/firestore/domain/value-objects/QueryOptions.ts +191 -0
  28. package/src/domains/firestore/domain/value-objects/QueryOptions.ts.bak +320 -0
  29. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization.ts +207 -0
  30. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation.ts +182 -0
  31. package/src/domains/firestore/domain/value-objects/WhereClause.ts +299 -0
  32. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts +207 -0
  33. package/src/domains/firestore/index.ts +9 -6
  34. package/src/index.ts +25 -0
  35. package/src/shared/domain/utils/error-handlers/error-messages.ts +11 -0
  36. package/src/shared/infrastructure/base/ErrorHandler.ts +189 -0
  37. package/src/shared/infrastructure/base/ServiceBase.ts +220 -0
  38. package/src/shared/infrastructure/base/TypedGuard.ts +131 -0
  39. package/src/shared/infrastructure/base/index.ts +34 -0
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Google OAuth Hook Service
3
+ * Single Responsibility: Handle Google OAuth business logic
4
+ *
5
+ * Service class that manages Google OAuth flow.
6
+ * Separates business logic from React hook concerns.
7
+ *
8
+ * Max lines: 150 (enforced for maintainability)
9
+ */
10
+
11
+ import type { Auth } from 'firebase/auth';
12
+ import { googleOAuthService } from '../../infrastructure/services/google-oauth.service';
13
+ import type { GoogleOAuthConfig } from '../../infrastructure/services/google-oauth.service';
14
+
15
+ // Conditional import for expo-auth-session
16
+ interface AuthSessionResponse {
17
+ type: string;
18
+ authentication?: { idToken?: string } | null;
19
+ }
20
+
21
+ interface ExpoAuthSessionModule {
22
+ useAuthRequest: (config: {
23
+ iosClientId: string;
24
+ webClientId: string;
25
+ androidClientId: string;
26
+ }) => [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
27
+ }
28
+
29
+ let ExpoAuthSession: ExpoAuthSessionModule | null = null;
30
+ let isExpoAuthAvailable = false;
31
+
32
+ try {
33
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
34
+ ExpoAuthSession = require('expo-auth-session/providers/google') as ExpoAuthSessionModule;
35
+ isExpoAuthAvailable = true;
36
+ } catch {
37
+ // expo-auth-session not available
38
+ }
39
+
40
+ /**
41
+ * Google OAuth hook service
42
+ * Manages OAuth flow, response handling, and errors
43
+ */
44
+ export class GoogleOAuthHookService {
45
+ private config: GoogleOAuthConfig | undefined;
46
+ private authRequest: [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
47
+
48
+ constructor(config?: GoogleOAuthConfig) {
49
+ this.config = config;
50
+ this.authRequest = this.initAuthRequest();
51
+ }
52
+
53
+ /**
54
+ * Initialize auth request
55
+ * Uses expo-auth-session if available
56
+ */
57
+ private initAuthRequest(): [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null] {
58
+ if (!isExpoAuthAvailable || !ExpoAuthSession) {
59
+ return [null, null, null];
60
+ }
61
+
62
+ return ExpoAuthSession.useAuthRequest({
63
+ iosClientId: this.config?.iosClientId ?? '',
64
+ webClientId: this.config?.webClientId ?? '',
65
+ androidClientId: this.config?.androidClientId ?? '',
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Check if Google OAuth is available
71
+ */
72
+ isAvailable(): boolean {
73
+ return isExpoAuthAvailable;
74
+ }
75
+
76
+ /**
77
+ * Check if Google OAuth is configured
78
+ */
79
+ isConfigured(): boolean {
80
+ return googleOAuthService.isConfigured(this.config);
81
+ }
82
+
83
+ /**
84
+ * Update configuration
85
+ */
86
+ updateConfig(config: GoogleOAuthConfig | undefined): void {
87
+ this.config = config;
88
+ }
89
+
90
+ /**
91
+ * Get auth request tuple
92
+ */
93
+ getAuthRequest(): [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null] {
94
+ return this.authRequest;
95
+ }
96
+
97
+ /**
98
+ * Handle OAuth response
99
+ * Called when expo-auth-session returns a response
100
+ */
101
+ async handleResponse(response: AuthSessionResponse | null, auth: Auth | null): Promise<void> {
102
+ if (!response) return;
103
+
104
+ if (response.type === 'success' && response.authentication?.idToken) {
105
+ if (!auth) {
106
+ throw new Error('Firebase Auth not initialized');
107
+ }
108
+
109
+ await googleOAuthService.signInWithOAuth(
110
+ auth,
111
+ this.config,
112
+ async () => response
113
+ );
114
+ } else if (response.type === 'error') {
115
+ throw new Error('Google authentication failed');
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Sign in with Google
121
+ * Initiates OAuth flow and returns result
122
+ */
123
+ async signIn(auth: Auth | null): Promise<{ success: boolean; isNewUser?: boolean; error?: string }> {
124
+ if (!this.isAvailable()) {
125
+ const error = 'expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.';
126
+ throw new Error(error);
127
+ }
128
+
129
+ if (!this.isConfigured()) {
130
+ const error = 'Google Sign-In is not configured. Please provide valid client IDs.';
131
+ throw new Error(error);
132
+ }
133
+
134
+ const [, , promptAsync] = this.authRequest;
135
+
136
+ if (!promptAsync) {
137
+ throw new Error('Google Sign-In not ready');
138
+ }
139
+
140
+ if (!auth) {
141
+ throw new Error('Firebase Auth not initialized');
142
+ }
143
+
144
+ return await googleOAuthService.signInWithOAuth(auth, this.config, promptAsync);
145
+ }
146
+
147
+ /**
148
+ * Validate OAuth state
149
+ */
150
+ validate(): { valid: boolean; error?: string } {
151
+ if (!this.isAvailable()) {
152
+ return {
153
+ valid: false,
154
+ error: 'expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.',
155
+ };
156
+ }
157
+
158
+ if (!this.isConfigured()) {
159
+ return {
160
+ valid: false,
161
+ error: 'Google Sign-In is not configured. Please provide valid client IDs.',
162
+ };
163
+ }
164
+
165
+ return { valid: true };
166
+ }
167
+
168
+ /**
169
+ * Get error message from error
170
+ */
171
+ getErrorMessage(error: unknown): string {
172
+ if (error instanceof Error) {
173
+ return error.message;
174
+ }
175
+ return 'Google sign-in failed';
176
+ }
177
+
178
+ /**
179
+ * Check if response is successful
180
+ */
181
+ isSuccessfulResponse(response: AuthSessionResponse | null): boolean {
182
+ return response?.type === 'success' && !!response.authentication?.idToken;
183
+ }
184
+
185
+ /**
186
+ * Check if response is error
187
+ */
188
+ isErrorResponse(response: AuthSessionResponse | null): boolean {
189
+ return response?.type === 'error';
190
+ }
191
+
192
+ /**
193
+ * Extract ID token from response
194
+ */
195
+ extractIdToken(response: AuthSessionResponse | null): string | null {
196
+ return response?.authentication?.idToken || null;
197
+ }
198
+
199
+ /**
200
+ * Create error result
201
+ */
202
+ createErrorResult(error: string): { success: false; error: string } {
203
+ return { success: false, error };
204
+ }
205
+
206
+ /**
207
+ * Check if auth request is ready
208
+ */
209
+ isReady(): boolean {
210
+ const [request, , promptAsync] = this.authRequest;
211
+ return request !== null && promptAsync !== null;
212
+ }
213
+
214
+ /**
215
+ * Get configuration
216
+ */
217
+ getConfig(): GoogleOAuthConfig | undefined {
218
+ return this.config;
219
+ }
220
+
221
+ /**
222
+ * Reset service state
223
+ */
224
+ reset(): void {
225
+ this.config = undefined;
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Factory function to create Google OAuth hook service
231
+ */
232
+ export function createGoogleOAuthHookService(config?: GoogleOAuthConfig): GoogleOAuthHookService {
233
+ return new GoogleOAuthHookService(config);
234
+ }
235
+
236
+ /**
237
+ * Check if expo-auth-session is available
238
+ * Useful for conditional rendering
239
+ */
240
+ export function isExpoAuthSessionAvailable(): boolean {
241
+ return isExpoAuthAvailable;
242
+ }
243
+
244
+ /**
245
+ * Re-export types for convenience
246
+ */
247
+ export type { AuthSessionResponse, ExpoAuthSessionModule };
@@ -1,37 +1,21 @@
1
1
  /**
2
2
  * useGoogleOAuth Hook
3
3
  * Handles Google OAuth flow using expo-auth-session and Firebase auth
4
- * This hook is optional and requires expo-auth-session to be installed
4
+ *
5
+ * This hook delegates business logic to GoogleOAuthHookService.
6
+ * Focuses only on React state management and side effects.
7
+ *
8
+ * Max lines: 150 (enforced for maintainability)
5
9
  */
6
10
 
7
- import { useState, useCallback, useEffect, useRef, useMemo } from "react";
8
- import { googleOAuthService } from "../../infrastructure/services/google-oauth.service";
9
- import { getFirebaseAuth } from "../../infrastructure/config/FirebaseAuthClient";
10
- import type { GoogleOAuthConfig } from "../../infrastructure/services/google-oauth.service";
11
- // Conditional import for expo-auth-session
12
- interface AuthSessionResponse {
13
- type: string;
14
- authentication?: { idToken?: string } | null;
15
- }
16
-
17
- interface ExpoAuthSessionModule {
18
- useAuthRequest: (config: {
19
- iosClientId: string;
20
- webClientId: string;
21
- androidClientId: string;
22
- }) => [unknown, AuthSessionResponse | null, (() => Promise<AuthSessionResponse>) | null];
23
- }
24
-
25
- let ExpoAuthSession: ExpoAuthSessionModule | null = null;
26
- let isExpoAuthAvailable = false;
27
-
28
- try {
29
- // eslint-disable-next-line @typescript-eslint/no-require-imports
30
- ExpoAuthSession = require("expo-auth-session/providers/google") as ExpoAuthSessionModule;
31
- isExpoAuthAvailable = true;
32
- } catch {
33
- // expo-auth-session not available - hook will return unavailable state
34
- }
11
+ import { useState, useCallback, useEffect, useMemo } from 'react';
12
+ import { getFirebaseAuth } from '../../infrastructure/config/FirebaseAuthClient';
13
+ import type { GoogleOAuthConfig } from '../../infrastructure/services/google-oauth.service';
14
+ import {
15
+ GoogleOAuthHookService,
16
+ createGoogleOAuthHookService,
17
+ isExpoAuthSessionAvailable,
18
+ } from './GoogleOAuthHookService';
35
19
 
36
20
  export interface UseGoogleOAuthResult {
37
21
  signInWithGoogle: () => Promise<SocialAuthResult>;
@@ -55,107 +39,62 @@ export function useGoogleOAuth(config?: GoogleOAuthConfig): UseGoogleOAuthResult
55
39
  const [isLoading, setIsLoading] = useState(false);
56
40
  const [googleError, setGoogleError] = useState<string | null>(null);
57
41
 
58
- // Memoize service checks to avoid repeated calls on every render
59
- const googleAvailable = useMemo(() => googleOAuthService.isAvailable(), []);
60
- const googleConfigured = useMemo(() => googleOAuthService.isConfigured(config), [config]);
61
-
62
- // Keep config in a ref so the response useEffect doesn't re-run when config object reference changes
63
- const configRef = useRef(config);
64
- configRef.current = config;
65
-
66
- // Call the Hook directly (only valid in React component)
67
- // If expo-auth-session is not available, these will be null
68
- // Empty strings are passed when config is missing to preserve hook call order (Rules of Hooks)
69
- const [request, response, promptAsync] = isExpoAuthAvailable && ExpoAuthSession
70
- ? ExpoAuthSession.useAuthRequest({
71
- iosClientId: config?.iosClientId ?? "",
72
- webClientId: config?.webClientId ?? "",
73
- androidClientId: config?.androidClientId ?? "",
74
- })
75
- : [null, null, null];
42
+ // Initialize service with config
43
+ const service = useMemo(() => createGoogleOAuthHookService(config), [config]);
44
+
45
+ // Update service when config changes
46
+ useEffect(() => {
47
+ service.updateConfig(config);
48
+ }, [service, config]);
49
+
50
+ // Memoize service checks
51
+ const googleAvailable = useMemo(() => service.isAvailable(), [service]);
52
+ const googleConfigured = useMemo(() => service.isConfigured(), [service]);
53
+
54
+ // Get auth request tuple from service
55
+ const [, response] = service.getAuthRequest();
76
56
 
77
57
  // Handle OAuth response
78
58
  useEffect(() => {
79
59
  if (!googleAvailable || !response) return;
80
60
 
81
61
  const handleResponse = async () => {
82
- if (response.type === "success" && response.authentication?.idToken) {
83
- setIsLoading(true);
84
- setGoogleError(null);
85
-
86
- try {
87
- const auth = getFirebaseAuth();
88
- if (!auth) {
89
- setGoogleError("Firebase Auth not initialized");
90
- setIsLoading(false);
91
- return;
92
- }
93
-
94
- await googleOAuthService.signInWithOAuth(
95
- auth,
96
- configRef.current,
97
- async () => response
98
- );
99
- } catch (error) {
100
- setGoogleError(
101
- error instanceof Error ? error.message : "Firebase sign-in failed"
102
- );
103
- } finally {
104
- setIsLoading(false);
105
- }
106
- } else if (response.type === "error") {
107
- setGoogleError("Google authentication failed");
62
+ setIsLoading(true);
63
+ setGoogleError(null);
64
+
65
+ try {
66
+ const auth = getFirebaseAuth();
67
+ await service.handleResponse(response, auth);
68
+ } catch (error) {
69
+ setGoogleError(service.getErrorMessage(error));
70
+ } finally {
71
+ setIsLoading(false);
108
72
  }
109
73
  };
110
74
 
111
- // Call async function and catch errors separately
112
75
  handleResponse().catch((err) => {
113
- // Errors are already handled in handleResponse
114
76
  if (__DEV__) {
115
77
  console.error('[useGoogleOAuth] Unexpected error in handleResponse:', err);
116
78
  }
117
79
  });
118
- }, [response, googleAvailable]); // config read via ref to prevent re-running on reference changes
80
+ }, [response, googleAvailable, service]);
119
81
 
82
+ // Sign in with Google
120
83
  const signInWithGoogle = useCallback(async (): Promise<SocialAuthResult> => {
121
- if (!googleAvailable) {
122
- const error = "expo-auth-session is not available. Please install expo-auth-session and expo-web-browser.";
123
- setGoogleError(error);
124
- return { success: false, error };
125
- }
126
-
127
- if (!googleConfigured) {
128
- const error = "Google Sign-In is not configured. Please provide valid client IDs.";
129
- setGoogleError(error);
130
- return { success: false, error };
131
- }
132
-
133
- if (!request || !promptAsync) {
134
- const error = "Google Sign-In not ready";
135
- setGoogleError(error);
136
- return { success: false, error };
137
- }
138
-
139
84
  setIsLoading(true);
140
85
  setGoogleError(null);
141
86
 
142
87
  try {
143
88
  const auth = getFirebaseAuth();
144
- if (!auth) {
145
- const error = "Firebase Auth not initialized";
146
- setGoogleError(error);
147
- return { success: false, error };
148
- }
149
-
150
- return await googleOAuthService.signInWithOAuth(auth, config, promptAsync);
89
+ return await service.signIn(auth);
151
90
  } catch (error) {
152
- const errorMessage = error instanceof Error ? error.message : "Google sign-in failed";
91
+ const errorMessage = service.getErrorMessage(error);
153
92
  setGoogleError(errorMessage);
154
93
  return { success: false, error: errorMessage };
155
94
  } finally {
156
95
  setIsLoading(false);
157
96
  }
158
- }, [googleAvailable, googleConfigured, request, promptAsync]); // config read via ref to prevent re-creation on reference changes
97
+ }, [service]);
159
98
 
160
99
  return {
161
100
  signInWithGoogle,
@@ -165,3 +104,10 @@ export function useGoogleOAuth(config?: GoogleOAuthConfig): UseGoogleOAuthResult
165
104
  googleError,
166
105
  };
167
106
  }
107
+
108
+ /**
109
+ * Check if expo-auth-session is available
110
+ * Useful for conditional rendering
111
+ */
112
+ export { isExpoAuthSessionAvailable };
113
+
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Firebase Auth Presentation Layer
3
+ * Domain-Driven Design (DDD) - Presentation Exports
4
+ *
5
+ * React hooks for Firebase authentication.
6
+ * Provides clean interface for UI components.
7
+ */
8
+
9
+ export { useFirebaseAuth } from './presentation/hooks/useFirebaseAuth';
10
+ export type { UseFirebaseAuthResult } from './presentation/hooks/useFirebaseAuth';
11
+
12
+ export { useAnonymousAuth } from './presentation/hooks/useAnonymousAuth';
13
+ export type { UseAnonymousAuthResult } from './presentation/hooks/useAnonymousAuth';
14
+
15
+ export { useSocialAuth } from './presentation/hooks/useSocialAuth';
16
+ export type {
17
+ SocialAuthConfig,
18
+ SocialAuthResult,
19
+ UseSocialAuthResult,
20
+ } from './presentation/hooks/useSocialAuth';
21
+
22
+ export { useGoogleOAuth } from './presentation/hooks/useGoogleOAuth';
23
+ export type {
24
+ UseGoogleOAuthResult,
25
+ } from './presentation/hooks/useGoogleOAuth';