@umituz/react-native-firebase 2.4.28 → 2.4.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/domains/auth/infrastructure/config/FirebaseAuthClient.ts +17 -6
- package/src/domains/firestore/infrastructure/config/FirestoreClient.ts +17 -6
- package/src/index.ts +13 -1
- package/src/init/createFirebaseInitModule.ts +4 -8
- package/src/shared/infrastructure/config/FirebaseConfigLoader.ts +9 -2
- package/src/shared/infrastructure/config/clients/FirebaseClientSingleton.ts +7 -4
- package/src/shared/infrastructure/config/orchestrators/FirebaseInitializationOrchestrator.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.30",
|
|
4
4
|
"description": "Unified Firebase package for React Native apps - Auth and Firestore services using Firebase JS SDK (no native modules).",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -69,12 +69,23 @@ class FirebaseAuthClientSingleton extends ServiceClientSingleton<Auth, FirebaseA
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
function getFirebaseAuthClientSafe(): FirebaseAuthClientSingleton | null {
|
|
73
|
+
try {
|
|
74
|
+
return FirebaseAuthClientSingleton.getInstance();
|
|
75
|
+
} catch {
|
|
76
|
+
if (__DEV__) {
|
|
77
|
+
console.warn('[Firebase] Could not create FirebaseAuth client singleton.');
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const firebaseAuthClient = getFirebaseAuthClientSafe();
|
|
84
|
+
export const initializeFirebaseAuth = (c?: FirebaseAuthConfig) => firebaseAuthClient?.initialize(c) ?? null;
|
|
85
|
+
export const getFirebaseAuth = () => firebaseAuthClient?.getAuth() ?? null;
|
|
86
|
+
export const isFirebaseAuthInitialized = () => firebaseAuthClient?.isInitialized() ?? false;
|
|
87
|
+
export const getFirebaseAuthInitializationError = () => firebaseAuthClient?.getInitializationError() ?? null;
|
|
88
|
+
export const resetFirebaseAuthClient = () => firebaseAuthClient?.reset();
|
|
78
89
|
|
|
79
90
|
export type { Auth } from 'firebase/auth';
|
|
80
91
|
export type { FirebaseAuthConfig } from '../../domain/value-objects/FirebaseAuthConfig';
|
|
@@ -61,26 +61,37 @@ class FirestoreClientSingleton extends ServiceClientSingleton<Firestore> {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
function getFirestoreClientSafe(): FirestoreClientSingleton | null {
|
|
65
|
+
try {
|
|
66
|
+
return FirestoreClientSingleton.getInstance();
|
|
67
|
+
} catch {
|
|
68
|
+
if (__DEV__) {
|
|
69
|
+
console.warn('[Firestore] Could not create Firestore client singleton.');
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const firestoreClient = getFirestoreClientSafe();
|
|
65
76
|
|
|
66
77
|
export function initializeFirestore(): Firestore | null {
|
|
67
|
-
return firestoreClient
|
|
78
|
+
return firestoreClient?.initialize() ?? null;
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
export function getFirestore(): Firestore | null {
|
|
71
|
-
return firestoreClient
|
|
82
|
+
return firestoreClient?.getFirestore() ?? null;
|
|
72
83
|
}
|
|
73
84
|
|
|
74
85
|
export function isFirestoreInitialized(): boolean {
|
|
75
|
-
return firestoreClient
|
|
86
|
+
return firestoreClient?.isInitialized() ?? false;
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
export function getFirestoreInitializationError(): string | null {
|
|
79
|
-
return firestoreClient
|
|
90
|
+
return firestoreClient?.getInitializationError() ?? null;
|
|
80
91
|
}
|
|
81
92
|
|
|
82
93
|
export function resetFirestoreClient(): void {
|
|
83
|
-
firestoreClient
|
|
94
|
+
firestoreClient?.reset();
|
|
84
95
|
}
|
|
85
96
|
|
|
86
97
|
export type { Firestore } from 'firebase/firestore';
|
package/src/index.ts
CHANGED
|
@@ -35,7 +35,19 @@ export type {
|
|
|
35
35
|
export type { FirebaseApp } from "./shared/infrastructure/config/initializers/FirebaseAppInitializer";
|
|
36
36
|
|
|
37
37
|
import { FirebaseClientSingleton } from "./shared/infrastructure/config/clients/FirebaseClientSingleton";
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
function getFirebaseClientSafe(): FirebaseClientSingleton | null {
|
|
40
|
+
try {
|
|
41
|
+
return FirebaseClientSingleton.getInstance();
|
|
42
|
+
} catch {
|
|
43
|
+
if (__DEV__) {
|
|
44
|
+
console.warn('[Firebase] Could not create Firebase client singleton — Firebase may not be configured.');
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const firebaseClient = getFirebaseClientSafe();
|
|
39
51
|
|
|
40
52
|
// Type Guards
|
|
41
53
|
export {
|
|
@@ -39,7 +39,7 @@ export interface FirebaseInitModuleConfig {
|
|
|
39
39
|
export function createFirebaseInitModule(
|
|
40
40
|
config: FirebaseInitModuleConfig = {}
|
|
41
41
|
): InitModule {
|
|
42
|
-
const { authInitializer, critical =
|
|
42
|
+
const { authInitializer, critical = false } = config;
|
|
43
43
|
|
|
44
44
|
return {
|
|
45
45
|
name: 'firebase',
|
|
@@ -50,28 +50,24 @@ export function createFirebaseInitModule(
|
|
|
50
50
|
authInitializer: authInitializer ?? (() => Promise.resolve()),
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
// Check if initialization was successful
|
|
54
53
|
if (!result.app) {
|
|
55
54
|
if (__DEV__) {
|
|
56
|
-
console.
|
|
55
|
+
console.warn('[Firebase] Firebase config not found or invalid — skipping initialization. Set EXPO_PUBLIC_FIREBASE_* env vars to enable.');
|
|
57
56
|
}
|
|
58
57
|
return false;
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
// Check if auth initialization failed
|
|
62
60
|
if (result.auth === false && result.authError) {
|
|
63
61
|
if (__DEV__) {
|
|
64
|
-
console.
|
|
62
|
+
console.warn(`[Firebase] Auth initialization skipped: ${result.authError}`);
|
|
65
63
|
}
|
|
66
|
-
// Auth failure is not critical for the app to function
|
|
67
|
-
// Log the error but don't fail the entire initialization
|
|
68
64
|
}
|
|
69
65
|
|
|
70
66
|
return true;
|
|
71
67
|
} catch (error) {
|
|
72
68
|
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
73
69
|
if (__DEV__) {
|
|
74
|
-
console.
|
|
70
|
+
console.warn(`[Firebase] Initialization skipped: ${errorMessage}`);
|
|
75
71
|
}
|
|
76
72
|
return false;
|
|
77
73
|
}
|
|
@@ -83,16 +83,23 @@ export function loadFirebaseConfig(): FirebaseConfig | null {
|
|
|
83
83
|
const projectId = config.projectId?.trim();
|
|
84
84
|
|
|
85
85
|
if (!isValidString(apiKey) || !isValidString(authDomain) || !isValidString(projectId)) {
|
|
86
|
+
if (__DEV__) {
|
|
87
|
+
console.warn('[Firebase] Missing required config (apiKey, authDomain, or projectId). Set EXPO_PUBLIC_FIREBASE_* env vars.');
|
|
88
|
+
}
|
|
86
89
|
return null;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
// Validate API key format
|
|
90
92
|
if (!isValidFirebaseApiKey(apiKey)) {
|
|
93
|
+
if (__DEV__) {
|
|
94
|
+
console.warn('[Firebase] Invalid Firebase API key format.');
|
|
95
|
+
}
|
|
91
96
|
return null;
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
// Validate authDomain format (should be like "projectId.firebaseapp.com")
|
|
95
99
|
if (!isValidFirebaseAuthDomain(authDomain)) {
|
|
100
|
+
if (__DEV__) {
|
|
101
|
+
console.warn('[Firebase] Invalid Firebase authDomain format.');
|
|
102
|
+
}
|
|
96
103
|
return null;
|
|
97
104
|
}
|
|
98
105
|
|
|
@@ -55,11 +55,14 @@ export class FirebaseClientSingleton implements IFirebaseClient {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
isInitialized(): boolean {
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
try {
|
|
59
|
+
if (this.state && this.state.isInitialized()) return true;
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
const app = FirebaseInitializationOrchestrator.autoInitialize();
|
|
62
|
+
return app !== null;
|
|
63
|
+
} catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
getInitializationError(): string | null {
|
package/src/shared/infrastructure/config/orchestrators/FirebaseInitializationOrchestrator.ts
CHANGED
|
@@ -47,7 +47,11 @@ export class FirebaseInitializationOrchestrator {
|
|
|
47
47
|
* Get existing app instance
|
|
48
48
|
*/
|
|
49
49
|
static autoInitialize(): FirebaseApp | null {
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
try {
|
|
51
|
+
const existingApps = getApps();
|
|
52
|
+
return existingApps.length > 0 ? (existingApps[0] ?? null) : null;
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
52
56
|
}
|
|
53
57
|
}
|