@umituz/react-native-firebase 1.13.12 → 1.13.14

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-firebase",
3
- "version": "1.13.12",
3
+ "version": "1.13.14",
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",
@@ -3,20 +3,15 @@
3
3
  * React hook for Firebase Auth state management
4
4
  *
5
5
  * Directly uses Firebase Auth's built-in state management via onAuthStateChanged
6
- * Includes retry mechanism to wait for Firebase initialization
6
+ * Simple, performant, no retry mechanism needed (auth is pre-initialized)
7
7
  */
8
8
 
9
- import { useEffect, useState, useRef, useCallback } from "react";
9
+ import { useEffect, useState, useRef } from "react";
10
10
  import { onAuthStateChanged, type User } from "firebase/auth";
11
11
  import { getFirebaseAuth } from "../../infrastructure/config/FirebaseAuthClient";
12
12
 
13
13
  declare const __DEV__: boolean;
14
14
 
15
- /** Retry interval in milliseconds */
16
- const RETRY_INTERVAL_MS = 100;
17
- /** Maximum retry attempts (100ms * 50 = 5 seconds max wait) */
18
- const MAX_RETRY_ATTEMPTS = 50;
19
-
20
15
  export interface UseFirebaseAuthResult {
21
16
  /** Current authenticated user from Firebase Auth */
22
17
  user: User | null;
@@ -30,7 +25,7 @@ export interface UseFirebaseAuthResult {
30
25
  * Hook for Firebase Auth state management
31
26
  *
32
27
  * Directly uses Firebase Auth's built-in state management.
33
- * Includes retry mechanism to wait for Firebase initialization.
28
+ * Auth is pre-initialized in appInitializer, so no retry needed.
34
29
  *
35
30
  * @example
36
31
  * ```typescript
@@ -42,101 +37,37 @@ export function useFirebaseAuth(): UseFirebaseAuthResult {
42
37
  const [loading, setLoading] = useState(true);
43
38
  const [initialized, setInitialized] = useState(false);
44
39
 
45
- const retryCountRef = useRef(0);
46
40
  const unsubscribeRef = useRef<(() => void) | null>(null);
47
- const retryIntervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
48
-
49
- const subscribeToAuth = useCallback(() => {
50
- try {
51
- const auth = getFirebaseAuth();
52
-
53
- if (!auth) {
54
- return false;
55
- }
56
-
57
- // Subscribe to auth state changes
58
- unsubscribeRef.current = onAuthStateChanged(auth, (currentUser: User | null) => {
59
- if (__DEV__) {
60
- console.log('[useFirebaseAuth] Auth state changed:', currentUser?.uid || 'null');
61
- }
62
- setUser(currentUser);
63
- setLoading(false);
64
- setInitialized(true);
65
- });
66
-
67
- return true;
68
- } catch {
69
- return false;
70
- }
71
- }, []);
72
41
 
73
42
  useEffect(() => {
74
- // Try to subscribe immediately - getFirebaseAuth() will auto-initialize
75
43
  const auth = getFirebaseAuth();
76
- if (auth) {
77
- if (__DEV__) {
78
- console.log('[useFirebaseAuth] Firebase Auth available, subscribing...');
79
- }
80
- setInitialized(true);
81
- subscribeToAuth();
82
- return () => {
83
- if (unsubscribeRef.current) {
84
- unsubscribeRef.current();
85
- }
86
- };
87
- }
88
44
 
89
- // Firebase not ready, start polling with getFirebaseAuth() which auto-initializes
90
- if (__DEV__) {
91
- console.log('[useFirebaseAuth] Firebase Auth not available, starting retry...');
45
+ if (!auth) {
46
+ // Auth not available (offline mode or error)
47
+ setLoading(false);
48
+ setUser(null);
49
+ setInitialized(false);
50
+ return;
92
51
  }
93
52
 
94
- retryIntervalRef.current = setInterval(() => {
95
- retryCountRef.current += 1;
96
-
97
- // getFirebaseAuth() will auto-initialize if Firebase App is available
98
- const authInstance = getFirebaseAuth();
99
- if (authInstance) {
100
- // Firebase Auth is now available, subscribe and stop polling
101
- if (__DEV__) {
102
- console.log('[useFirebaseAuth] Firebase Auth available after', retryCountRef.current, 'retries');
103
- }
104
-
105
- if (retryIntervalRef.current) {
106
- clearInterval(retryIntervalRef.current);
107
- retryIntervalRef.current = null;
108
- }
109
-
110
- setInitialized(true);
111
- subscribeToAuth();
112
- return;
113
- }
114
-
115
- if (retryCountRef.current >= MAX_RETRY_ATTEMPTS) {
116
- // Max retries reached, stop polling
117
- if (__DEV__) {
118
- console.log('[useFirebaseAuth] Max retries reached, Firebase Auth not available');
119
- }
120
-
121
- if (retryIntervalRef.current) {
122
- clearInterval(retryIntervalRef.current);
123
- retryIntervalRef.current = null;
124
- }
125
-
126
- setLoading(false);
127
- setUser(null);
53
+ // Subscribe to auth state changes
54
+ unsubscribeRef.current = onAuthStateChanged(auth, (currentUser: User | null) => {
55
+ if (__DEV__) {
56
+ console.log('[useFirebaseAuth] Auth state changed:', currentUser?.uid || 'null');
128
57
  }
129
- }, RETRY_INTERVAL_MS);
58
+ setUser(currentUser);
59
+ setLoading(false);
60
+ setInitialized(true);
61
+ });
130
62
 
63
+ // Cleanup on unmount
131
64
  return () => {
132
- if (retryIntervalRef.current) {
133
- clearInterval(retryIntervalRef.current);
134
- }
135
65
  if (unsubscribeRef.current) {
136
66
  unsubscribeRef.current();
67
+ unsubscribeRef.current = null;
137
68
  }
138
69
  };
139
- }, [subscribeToAuth]);
70
+ }, []); // Empty deps - subscribe once on mount
140
71
 
141
72
  return {
142
73
  user,