I've did some research and found that some people suggest not to use Navigation.navigate(" "), I'm using firebase auth and when a user signs in, I want to redirect the user to Home screen. How could it be done without using navigation.navigate(" ")
This is my App.js
return (
<NavigationContainer>
<Stack.Navigator>
{user ? (
< Stack.Screen name="HomeScreen" component={HomeScreen} />
) : (
<>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Registration" component={RegistrationScreen} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
Here is where I'm using to login the user.
const onLoginPress = () => {
firebase.auth()
.signInWithEmailAndPassword(email, password)
.then((response) => {
const uid = response.user.uid
const usersRef = firebase.firestore().collection('users')
usersRef
.doc(uid)
.get()
.then(firestoreDocument => {
if (!firestoreDocument.exists) {
alert("User does not exist anymore.")
return;
}
const user = firestoreDocument.data()
navigation.navigate('HomeScreen')
})
.catch(error => {
alert(error)
});
})
.catch(error => {
alert(error)
})
}
Any help will be appreciated :)