-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
plugin: authenticationFirebase AuthenticationFirebase Authenticationresolution: fixedA fix has been merged into main.A fix has been merged into main.type: bugNew bug reportNew bug report
Description
Issue
So auth.onAuthStateChanged()
works fine when I open the app in emulator. However, when I press R on the metro terminal the app reloads but auth.onAuthStateChanged()
does not fire. It works fine for iOS.
Is this an expected behaviour? I am using react native CLI
My versions are -
"@react-native-firebase/app": "^20.0.0", "@react-native-firebase/auth": "^20.0.0", "react": "18.2.0", "react-native": "0.74.1"
My JS:
import { View, Text } from 'react-native';
import auth from '@react-native-firebase/auth';
function App() {
// Set an initializing state whilst Firebase connects
const [initializing, setInitializing] = useState(true);
const [user, setUser] = useState();
// Handle user state changes
async function onAuthStateChanged(user) {
setUser(user);
if (initializing) setInitializing(false);
}
useEffect(() => {
const subscriber = auth().onAuthStateChanged(onAuthStateChanged);
if (auth().currentUser) {
onAuthStateChanged(auth().currentUser);
}
return subscriber; // unsubscribe on unmount
}, []);
if (initializing) return (
<View>
<Text>Loading</Text>
</View>
);
if (!user) {
return (
<View>
<Text>Login</Text>
</View>
);
}
return (
<View>
<Text>Welcome {user.email}</Text>
</View>
);
}
export default App;
Closing and reopening the app shows Login but when I press R I see Loading only
vm02, enlob, horiondreher and bugrafelekoglu
Metadata
Metadata
Assignees
Labels
plugin: authenticationFirebase AuthenticationFirebase Authenticationresolution: fixedA fix has been merged into main.A fix has been merged into main.type: bugNew bug reportNew bug report