@umituz/react-native-firebase 1.13.28 → 1.13.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umituz/react-native-firebase",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.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",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"expo-crypto": ">=13.0.0",
|
|
36
36
|
"firebase": ">=10.0.0",
|
|
37
37
|
"react": ">=18.2.0",
|
|
38
|
-
"react-native": ">=0.74.0"
|
|
38
|
+
"react-native": ">=0.74.0",
|
|
39
|
+
"zustand": ">=5.0.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
@@ -49,7 +50,8 @@
|
|
|
49
50
|
"firebase": "^12.6.0",
|
|
50
51
|
"react": "19.1.0",
|
|
51
52
|
"react-native": "0.81.5",
|
|
52
|
-
"typescript": "~5.9.2"
|
|
53
|
+
"typescript": "~5.9.2",
|
|
54
|
+
"zustand": "^5.0.0"
|
|
53
55
|
},
|
|
54
56
|
"publishConfig": {
|
|
55
57
|
"access": "public"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Firebase Auth Store
|
|
3
|
+
* Basic Zustand store for Firebase Auth state
|
|
4
|
+
*
|
|
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.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { create } from "zustand";
|
|
11
|
+
import { onAuthStateChanged, type User, type Auth } from "firebase/auth";
|
|
12
|
+
|
|
13
|
+
declare const __DEV__: boolean;
|
|
14
|
+
|
|
15
|
+
interface AuthState {
|
|
16
|
+
user: User | null;
|
|
17
|
+
loading: boolean;
|
|
18
|
+
initialized: boolean;
|
|
19
|
+
listenerSetup: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface AuthActions {
|
|
23
|
+
setupListener: (auth: Auth) => void;
|
|
24
|
+
cleanup: () => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type AuthStore = AuthState & AuthActions;
|
|
28
|
+
|
|
29
|
+
let unsubscribe: (() => void) | null = null;
|
|
30
|
+
|
|
31
|
+
export const useFirebaseAuthStore = create<AuthStore>((set, get) => ({
|
|
32
|
+
user: null,
|
|
33
|
+
loading: true,
|
|
34
|
+
initialized: false,
|
|
35
|
+
listenerSetup: false,
|
|
36
|
+
|
|
37
|
+
setupListener: (auth: Auth) => {
|
|
38
|
+
const state = get();
|
|
39
|
+
|
|
40
|
+
if (state.listenerSetup || unsubscribe) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
set({ listenerSetup: true });
|
|
45
|
+
|
|
46
|
+
unsubscribe = onAuthStateChanged(auth, (currentUser: User | null) => {
|
|
47
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.log(
|
|
50
|
+
"[FirebaseAuthStore] Auth state changed:",
|
|
51
|
+
currentUser?.uid || "null"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
set({
|
|
55
|
+
user: currentUser,
|
|
56
|
+
loading: false,
|
|
57
|
+
initialized: true,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
cleanup: () => {
|
|
63
|
+
if (unsubscribe) {
|
|
64
|
+
unsubscribe();
|
|
65
|
+
unsubscribe = null;
|
|
66
|
+
}
|
|
67
|
+
set({
|
|
68
|
+
user: null,
|
|
69
|
+
loading: true,
|
|
70
|
+
initialized: false,
|
|
71
|
+
listenerSetup: false,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
}));
|
|
@@ -1,73 +1,43 @@
|
|
|
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
|
-
import { useEffect
|
|
10
|
-
import {
|
|
10
|
+
import { useEffect } from "react";
|
|
11
|
+
import type { User } from "firebase/auth";
|
|
11
12
|
import { getFirebaseAuth } from "../../infrastructure/config/FirebaseAuthClient";
|
|
12
|
-
|
|
13
|
-
declare const __DEV__: boolean;
|
|
13
|
+
import { useFirebaseAuthStore } from "../../infrastructure/stores/auth.store";
|
|
14
14
|
|
|
15
15
|
export interface UseFirebaseAuthResult {
|
|
16
|
-
/** Current
|
|
16
|
+
/** Current Firebase user */
|
|
17
17
|
user: User | null;
|
|
18
|
-
/** Whether auth state is loading
|
|
18
|
+
/** Whether auth state is loading */
|
|
19
19
|
loading: boolean;
|
|
20
20
|
/** Whether Firebase Auth is initialized */
|
|
21
21
|
initialized: boolean;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Hook for Firebase Auth state
|
|
26
|
-
*
|
|
27
|
-
* Directly uses Firebase Auth's built-in state management.
|
|
28
|
-
* Auth is pre-initialized in appInitializer, so no retry needed.
|
|
25
|
+
* Hook for raw Firebase Auth state
|
|
29
26
|
*
|
|
30
|
-
*
|
|
31
|
-
* ```typescript
|
|
32
|
-
* const { user, loading } = useFirebaseAuth();
|
|
33
|
-
* ```
|
|
27
|
+
* Uses shared store to ensure only one listener is active.
|
|
34
28
|
*/
|
|
35
29
|
export function useFirebaseAuth(): UseFirebaseAuthResult {
|
|
36
|
-
const
|
|
37
|
-
const [loading, setLoading] = useState(true);
|
|
38
|
-
const [initialized, setInitialized] = useState(false);
|
|
39
|
-
|
|
40
|
-
const unsubscribeRef = useRef<(() => void) | null>(null);
|
|
30
|
+
const { user, loading, initialized, setupListener } = useFirebaseAuthStore();
|
|
41
31
|
|
|
42
32
|
useEffect(() => {
|
|
43
33
|
const auth = getFirebaseAuth();
|
|
44
34
|
|
|
45
35
|
if (!auth) {
|
|
46
|
-
// Auth not available (offline mode or error)
|
|
47
|
-
setLoading(false);
|
|
48
|
-
setUser(null);
|
|
49
|
-
setInitialized(false);
|
|
50
36
|
return;
|
|
51
37
|
}
|
|
52
38
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (__DEV__) {
|
|
56
|
-
console.log('[useFirebaseAuth] Auth state changed:', currentUser?.uid || 'null');
|
|
57
|
-
}
|
|
58
|
-
setUser(currentUser);
|
|
59
|
-
setLoading(false);
|
|
60
|
-
setInitialized(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// Cleanup on unmount
|
|
64
|
-
return () => {
|
|
65
|
-
if (unsubscribeRef.current) {
|
|
66
|
-
unsubscribeRef.current();
|
|
67
|
-
unsubscribeRef.current = null;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}, []); // Empty deps - subscribe once on mount
|
|
39
|
+
setupListener(auth);
|
|
40
|
+
}, [setupListener]);
|
|
71
41
|
|
|
72
42
|
return {
|
|
73
43
|
user,
|
|
@@ -75,4 +45,3 @@ export function useFirebaseAuth(): UseFirebaseAuthResult {
|
|
|
75
45
|
initialized,
|
|
76
46
|
};
|
|
77
47
|
}
|
|
78
|
-
|