Skip to content

Instantly share code, notes, and snippets.

@mrcflorian
Last active August 20, 2023 18:47
Show Gist options
  • Save mrcflorian/99d7b46ae8323f103213e331c1f1d7ff to your computer and use it in GitHub Desktop.
Save mrcflorian/99d7b46ae8323f103213e331c1f1d7ff to your computer and use it in GitHub Desktop.
...
import { firebase } from '../../firebase/config'
...
export default function LoginScreen({navigation}) {
...
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('Home', {user})
})
.catch(error => {
alert(error)
});
})
.catch(error => {
alert(error)
})
}
...
}
@dp-05
Copy link

dp-05 commented Aug 20, 2023

@mrcflorian You're not supposed to manually navigate when conditionally rendering screens. See here: https://reactnavigation.org/docs/auth-flow/#dont-manually-navigate-when-conditionally-rendering-screens.

Suggested that this be removed: navigation.navigate('Home', {user}) (line 27)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment