October 2017
Intermediate to advanced
302 pages
7h 27m
English
Our handleSubmit function is getting a little long and difficult to follow. Let's do some reorganization before we move on.
We'll start by moving everything after the initial if statement inside a separate function, called login(), for simplicity:
login() { firebase .auth() .signInWithEmailAndPassword(this.state.email, this.state.password) .then(res => { console.log(res); }) .catch(err => { if (err.code === 'auth/user-not-found') { this.signup(); } else { this.setState({ error: 'Error logging in.' }); } });}
Then, our handleSubmit becomes much smaller:
handleSubmit = event => { event.preventDefault(); this.setState({ error: '' }); if (this.state.email && this.state.password) { this.login(); } else { this.setState({ error: 'Please ...Read now
Unlock full access