@umituz/react-native-firebase 1.3.0 → 1.3.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.
package/LICENSE CHANGED
@@ -20,3 +20,14 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
package/README.md CHANGED
@@ -72,7 +72,9 @@ if (!app) {
72
72
  #### Direct Access
73
73
 
74
74
  ```typescript
75
- import { getFirebaseApp, getFirebaseAuth, getFirestore } from '@umituz/react-native-firebase';
75
+ import { getFirebaseApp } from '@umituz/react-native-firebase';
76
+ import { getFirebaseAuth } from '@umituz/react-native-firebase-auth';
77
+ import { getFirestore } from '@umituz/react-native-firestore';
76
78
 
77
79
  // Get instances
78
80
  const app = getFirebaseApp();
@@ -134,9 +136,7 @@ if (isFirebaseInitialized()) {
134
136
  - **Single Responsibility**: Each class has one clear purpose
135
137
  - `FirebaseConfigValidator`: Only validates configuration
136
138
  - `FirebaseAppInitializer`: Only initializes Firebase App
137
- - `FirebaseAuthInitializer`: Only initializes Auth
138
- - `FirebaseFirestoreInitializer`: Only initializes Firestore
139
- - `FirebaseClient`: Only orchestrates initialization
139
+ - `FirebaseClient`: Only orchestrates Firebase App initialization
140
140
 
141
141
  - **Open/Closed**: Extensible through configuration, closed for modification
142
142
 
@@ -157,28 +157,30 @@ if (isFirebaseInitialized()) {
157
157
 
158
158
  ### Functions
159
159
 
160
- - `initializeFirebase(config)`: Initialize Firebase client with configuration
161
- - `getFirebaseApp()`: Get Firebase app instance (throws if not initialized)
162
- - `getFirebaseAuth()`: Get Firebase Auth instance (throws if not initialized)
163
- - `getFirestore()`: Get Firestore instance (throws if not initialized)
164
- - `isFirebaseInitialized()`: Check if client is initialized
160
+ - `initializeFirebase(config)`: Initialize Firebase App with configuration
161
+ - `getFirebaseApp()`: Get Firebase App instance (throws if not initialized)
162
+ - `isFirebaseInitialized()`: Check if Firebase App is initialized
165
163
  - `getFirebaseInitializationError()`: Get initialization error if any
166
164
  - `resetFirebaseClient()`: Reset client instance (useful for testing)
167
165
 
168
166
  ### Types
169
167
 
170
168
  - `FirebaseConfig`: Configuration interface
171
- - `FirebaseApp`: Firebase app type
172
- - `Auth`: Firebase Auth type
173
- - `Firestore`: Firestore type
169
+ - `FirebaseApp`: Firebase App type
174
170
 
175
171
  ### Errors
176
172
 
177
173
  - `FirebaseError`: Base error class
178
174
  - `FirebaseInitializationError`: Initialization errors
179
175
  - `FirebaseConfigurationError`: Configuration errors
180
- - `FirebaseAuthError`: Authentication errors
181
- - `FirebaseFirestoreError`: Firestore errors
176
+
177
+ ### Related Packages
178
+
179
+ For other Firebase services, use dedicated packages:
180
+ - `@umituz/react-native-firebase-auth` - Firebase Authentication
181
+ - `@umituz/react-native-firebase-analytics` - Firebase Analytics
182
+ - `@umituz/react-native-firebase-crashlytics` - Firebase Crashlytics
183
+ - `@umituz/react-native-firestore` - Firestore initialization and utilities
182
184
 
183
185
  ## Integration with Expo
184
186
 
@@ -213,3 +215,7 @@ module.exports = () => {
213
215
 
214
216
  MIT
215
217
 
218
+
219
+
220
+
221
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@umituz/react-native-firebase",
3
- "version": "1.3.0",
4
- "description": "Domain-Driven Design Firebase client for React Native apps with type-safe operations and singleton pattern",
3
+ "version": "1.3.1",
4
+ "description": "Firebase core package for React Native apps - Centralized initialization for all Firebase services (App, Auth, Analytics, Crashlytics). Use dedicated packages for service-specific operations.",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
7
7
  "scripts": {
@@ -14,30 +14,26 @@
14
14
  "keywords": [
15
15
  "react-native",
16
16
  "firebase",
17
+ "firebase-core",
18
+ "firestore",
17
19
  "ddd",
18
- "domain-driven-design",
19
- "type-safe",
20
- "solid",
21
- "dry",
22
- "kiss",
23
- "singleton"
20
+ "domain-driven-design"
24
21
  ],
25
22
  "author": "Ümit UZ <umit@umituz.com>",
26
23
  "license": "MIT",
27
24
  "repository": {
28
25
  "type": "git",
29
- "url": "git+https://github.com/umituz/react-native-firebase.git"
26
+ "url": "https://github.com/umituz/react-native-firebase"
30
27
  },
31
28
  "peerDependencies": {
32
29
  "firebase": ">=11.0.0",
33
30
  "react": ">=18.2.0",
34
- "react-native": ">=0.74.0",
35
- "@react-native-async-storage/async-storage": ">=1.21.0"
31
+ "react-native": ">=0.74.0"
36
32
  },
37
33
  "devDependencies": {
38
- "firebase": "^11.10.0",
39
34
  "@types/react": "^18.2.45",
40
35
  "@types/react-native": "^0.73.0",
36
+ "firebase": "^11.0.0",
41
37
  "react": "^18.2.0",
42
38
  "react-native": "^0.74.0",
43
39
  "typescript": "^5.3.3"
@@ -6,12 +6,14 @@
6
6
  */
7
7
 
8
8
  import type { FirebaseApp } from 'firebase/app';
9
- import type { Auth } from 'firebase/auth';
10
- import type { Firestore } from 'firebase/firestore';
11
9
 
12
10
  /**
13
11
  * Firebase Client Interface
14
12
  * Defines the contract for Firebase client operations
13
+ *
14
+ * Note:
15
+ * - Firebase Auth is now handled by @umituz/react-native-firebase-auth
16
+ * - Firestore is now handled by @umituz/react-native-firestore
15
17
  */
16
18
  export interface IFirebaseClient {
17
19
  /**
@@ -20,18 +22,6 @@ export interface IFirebaseClient {
20
22
  */
21
23
  getApp(): FirebaseApp;
22
24
 
23
- /**
24
- * Get the Firebase Auth instance
25
- * @throws {FirebaseInitializationError} If client is not initialized
26
- */
27
- getAuth(): Auth;
28
-
29
- /**
30
- * Get the Firestore instance
31
- * @throws {FirebaseInitializationError} If client is not initialized
32
- */
33
- getFirestore(): Firestore;
34
-
35
25
  /**
36
26
  * Check if client is initialized
37
27
  */
@@ -49,3 +39,7 @@ export interface IFirebaseClient {
49
39
  reset(): void;
50
40
  }
51
41
 
42
+
43
+
44
+
45
+
@@ -43,51 +43,14 @@ export class FirebaseConfigurationError extends FirebaseError {
43
43
  }
44
44
  }
45
45
 
46
- /**
47
- * Analytics Error
48
- * Thrown when analytics operations fail
49
- */
50
- export class FirebaseAnalyticsError extends FirebaseError {
51
- constructor(message: string, originalError?: unknown) {
52
- super(message, 'ANALYTICS_ERROR', originalError);
53
- this.name = 'FirebaseAnalyticsError';
54
- Object.setPrototypeOf(this, FirebaseAnalyticsError.prototype);
55
- }
56
- }
46
+ // Note: FirebaseAnalyticsError, FirebaseCrashlyticsError, FirebaseAuthError, and FirebaseFirestoreError
47
+ // have been moved to their respective packages:
48
+ // - @umituz/react-native-firebase-analytics
49
+ // - @umituz/react-native-firebase-crashlytics
50
+ // - @umituz/react-native-firebase-auth
51
+ // - @umituz/react-native-firestore
52
+
57
53
 
58
- /**
59
- * Crashlytics Error
60
- * Thrown when crashlytics operations fail
61
- */
62
- export class FirebaseCrashlyticsError extends FirebaseError {
63
- constructor(message: string, originalError?: unknown) {
64
- super(message, 'CRASHLYTICS_ERROR', originalError);
65
- this.name = 'FirebaseCrashlyticsError';
66
- Object.setPrototypeOf(this, FirebaseCrashlyticsError.prototype);
67
- }
68
- }
69
54
 
70
- /**
71
- * Auth Error
72
- * Thrown when authentication operations fail
73
- */
74
- export class FirebaseAuthError extends FirebaseError {
75
- constructor(message: string, originalError?: unknown) {
76
- super(message, 'AUTH_ERROR', originalError);
77
- this.name = 'FirebaseAuthError';
78
- Object.setPrototypeOf(this, FirebaseAuthError.prototype);
79
- }
80
- }
81
55
 
82
- /**
83
- * Firestore Error
84
- * Thrown when Firestore operations fail
85
- */
86
- export class FirebaseFirestoreError extends FirebaseError {
87
- constructor(message: string, originalError?: unknown) {
88
- super(message, 'FIRESTORE_ERROR', originalError);
89
- this.name = 'FirebaseFirestoreError';
90
- Object.setPrototypeOf(this, FirebaseFirestoreError.prototype);
91
- }
92
- }
93
56
 
@@ -38,16 +38,6 @@ export interface FirebaseConfig {
38
38
  * Firebase App ID
39
39
  */
40
40
  appId?: string;
41
-
42
- /**
43
- * Optional: Custom storage adapter for Auth persistence
44
- * If not provided, AsyncStorage will be used for React Native
45
- */
46
- authStorage?: {
47
- getItem: (key: string) => Promise<string | null>;
48
- setItem: (key: string, value: string) => Promise<void>;
49
- removeItem: (key: string) => Promise<void>;
50
- };
51
41
  }
52
42
 
53
43
  // Validation moved to FirebaseConfigValidator class (SOLID: Single Responsibility)
package/src/index.ts CHANGED
@@ -1,19 +1,22 @@
1
1
  /**
2
- * React Native Firebase - Public API
2
+ * React Native Firebase - Minimal Core Package
3
3
  *
4
4
  * Domain-Driven Design (DDD) Architecture
5
5
  *
6
- * This is the SINGLE SOURCE OF TRUTH for all Firebase operations.
7
- * ALL imports from the Firebase package MUST go through this file.
6
+ * This package provides ONLY Firebase App initialization.
7
+ * For other Firebase services, use dedicated packages:
8
+ * - @umituz/react-native-firebase-auth - Firebase Authentication
9
+ * - @umituz/react-native-firebase-analytics - Firebase Analytics
10
+ * - @umituz/react-native-firebase-crashlytics - Firebase Crashlytics
11
+ * - @umituz/react-native-firestore - Firestore initialization and utilities
8
12
  *
9
13
  * Architecture:
10
14
  * - domain: Entities, value objects, errors (business logic)
11
15
  * - application: Ports (interfaces)
12
- * - infrastructure: Firebase client implementation + services
13
- * - presentation: Hooks, decorators (React integration)
16
+ * - infrastructure: Firebase client implementation
14
17
  *
15
18
  * Usage:
16
- * import { initializeFirebase, firebaseAnalyticsService, TrackEvent } from '@umituz/react-native-firebase';
19
+ * import { initializeFirebase, getFirebaseApp } from '@umituz/react-native-firebase';
17
20
  */
18
21
 
19
22
  // =============================================================================
@@ -24,10 +27,6 @@ export {
24
27
  FirebaseError,
25
28
  FirebaseInitializationError,
26
29
  FirebaseConfigurationError,
27
- FirebaseAnalyticsError,
28
- FirebaseCrashlyticsError,
29
- FirebaseAuthError,
30
- FirebaseFirestoreError,
31
30
  } from './domain/errors/FirebaseError';
32
31
 
33
32
  export type { FirebaseConfig } from './domain/value-objects/FirebaseConfig';
@@ -45,8 +44,8 @@ export type { IFirebaseClient } from './application/ports/IFirebaseClient';
45
44
  export {
46
45
  initializeFirebase,
47
46
  getFirebaseApp,
48
- getFirebaseAuth,
49
- getFirestore,
47
+ autoInitializeFirebase,
48
+ initializeAllFirebaseServices,
50
49
  isFirebaseInitialized,
51
50
  getFirebaseInitializationError,
52
51
  resetFirebaseClient,
@@ -55,45 +54,5 @@ export {
55
54
 
56
55
  export type {
57
56
  FirebaseApp,
58
- Auth,
59
- Firestore,
60
57
  } from './infrastructure/config/FirebaseClient';
61
58
 
62
- // =============================================================================
63
- // SERVICES - Analytics, Crashlytics, Performance
64
- // =============================================================================
65
-
66
- export {
67
- firebaseAnalyticsService,
68
- } from './infrastructure/services/analytics/FirebaseAnalyticsService';
69
- export type { IAnalyticsService } from './infrastructure/services/analytics/FirebaseAnalyticsService';
70
-
71
- export {
72
- firebaseCrashlyticsService,
73
- } from './infrastructure/services/crashlytics/FirebaseCrashlyticsService';
74
- export type { ICrashlyticsService } from './infrastructure/services/crashlytics/FirebaseCrashlyticsService';
75
-
76
- export {
77
- performanceTracker,
78
- PerformanceTracker,
79
- } from './infrastructure/services/performance/PerformanceTracker';
80
-
81
- // =============================================================================
82
- // PRESENTATION LAYER - Decorators
83
- // =============================================================================
84
-
85
- export {
86
- TrackEvent,
87
- trackEvent,
88
- } from './presentation/decorators/TrackingDecorator';
89
-
90
- export {
91
- TrackErrors,
92
- trackErrors,
93
- } from './presentation/decorators/ErrorTrackingDecorator';
94
-
95
- export {
96
- TrackPerformance,
97
- TrackOperation,
98
- } from './presentation/decorators/PerformanceDecorator';
99
-
@@ -14,15 +14,12 @@
14
14
  */
15
15
 
16
16
  import type { FirebaseApp } from 'firebase/app';
17
- import type { Auth } from 'firebase/auth';
18
- import type { Firestore } from 'firebase/firestore';
19
17
  import type { FirebaseConfig } from '../../domain/value-objects/FirebaseConfig';
20
18
  import { FirebaseInitializationError } from '../../domain/errors/FirebaseError';
21
19
  import type { IFirebaseClient } from '../../application/ports/IFirebaseClient';
22
20
  import { FirebaseConfigValidator } from './validators/FirebaseConfigValidator';
23
21
  import { FirebaseAppInitializer } from './initializers/FirebaseAppInitializer';
24
- import { FirebaseAuthInitializer } from './initializers/FirebaseAuthInitializer';
25
- import { FirebaseFirestoreInitializer } from './initializers/FirebaseFirestoreInitializer';
22
+ import { loadFirebaseConfig } from './FirebaseConfigLoader';
26
23
 
27
24
  /**
28
25
  * Firebase Client Singleton
@@ -31,8 +28,6 @@ import { FirebaseFirestoreInitializer } from './initializers/FirebaseFirestoreIn
31
28
  class FirebaseClientSingleton implements IFirebaseClient {
32
29
  private static instance: FirebaseClientSingleton | null = null;
33
30
  private app: FirebaseApp | null = null;
34
- private auth: Auth | null = null;
35
- private db: Firestore | null = null;
36
31
  private initializationError: string | null = null;
37
32
 
38
33
  private constructor() {
@@ -74,12 +69,6 @@ class FirebaseClientSingleton implements IFirebaseClient {
74
69
  // Initialize Firebase App
75
70
  this.app = FirebaseAppInitializer.initialize(config);
76
71
 
77
- // Initialize Auth
78
- this.auth = FirebaseAuthInitializer.initialize(this.app, config);
79
-
80
- // Initialize Firestore
81
- this.db = FirebaseFirestoreInitializer.initialize(this.app);
82
-
83
72
  return this.app;
84
73
  } catch (error) {
85
74
  this.initializationError =
@@ -92,45 +81,23 @@ class FirebaseClientSingleton implements IFirebaseClient {
92
81
 
93
82
  /**
94
83
  * Get the Firebase app instance
95
- * @throws {FirebaseInitializationError} If client is not initialized
84
+ * Auto-initializes from Constants/environment if not already initialized
85
+ * Returns null if config is not available (offline mode)
86
+ * @returns Firebase app instance or null if not initialized
96
87
  */
97
- getApp(): FirebaseApp {
98
- if (!this.app) {
99
- const errorMsg =
100
- this.initializationError ||
101
- 'Firebase client not initialized. Call initialize() first with configuration.';
102
- throw new FirebaseInitializationError(errorMsg);
88
+ getApp(): FirebaseApp | null {
89
+ // Auto-initialize if not already initialized
90
+ if (!this.app && !this.initializationError) {
91
+ const autoConfig = loadFirebaseConfig();
92
+ if (autoConfig) {
93
+ this.initialize(autoConfig);
94
+ }
103
95
  }
104
- return this.app;
105
- }
106
96
 
107
- /**
108
- * Get the Firebase Auth instance
109
- * @throws {FirebaseInitializationError} If client is not initialized
110
- */
111
- getAuth(): Auth {
112
- if (!this.auth) {
113
- const errorMsg =
114
- this.initializationError ||
115
- 'Firebase client not initialized. Call initialize() first with configuration.';
116
- throw new FirebaseInitializationError(errorMsg);
117
- }
118
- return this.auth;
97
+ // Return null if not initialized (offline mode - no error)
98
+ return this.app || null;
119
99
  }
120
100
 
121
- /**
122
- * Get the Firestore instance
123
- * @throws {FirebaseInitializationError} If client is not initialized
124
- */
125
- getFirestore(): Firestore {
126
- if (!this.db) {
127
- const errorMsg =
128
- this.initializationError ||
129
- 'Firebase client not initialized. Call initialize() first with configuration.';
130
- throw new FirebaseInitializationError(errorMsg);
131
- }
132
- return this.db;
133
- }
134
101
 
135
102
  /**
136
103
  * Check if client is initialized
@@ -152,8 +119,6 @@ class FirebaseClientSingleton implements IFirebaseClient {
152
119
  */
153
120
  reset(): void {
154
121
  this.app = null;
155
- this.auth = null;
156
- this.db = null;
157
122
  this.initializationError = null;
158
123
  }
159
124
  }
@@ -191,26 +156,115 @@ export function initializeFirebase(
191
156
 
192
157
  /**
193
158
  * Get Firebase app instance
194
- * @throws {FirebaseInitializationError} If client is not initialized
159
+ * Auto-initializes from Constants/environment if not already initialized
160
+ * Returns null if config is not available (offline mode - no error)
161
+ * @returns Firebase app instance or null if not initialized
195
162
  */
196
- export function getFirebaseApp(): FirebaseApp {
163
+ export function getFirebaseApp(): FirebaseApp | null {
197
164
  return firebaseClient.getApp();
198
165
  }
199
166
 
200
167
  /**
201
- * Get Firebase Auth instance
202
- * @throws {FirebaseInitializationError} If client is not initialized
168
+ * Auto-initialize Firebase from Constants/environment
169
+ * Called automatically when getFirebaseApp() is first accessed
170
+ * Can be called manually to initialize early
171
+ * @returns Firebase app instance or null if initialization fails
203
172
  */
204
- export function getFirebaseAuth(): Auth {
205
- return firebaseClient.getAuth();
173
+ export function autoInitializeFirebase(): FirebaseApp | null {
174
+ const config = loadFirebaseConfig();
175
+ if (config) {
176
+ return initializeFirebase(config);
177
+ }
178
+ return null;
206
179
  }
207
180
 
208
181
  /**
209
- * Get Firestore instance
210
- * @throws {FirebaseInitializationError} If client is not initialized
182
+ * Initialize all Firebase services (App, Auth, Analytics, Crashlytics)
183
+ * This is the main entry point for applications - call this once at app startup
184
+ * All services will be initialized automatically if Firebase App is available
185
+ *
186
+ * @param config - Optional Firebase configuration (if not provided, will auto-load from Constants/env)
187
+ * @returns Object with initialization results for each service
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * import { initializeAllFirebaseServices } from '@umituz/react-native-firebase';
192
+ *
193
+ * // Auto-initialize from Constants/env
194
+ * const result = await initializeAllFirebaseServices();
195
+ *
196
+ * // Or provide config explicitly
197
+ * const result = await initializeAllFirebaseServices({
198
+ * apiKey: 'your-api-key',
199
+ * projectId: 'your-project-id',
200
+ * // ...
201
+ * });
202
+ * ```
211
203
  */
212
- export function getFirestore(): Firestore {
213
- return firebaseClient.getFirestore();
204
+ export async function initializeAllFirebaseServices(
205
+ config?: FirebaseConfig
206
+ ): Promise<{
207
+ app: FirebaseApp | null;
208
+ auth: any | null;
209
+ analytics: any | null;
210
+ crashlytics: any | null;
211
+ }> {
212
+ // 1. Initialize Firebase App
213
+ let app: FirebaseApp | null = null;
214
+ if (config) {
215
+ app = initializeFirebase(config);
216
+ } else {
217
+ app = autoInitializeFirebase();
218
+ }
219
+
220
+ if (!app) {
221
+ // Firebase App not available - return null for all services
222
+ return {
223
+ app: null,
224
+ auth: null,
225
+ analytics: null,
226
+ crashlytics: null,
227
+ };
228
+ }
229
+
230
+ // 2. Initialize Firebase Auth (if package is available)
231
+ let auth: any | null = null;
232
+ try {
233
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
234
+ const { initializeFirebaseAuth } = require('@umituz/react-native-firebase-auth');
235
+ auth = initializeFirebaseAuth();
236
+ } catch {
237
+ // @umituz/react-native-firebase-auth not available
238
+ }
239
+
240
+ // 3. Initialize Firebase Analytics (if package is available)
241
+ let analytics: any | null = null;
242
+ try {
243
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
244
+ const { firebaseAnalyticsService } = require('@umituz/react-native-firebase-analytics');
245
+ await firebaseAnalyticsService.init();
246
+ analytics = firebaseAnalyticsService;
247
+ } catch {
248
+ // @umituz/react-native-firebase-analytics not available
249
+ }
250
+
251
+ // 4. Initialize Firebase Crashlytics (if package is available)
252
+ let crashlytics: any | null = null;
253
+ try {
254
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
255
+ const { firebaseCrashlyticsService } = require('@umituz/react-native-firebase-crashlytics');
256
+ await firebaseCrashlyticsService.init();
257
+ crashlytics = firebaseCrashlyticsService;
258
+ } catch {
259
+ // @umituz/react-native-firebase-crashlytics not available
260
+ }
261
+
262
+ return {
263
+ app,
264
+ auth,
265
+ analytics,
266
+ crashlytics,
267
+ };
214
268
  }
215
269
 
216
270
  /**
@@ -237,6 +291,4 @@ export function resetFirebaseClient(): void {
237
291
 
238
292
  // Export types
239
293
  export type { FirebaseApp } from 'firebase/app';
240
- export type { Auth } from 'firebase/auth';
241
- export type { Firestore } from 'firebase/firestore';
242
294
  export type { FirebaseConfig } from '../../domain/value-objects/FirebaseConfig';
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Firebase Config Loader
3
+ *
4
+ * Automatically loads Firebase configuration from:
5
+ * 1. expo-constants (Constants.expoConfig?.extra)
6
+ * 2. Environment variables (process.env)
7
+ *
8
+ * This allows zero-configuration Firebase initialization.
9
+ */
10
+
11
+ import type { FirebaseConfig } from '../../domain/value-objects/FirebaseConfig';
12
+
13
+ /**
14
+ * Load Firebase configuration from Constants and environment variables
15
+ * Returns null if no valid configuration is found
16
+ */
17
+ export function loadFirebaseConfig(): FirebaseConfig | null {
18
+ let Constants: any;
19
+
20
+ // Try to load expo-constants (optional dependency)
21
+ try {
22
+ Constants = require('expo-constants');
23
+ } catch {
24
+ // expo-constants not available, skip
25
+ }
26
+
27
+ // Try both Constants.expoConfig and Constants.default.expoConfig
28
+ const expoConfig = Constants?.expoConfig || Constants?.default?.expoConfig;
29
+ const extra = expoConfig?.extra;
30
+
31
+ const config: Partial<FirebaseConfig> = {
32
+ apiKey:
33
+ extra?.firebaseApiKey ||
34
+ process.env.EXPO_PUBLIC_FIREBASE_API_KEY ||
35
+ process.env.FIREBASE_API_KEY ||
36
+ '',
37
+ authDomain:
38
+ extra?.firebaseAuthDomain ||
39
+ process.env.EXPO_PUBLIC_FIREBASE_AUTH_DOMAIN ||
40
+ process.env.FIREBASE_AUTH_DOMAIN ||
41
+ '',
42
+ projectId:
43
+ extra?.firebaseProjectId ||
44
+ process.env.EXPO_PUBLIC_FIREBASE_PROJECT_ID ||
45
+ process.env.FIREBASE_PROJECT_ID ||
46
+ '',
47
+ storageBucket:
48
+ extra?.firebaseStorageBucket ||
49
+ process.env.EXPO_PUBLIC_FIREBASE_STORAGE_BUCKET ||
50
+ process.env.FIREBASE_STORAGE_BUCKET ||
51
+ '',
52
+ messagingSenderId:
53
+ extra?.firebaseMessagingSenderId ||
54
+ process.env.EXPO_PUBLIC_FIREBASE_MESSAGING_SENDER_ID ||
55
+ process.env.FIREBASE_MESSAGING_SENDER_ID ||
56
+ '',
57
+ appId:
58
+ extra?.firebaseAppId ||
59
+ process.env.EXPO_PUBLIC_FIREBASE_APP_ID ||
60
+ process.env.FIREBASE_APP_ID ||
61
+ '',
62
+ };
63
+
64
+ // Only return config if required fields are present and not empty
65
+ if (
66
+ config.apiKey &&
67
+ config.projectId &&
68
+ config.apiKey.trim() !== '' &&
69
+ config.projectId.trim() !== ''
70
+ ) {
71
+ return config as FirebaseConfig;
72
+ }
73
+
74
+ return null;
75
+ }
76
+
@@ -44,3 +44,14 @@ export class FirebaseAppInitializer {
44
44
  }
45
45
  }
46
46
 
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+