diff --git a/app/src/frontend/login.js b/app/src/frontend/login.js index 2529e4a0..2f349e64 100644 --- a/app/src/frontend/login.js +++ b/app/src/frontend/login.js @@ -29,6 +29,8 @@ class Login extends Component { handleSubmit(event) { event.preventDefault(); + this.setState({error: undefined}) + fetch('/login', { method: 'POST', body: JSON.stringify(this.state), @@ -41,7 +43,6 @@ class Login extends Component { if (res.error) { this.setState({error: res.error}) } else { - this.setState({error: undefined}) fetch('/users/me').then( (res) => res.json() ).then( diff --git a/app/src/frontend/my-account.js b/app/src/frontend/my-account.js index 110e0603..adfd7be8 100644 --- a/app/src/frontend/my-account.js +++ b/app/src/frontend/my-account.js @@ -1,28 +1,33 @@ import React, { Component } from 'react'; import { Redirect } from 'react-router'; +import ErrorBox from './error-box'; + class MyAccountPage extends Component { constructor(props) { super(props); + this.state = { + error: undefined + }; this.handleSubmit = this.handleSubmit.bind(this); } handleSubmit(event) { - const logout = this.props.logout; event.preventDefault(); + this.setState({error: undefined}); + fetch('/logout', { method: 'POST' }).then( res => res.json() ).then(function(res){ if (res.error) { - console.error(res.error); // tell user + this.setState({error: res.error}) } else { - logout(); - console.log(res); // redirect back + this.props.logout(); } - }).catch( - err => console.error(err) + }.bind(this)).catch( + (err) => this.setState({error: err}) ); } @@ -32,6 +37,7 @@ class MyAccountPage extends Component {

Welcome, {this.props.user.username}

+
diff --git a/app/src/frontend/signup.js b/app/src/frontend/signup.js index 7ff27f39..fd525983 100644 --- a/app/src/frontend/signup.js +++ b/app/src/frontend/signup.js @@ -32,6 +32,8 @@ class SignUp extends Component { handleSubmit(event) { event.preventDefault(); + this.setState({error: undefined}) + fetch('/users', { method: 'POST', body: JSON.stringify(this.state), @@ -44,7 +46,6 @@ class SignUp extends Component { if (res.error) { this.setState({error: res.error}) } else { - this.setState({error: undefined}) fetch('/users/me').then( (res) => res.json() ).then(