I'm developing my first app in React-native and I'm using firebase with it. It uses e-mail and password for user authentication. Before using firebase, loading raw data from code, it worked fine on Android and iOS.
When I integrated firebase with it, I couldn't make the auth work correctly on Android, for example, the buttons that are wired to firebase register, are letting the user register without throwing exceptions. But, after reloading the app to continue to the 'MainView' of the app, it would not exit the 'SplashScreen' because it is not able to retrieve information from firebase. I realized that the register was not creating the corresponding user doc in my firestore collection while in iOS, with the same code, it does!
Here's the code I'm having trouble with:
class Enter extends React.Component {
(...)
signUp = () => {
const { email, pass } = this.state;
firebase.auth().createUserWithEmailAndPassword(email, pass).then(firebaseUser => {
base.collection('users').doc(firebaseUser.uid).set({ email })
.catch(error => {
this.setState({error: error.message})
console.log('doc requiring error: ' + error.message)
});
}).catch(error => {
this.setState({error: error.message})
console.log('account creation error: ' + error.message)
} );
}
render() {
[A button calls signUp onPress]
}
}
am I missing something in the signUp function?
Just in case, here's the way I'm trying to retrieve the doc from App.js. It gets stuck on the SplashScreen because userReady never gets to true because the users/{uid} document was not created in the registry.
componentWillMount = async () => {
firebase.auth().onAuthStateChanged(firebaseUser => {
if (firebaseUser) {
base.collection('users').doc(firebaseUser.uid)
.onSnapshot(DocumentSnapshot => {
this.setState({ userDocumentSnapshot: DocumentSnapshot, userReady: true })
});
} else {
this.setState({ userDocumentSnapshot: null, userReady: true });
}
});
}
Thanks in advance