@umituz/react-native-firebase 1.13.29 → 1.13.31
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/auth/infrastructure/config/initializers/FirebaseAuthInitializer.ts +48 -71
- package/src/auth/infrastructure/stores/auth.store.ts +8 -7
- package/src/auth/presentation/hooks/useFirebaseAuth.ts +9 -15
- package/src/firestore/infrastructure/config/FirestoreClient.ts +3 -0
- package/src/firestore/infrastructure/repositories/BaseRepository.ts +3 -0
- package/src/infrastructure/config/FirebaseClient.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.31",
|
|
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",
|
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
* Platform-agnostic: Works on all platforms (Web, iOS, Android)
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
initializeAuth,
|
|
10
|
+
getAuth,
|
|
11
|
+
getReactNativePersistence,
|
|
12
|
+
} from 'firebase/auth';
|
|
9
13
|
import type { Auth } from 'firebase/auth';
|
|
10
14
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
11
15
|
import type { FirebaseApp } from 'firebase/app';
|
|
@@ -30,7 +34,6 @@ export class FirebaseAuthInitializer {
|
|
|
30
34
|
addPackageBreadcrumb('firebase-auth', 'Initializing Firebase Auth');
|
|
31
35
|
|
|
32
36
|
try {
|
|
33
|
-
// Try React Native persistence first (works on all platforms)
|
|
34
37
|
const auth = this.initializeWithPersistence(app, config);
|
|
35
38
|
|
|
36
39
|
if (auth) {
|
|
@@ -38,57 +41,54 @@ export class FirebaseAuthInitializer {
|
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
return auth;
|
|
41
|
-
} catch (error:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
} catch (error: unknown) {
|
|
45
|
+
return this.handleInitializationError(error, app);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static handleInitializationError(error: unknown, app: FirebaseApp): Auth | null {
|
|
50
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
51
|
+
const errorCode = (error as { code?: string })?.code;
|
|
52
|
+
|
|
53
|
+
if (errorCode === 'auth/already-initialized') {
|
|
54
|
+
trackPackageWarning(
|
|
55
|
+
'firebase-auth',
|
|
56
|
+
'Auth already initialized, returning existing instance',
|
|
57
|
+
{ errorCode }
|
|
58
|
+
);
|
|
59
|
+
return this.getExistingAuth(app);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
trackPackageError(errorObj, {
|
|
63
|
+
packageName: 'firebase-auth',
|
|
64
|
+
operation: 'initialize',
|
|
65
|
+
errorCode,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (__DEV__) {
|
|
69
|
+
console.warn('Firebase Auth initialization error:', error);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return this.getExistingAuth(app);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private static getExistingAuth(app: FirebaseApp): Auth | null {
|
|
76
|
+
try {
|
|
77
|
+
return getAuth(app);
|
|
78
|
+
} catch (getAuthError) {
|
|
79
|
+
const errorObj = getAuthError instanceof Error
|
|
80
|
+
? getAuthError
|
|
81
|
+
: new Error(String(getAuthError));
|
|
65
82
|
|
|
66
|
-
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
67
83
|
trackPackageError(errorObj, {
|
|
68
84
|
packageName: 'firebase-auth',
|
|
69
|
-
operation: '
|
|
70
|
-
errorCode: error.code,
|
|
85
|
+
operation: 'getAuth-fallback',
|
|
71
86
|
});
|
|
72
87
|
|
|
73
88
|
if (__DEV__) {
|
|
74
|
-
console.warn('Firebase Auth
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Try to get auth instance as fallback
|
|
78
|
-
try {
|
|
79
|
-
return getAuth(app);
|
|
80
|
-
} catch (getAuthError) {
|
|
81
|
-
const fallbackError = getAuthError instanceof Error ? getAuthError : new Error(String(getAuthError));
|
|
82
|
-
trackPackageError(fallbackError, {
|
|
83
|
-
packageName: 'firebase-auth',
|
|
84
|
-
operation: 'getAuth-fallback',
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (__DEV__) {
|
|
88
|
-
console.warn('Firebase Auth: Failed to get auth instance after initialization error:', getAuthError);
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
89
|
+
console.warn('Firebase Auth: Failed to get auth instance:', getAuthError);
|
|
91
90
|
}
|
|
91
|
+
return null;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -97,25 +97,6 @@ export class FirebaseAuthInitializer {
|
|
|
97
97
|
config?: FirebaseAuthConfig
|
|
98
98
|
): Auth | null {
|
|
99
99
|
try {
|
|
100
|
-
const authModule = require('firebase/auth');
|
|
101
|
-
const getReactNativePersistence = authModule.getReactNativePersistence;
|
|
102
|
-
|
|
103
|
-
if (!getReactNativePersistence) {
|
|
104
|
-
trackPackageWarning(
|
|
105
|
-
'firebase-auth',
|
|
106
|
-
'getReactNativePersistence not available, using default persistence'
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
if (__DEV__) {
|
|
110
|
-
console.log('Firebase Auth: getReactNativePersistence not available, using default persistence');
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
return getAuth(app);
|
|
114
|
-
} catch {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
100
|
const storage = config?.authStorage || {
|
|
120
101
|
getItem: (key: string) => AsyncStorage.getItem(key),
|
|
121
102
|
setItem: (key: string, value: string) => AsyncStorage.setItem(key, value),
|
|
@@ -137,12 +118,8 @@ export class FirebaseAuthInitializer {
|
|
|
137
118
|
if (__DEV__) {
|
|
138
119
|
console.warn('Firebase Auth: Persistence initialization failed:', error);
|
|
139
120
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
} catch {
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
121
|
+
|
|
122
|
+
return this.getExistingAuth(app);
|
|
145
123
|
}
|
|
146
124
|
}
|
|
147
125
|
}
|
|
148
|
-
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Firebase Auth Store
|
|
3
|
-
*
|
|
3
|
+
* Basic Zustand store for Firebase Auth state
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* NOTE: For comprehensive auth state management including
|
|
6
|
+
* user types and guest mode, use @umituz/react-native-auth package.
|
|
7
|
+
* This store provides minimal state for low-level Firebase operations.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { create } from "zustand";
|
|
@@ -27,7 +28,7 @@ type AuthStore = AuthState & AuthActions;
|
|
|
27
28
|
|
|
28
29
|
let unsubscribe: (() => void) | null = null;
|
|
29
30
|
|
|
30
|
-
export const
|
|
31
|
+
export const useFirebaseAuthStore = create<AuthStore>((set, get) => ({
|
|
31
32
|
user: null,
|
|
32
33
|
loading: true,
|
|
33
34
|
initialized: false,
|
|
@@ -36,7 +37,6 @@ export const useAuthStore = create<AuthStore>((set, get) => ({
|
|
|
36
37
|
setupListener: (auth: Auth) => {
|
|
37
38
|
const state = get();
|
|
38
39
|
|
|
39
|
-
// Only setup listener once
|
|
40
40
|
if (state.listenerSetup || unsubscribe) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -44,9 +44,10 @@ export const useAuthStore = create<AuthStore>((set, get) => ({
|
|
|
44
44
|
set({ listenerSetup: true });
|
|
45
45
|
|
|
46
46
|
unsubscribe = onAuthStateChanged(auth, (currentUser: User | null) => {
|
|
47
|
-
if (__DEV__) {
|
|
47
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
48
49
|
console.log(
|
|
49
|
-
"[
|
|
50
|
+
"[FirebaseAuthStore] Auth state changed:",
|
|
50
51
|
currentUser?.uid || "null"
|
|
51
52
|
);
|
|
52
53
|
}
|
|
@@ -1,38 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* useFirebaseAuth Hook
|
|
3
|
-
* React hook for Firebase Auth state
|
|
3
|
+
* React hook for raw Firebase Auth state
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* NOTE: For comprehensive auth management (user types, guest mode, sign in/out),
|
|
6
|
+
* use useAuth from @umituz/react-native-auth package instead.
|
|
7
|
+
* This hook provides minimal Firebase Auth access.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import { useEffect } from "react";
|
|
10
11
|
import type { User } from "firebase/auth";
|
|
11
12
|
import { getFirebaseAuth } from "../../infrastructure/config/FirebaseAuthClient";
|
|
12
|
-
import {
|
|
13
|
+
import { useFirebaseAuthStore } from "../../infrastructure/stores/auth.store";
|
|
13
14
|
|
|
14
15
|
export interface UseFirebaseAuthResult {
|
|
15
|
-
/** Current
|
|
16
|
+
/** Current Firebase user */
|
|
16
17
|
user: User | null;
|
|
17
|
-
/** Whether auth state is loading
|
|
18
|
+
/** Whether auth state is loading */
|
|
18
19
|
loading: boolean;
|
|
19
20
|
/** Whether Firebase Auth is initialized */
|
|
20
21
|
initialized: boolean;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
|
-
* Hook for Firebase Auth state
|
|
25
|
+
* Hook for raw Firebase Auth state
|
|
25
26
|
*
|
|
26
27
|
* Uses shared store to ensure only one listener is active.
|
|
27
|
-
* Auth is pre-initialized in appInitializer, so no retry needed.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const { user, loading } = useFirebaseAuth();
|
|
32
|
-
* ```
|
|
33
28
|
*/
|
|
34
29
|
export function useFirebaseAuth(): UseFirebaseAuthResult {
|
|
35
|
-
const { user, loading, initialized, setupListener } =
|
|
30
|
+
const { user, loading, initialized, setupListener } = useFirebaseAuthStore();
|
|
36
31
|
|
|
37
32
|
useEffect(() => {
|
|
38
33
|
const auth = getFirebaseAuth();
|
|
@@ -41,7 +36,6 @@ export function useFirebaseAuth(): UseFirebaseAuthResult {
|
|
|
41
36
|
return;
|
|
42
37
|
}
|
|
43
38
|
|
|
44
|
-
// Setup listener (will only run once due to store check)
|
|
45
39
|
setupListener(auth);
|
|
46
40
|
}, [setupListener]);
|
|
47
41
|
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
* - Dependency Inversion: Depends on Firebase App from @umituz/react-native-firebase
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) console.log("📍 [LIFECYCLE] FirestoreClient.ts - Module loading");
|
|
18
|
+
|
|
16
19
|
import type { Firestore } from 'firebase/firestore';
|
|
17
20
|
import { getFirebaseApp } from '../../../infrastructure/config/FirebaseClient';
|
|
18
21
|
import { FirebaseFirestoreInitializer } from './initializers/FirebaseFirestoreInitializer';
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
* It provides a consistent interface for Firestore operations.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
// eslint-disable-next-line no-console
|
|
18
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) console.log("📍 [LIFECYCLE] BaseRepository.ts - Module loading");
|
|
19
|
+
|
|
17
20
|
import type { Firestore } from "firebase/firestore";
|
|
18
21
|
import { getFirestore } from "../config/FirestoreClient";
|
|
19
22
|
import {
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
* - Dependency Inversion: Depends on abstractions (interfaces), not concrete implementations
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) console.log("📍 [LIFECYCLE] FirebaseClient.ts - Module loading");
|
|
21
|
+
|
|
19
22
|
import type { FirebaseConfig } from '../../domain/value-objects/FirebaseConfig';
|
|
20
23
|
import type { IFirebaseClient } from '../../application/ports/IFirebaseClient';
|
|
21
24
|
import type { FirebaseApp } from './initializers/FirebaseAppInitializer';
|