@umituz/react-native-firebase 2.6.3 → 2.6.4

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 (96) hide show
  1. package/package.json +1 -1
  2. package/src/application/auth/index.ts +2 -34
  3. package/src/application/auth/use-cases/index.ts +1 -21
  4. package/src/domains/account-deletion/domain/index.ts +1 -8
  5. package/src/domains/account-deletion/index.ts +0 -42
  6. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts +79 -0
  7. package/src/domains/account-deletion/infrastructure/services/AccountDeletionTypes.ts +0 -1
  8. package/src/domains/account-deletion/infrastructure/services/account-deletion.service.ts +2 -14
  9. package/src/domains/auth/index.ts +3 -12
  10. package/src/domains/auth/infrastructure.ts +11 -0
  11. package/src/domains/firestore/domain/entities/Collection.ts +0 -2
  12. package/src/domains/firestore/domain/index.ts +6 -2
  13. package/src/domains/firestore/domain/value-objects/WhereClause.ts +0 -14
  14. package/src/domains/firestore/presentation/hooks/useFirestoreMutation.ts +1 -1
  15. package/src/domains/firestore/presentation/hooks/useFirestoreQuery.ts +1 -1
  16. package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts +29 -0
  17. package/src/application/auth/ports/AuthPort.ts.bak +0 -164
  18. package/src/application/auth/ports/AuthPort_part_aa +0 -150
  19. package/src/application/auth/ports/AuthPort_part_ab +0 -14
  20. package/src/application/auth/use-cases/SignInUseCase.ts.bak +0 -253
  21. package/src/application/auth/use-cases/SignInUseCaseHelpers.ts +0 -0
  22. package/src/application/auth/use-cases/SignInUseCaseMain.ts +0 -0
  23. package/src/application/auth/use-cases/SignInUseCase_part_aa +0 -150
  24. package/src/application/auth/use-cases/SignInUseCase_part_ab +0 -103
  25. package/src/application/auth/use-cases/SignOutUseCase.ts.bak +0 -288
  26. package/src/application/auth/use-cases/SignOutUseCaseCleanup.ts +0 -0
  27. package/src/application/auth/use-cases/SignOutUseCaseMain.ts +0 -0
  28. package/src/application/auth/use-cases/SignOutUseCase_part_aa +0 -150
  29. package/src/application/auth/use-cases/SignOutUseCase_part_ab +0 -138
  30. package/src/domains/account-deletion/domain/services/UserValidationHelpers.ts.bak +0 -181
  31. package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_aa +0 -150
  32. package/src/domains/account-deletion/domain/services/UserValidationHelpers_part_ab +0 -31
  33. package/src/domains/account-deletion/domain/services/UserValidationService.ts.bak +0 -286
  34. package/src/domains/account-deletion/domain/services/UserValidationService_part_aa +0 -150
  35. package/src/domains/account-deletion/domain/services/UserValidationService_part_ab +0 -136
  36. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor.ts.bak +0 -230
  37. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_aa +0 -150
  38. package/src/domains/account-deletion/infrastructure/services/AccountDeletionExecutor_part_ab +0 -80
  39. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler.ts.bak +0 -174
  40. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_aa +0 -150
  41. package/src/domains/account-deletion/infrastructure/services/AccountDeletionReauthHandler_part_ab +0 -24
  42. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository.ts.bak +0 -266
  43. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_aa +0 -150
  44. package/src/domains/account-deletion/infrastructure/services/AccountDeletionRepository_part_ab +0 -116
  45. package/src/domains/account-deletion/infrastructure/services/reauthentication.service.ts.bak +0 -160
  46. package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_aa +0 -150
  47. package/src/domains/account-deletion/infrastructure/services/reauthentication.service_part_ab +0 -10
  48. package/src/domains/auth/infrastructure.ts.bak +0 -156
  49. package/src/domains/auth/infrastructure_part_aa +0 -150
  50. package/src/domains/auth/infrastructure_part_ab +0 -6
  51. package/src/domains/auth/presentation/hooks/GoogleOAuthHelpers.ts +0 -0
  52. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService.ts.bak +0 -247
  53. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_aa +0 -150
  54. package/src/domains/auth/presentation/hooks/GoogleOAuthHookService_part_ab +0 -97
  55. package/src/domains/auth/presentation/hooks/GoogleOAuthService.ts +0 -0
  56. package/src/domains/firestore/domain/entities/Collection.ts.bak +0 -288
  57. package/src/domains/firestore/domain/entities/Collection_part_aa +0 -150
  58. package/src/domains/firestore/domain/entities/Collection_part_ab +0 -138
  59. package/src/domains/firestore/domain/entities/Document.ts.bak +0 -233
  60. package/src/domains/firestore/domain/entities/DocumentHelpers.ts +0 -0
  61. package/src/domains/firestore/domain/entities/DocumentMain.ts +0 -0
  62. package/src/domains/firestore/domain/entities/Document_part_aa +0 -150
  63. package/src/domains/firestore/domain/entities/Document_part_ab +0 -83
  64. package/src/domains/firestore/domain/services/QueryService.ts.bak +0 -182
  65. package/src/domains/firestore/domain/services/QueryServiceAnalysis.ts.bak +0 -169
  66. package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_aa +0 -150
  67. package/src/domains/firestore/domain/services/QueryServiceAnalysis_part_ab +0 -19
  68. package/src/domains/firestore/domain/services/QueryServiceHelpers.ts.bak +0 -151
  69. package/src/domains/firestore/domain/services/QueryServiceHelpers_part_aa +0 -150
  70. package/src/domains/firestore/domain/services/QueryServiceHelpers_part_ab +0 -1
  71. package/src/domains/firestore/domain/services/QueryService_part_aa +0 -150
  72. package/src/domains/firestore/domain/services/QueryService_part_ab +0 -32
  73. package/src/domains/firestore/domain/value-objects/QueryOptions.ts.bak +0 -191
  74. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization.ts.bak +0 -207
  75. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_aa +0 -150
  76. package/src/domains/firestore/domain/value-objects/QueryOptionsSerialization_part_ab +0 -57
  77. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation.ts.bak +0 -182
  78. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_aa +0 -150
  79. package/src/domains/firestore/domain/value-objects/QueryOptionsValidation_part_ab +0 -32
  80. package/src/domains/firestore/domain/value-objects/QueryOptions_part_aa +0 -150
  81. package/src/domains/firestore/domain/value-objects/QueryOptions_part_ab +0 -41
  82. package/src/domains/firestore/domain/value-objects/WhereClause.ts.bak +0 -299
  83. package/src/domains/firestore/domain/value-objects/WhereClauseFactory.ts.bak +0 -207
  84. package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_aa +0 -150
  85. package/src/domains/firestore/domain/value-objects/WhereClauseFactory_part_ab +0 -57
  86. package/src/domains/firestore/domain/value-objects/WhereClause_part_aa +0 -150
  87. package/src/domains/firestore/domain/value-objects/WhereClause_part_ab +0 -149
  88. package/src/shared/infrastructure/base/ErrorHandler.ts.bak +0 -189
  89. package/src/shared/infrastructure/base/ErrorHandler_part_aa +0 -150
  90. package/src/shared/infrastructure/base/ErrorHandler_part_ab +0 -39
  91. package/src/shared/infrastructure/base/ServiceBase.ts.bak +0 -220
  92. package/src/shared/infrastructure/base/ServiceBase_part_aa +0 -150
  93. package/src/shared/infrastructure/base/ServiceBase_part_ab +0 -70
  94. package/src/shared/infrastructure/config/base/ServiceClientSingleton.ts.bak +0 -155
  95. package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_aa +0 -150
  96. package/src/shared/infrastructure/config/base/ServiceClientSingleton_part_ab +0 -5
@@ -1,156 +0,0 @@
1
- /**
2
- * Firebase Auth Infrastructure Layer
3
- * Domain-Driven Design (DDD) - Infrastructure Exports
4
- *
5
- * Infrastructure implementation including:
6
- * - Firebase Auth client configuration
7
- * - Auth utilities and services
8
- * - Social auth providers
9
- * - Email/password authentication
10
- * - User document management
11
- */
12
-
13
- // =============================================================================
14
- // Firebase Auth Client
15
- // =============================================================================
16
-
17
- export {
18
- getFirebaseAuth,
19
- isFirebaseAuthInitialized,
20
- getFirebaseAuthInitializationError,
21
- resetFirebaseAuthClient,
22
- firebaseAuthClient,
23
- initializeFirebaseAuth,
24
- } from './infrastructure/config/FirebaseAuthClient';
25
-
26
- export type {
27
- Auth,
28
- } from './infrastructure/config/FirebaseAuthClient';
29
-
30
- // =============================================================================
31
- // Auth Utilities
32
- // =============================================================================
33
-
34
- export {
35
- checkAuthState,
36
- isAuthenticated,
37
- isAnonymous,
38
- getCurrentUserId,
39
- getCurrentUser,
40
- getCurrentUserIdFromGlobal,
41
- getCurrentUserFromGlobal,
42
- isCurrentUserAuthenticated,
43
- isCurrentUserAnonymous,
44
- verifyUserId,
45
- isValidUser,
46
- } from './infrastructure/services/auth-utils.service';
47
-
48
- export type {
49
- AuthCheckResult,
50
- } from './infrastructure/services/auth-utils.service';
51
-
52
- // =============================================================================
53
- // Anonymous Auth Service
54
- // =============================================================================
55
-
56
- export {
57
- AnonymousAuthService,
58
- anonymousAuthService,
59
- } from './infrastructure/services/anonymous-auth.service';
60
-
61
- export type {
62
- AnonymousAuthResult,
63
- AnonymousAuthServiceInterface,
64
- } from './infrastructure/services/anonymous-auth.service';
65
-
66
- // =============================================================================
67
- // Firestore Utilities
68
- // =============================================================================
69
-
70
- export {
71
- shouldSkipFirestoreQuery,
72
- createFirestoreQueryOptions,
73
- } from './infrastructure/services/firestore-utils.service';
74
-
75
- export type {
76
- FirestoreQueryOptions,
77
- FirestoreQueryResult,
78
- FirestoreQuerySkipReason,
79
- } from './infrastructure/services/firestore-utils.service';
80
-
81
- // =============================================================================
82
- // Social Auth Services
83
- // =============================================================================
84
-
85
- export {
86
- GoogleAuthService,
87
- googleAuthService,
88
- } from './infrastructure/services/google-auth.service';
89
- export type {
90
- GoogleAuthConfig,
91
- GoogleAuthResult,
92
- } from './infrastructure/services/google-auth.types';
93
-
94
- export {
95
- GoogleOAuthService,
96
- googleOAuthService,
97
- } from './infrastructure/services/google-oauth.service';
98
- export type {
99
- GoogleOAuthConfig,
100
- } from './infrastructure/services/google-oauth.service';
101
-
102
- export {
103
- AppleAuthService,
104
- appleAuthService,
105
- } from './infrastructure/services/apple-auth.service';
106
- export type { AppleAuthResult } from './infrastructure/services/apple-auth.types';
107
-
108
- // =============================================================================
109
- // Email/Password Authentication
110
- // =============================================================================
111
-
112
- export {
113
- signInWithEmail,
114
- signUpWithEmail,
115
- signOut,
116
- linkAnonymousWithEmail,
117
- } from './infrastructure/services/email-auth.service';
118
- export type {
119
- EmailCredentials,
120
- EmailAuthResult,
121
- } from './infrastructure/services/email-auth.service';
122
-
123
- // =============================================================================
124
- // Password Management
125
- // =============================================================================
126
-
127
- export {
128
- updateUserPassword,
129
- } from './infrastructure/services/password.service';
130
-
131
- // =============================================================================
132
- // Auth Listener
133
- // =============================================================================
134
-
135
- export {
136
- setupAuthListener,
137
- } from './infrastructure/services/auth-listener.service';
138
- export type {
139
- AuthListenerConfig,
140
- AuthListenerResult,
141
- } from './infrastructure/services/auth-listener.service';
142
-
143
- // =============================================================================
144
- // User Document Service
145
- // =============================================================================
146
-
147
- export {
148
- ensureUserDocument,
149
- markUserDeleted,
150
- configureUserDocumentService,
151
- } from './infrastructure/services/user-document.service';
152
- export type {
153
- UserDocumentUser,
154
- UserDocumentConfig,
155
- UserDocumentExtras,
156
- } from './infrastructure/services/user-document.types';
@@ -1,150 +0,0 @@
1
- /**
2
- * Firebase Auth Infrastructure Layer
3
- * Domain-Driven Design (DDD) - Infrastructure Exports
4
- *
5
- * Infrastructure implementation including:
6
- * - Firebase Auth client configuration
7
- * - Auth utilities and services
8
- * - Social auth providers
9
- * - Email/password authentication
10
- * - User document management
11
- */
12
-
13
- // =============================================================================
14
- // Firebase Auth Client
15
- // =============================================================================
16
-
17
- export {
18
- getFirebaseAuth,
19
- isFirebaseAuthInitialized,
20
- getFirebaseAuthInitializationError,
21
- resetFirebaseAuthClient,
22
- firebaseAuthClient,
23
- initializeFirebaseAuth,
24
- } from './infrastructure/config/FirebaseAuthClient';
25
-
26
- export type {
27
- Auth,
28
- } from './infrastructure/config/FirebaseAuthClient';
29
-
30
- // =============================================================================
31
- // Auth Utilities
32
- // =============================================================================
33
-
34
- export {
35
- checkAuthState,
36
- isAuthenticated,
37
- isAnonymous,
38
- getCurrentUserId,
39
- getCurrentUser,
40
- getCurrentUserIdFromGlobal,
41
- getCurrentUserFromGlobal,
42
- isCurrentUserAuthenticated,
43
- isCurrentUserAnonymous,
44
- verifyUserId,
45
- isValidUser,
46
- } from './infrastructure/services/auth-utils.service';
47
-
48
- export type {
49
- AuthCheckResult,
50
- } from './infrastructure/services/auth-utils.service';
51
-
52
- // =============================================================================
53
- // Anonymous Auth Service
54
- // =============================================================================
55
-
56
- export {
57
- AnonymousAuthService,
58
- anonymousAuthService,
59
- } from './infrastructure/services/anonymous-auth.service';
60
-
61
- export type {
62
- AnonymousAuthResult,
63
- AnonymousAuthServiceInterface,
64
- } from './infrastructure/services/anonymous-auth.service';
65
-
66
- // =============================================================================
67
- // Firestore Utilities
68
- // =============================================================================
69
-
70
- export {
71
- shouldSkipFirestoreQuery,
72
- createFirestoreQueryOptions,
73
- } from './infrastructure/services/firestore-utils.service';
74
-
75
- export type {
76
- FirestoreQueryOptions,
77
- FirestoreQueryResult,
78
- FirestoreQuerySkipReason,
79
- } from './infrastructure/services/firestore-utils.service';
80
-
81
- // =============================================================================
82
- // Social Auth Services
83
- // =============================================================================
84
-
85
- export {
86
- GoogleAuthService,
87
- googleAuthService,
88
- } from './infrastructure/services/google-auth.service';
89
- export type {
90
- GoogleAuthConfig,
91
- GoogleAuthResult,
92
- } from './infrastructure/services/google-auth.types';
93
-
94
- export {
95
- GoogleOAuthService,
96
- googleOAuthService,
97
- } from './infrastructure/services/google-oauth.service';
98
- export type {
99
- GoogleOAuthConfig,
100
- } from './infrastructure/services/google-oauth.service';
101
-
102
- export {
103
- AppleAuthService,
104
- appleAuthService,
105
- } from './infrastructure/services/apple-auth.service';
106
- export type { AppleAuthResult } from './infrastructure/services/apple-auth.types';
107
-
108
- // =============================================================================
109
- // Email/Password Authentication
110
- // =============================================================================
111
-
112
- export {
113
- signInWithEmail,
114
- signUpWithEmail,
115
- signOut,
116
- linkAnonymousWithEmail,
117
- } from './infrastructure/services/email-auth.service';
118
- export type {
119
- EmailCredentials,
120
- EmailAuthResult,
121
- } from './infrastructure/services/email-auth.service';
122
-
123
- // =============================================================================
124
- // Password Management
125
- // =============================================================================
126
-
127
- export {
128
- updateUserPassword,
129
- } from './infrastructure/services/password.service';
130
-
131
- // =============================================================================
132
- // Auth Listener
133
- // =============================================================================
134
-
135
- export {
136
- setupAuthListener,
137
- } from './infrastructure/services/auth-listener.service';
138
- export type {
139
- AuthListenerConfig,
140
- AuthListenerResult,
141
- } from './infrastructure/services/auth-listener.service';
142
-
143
- // =============================================================================
144
- // User Document Service
145
- // =============================================================================
146
-
147
- export {
148
- ensureUserDocument,
149
- markUserDeleted,
150
- configureUserDocumentService,
@@ -1,6 +0,0 @@
1
- } from './infrastructure/services/user-document.service';
2
- export type {
3
- UserDocumentUser,
4
- UserDocumentConfig,
5
- UserDocumentExtras,
6
- } from './infrastructure/services/user-document.types';
@@ -1,247 +0,0 @@
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,150 +0,0 @@
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 } {