Handle errors logging in
This commit is contained in:
parent
2e80c9d2e9
commit
aae5c1ca32
@ -32,8 +32,11 @@ class App extends React.Component {
|
||||
}
|
||||
|
||||
login(user) {
|
||||
console.log("Logging in")
|
||||
console.log(user)
|
||||
if (user.error) {
|
||||
this.logout();
|
||||
return
|
||||
}
|
||||
console.log("Logging in", user);
|
||||
this.setState({user: user});
|
||||
}
|
||||
|
||||
|
@ -38,18 +38,25 @@ class Login extends Component {
|
||||
body: JSON.stringify(this.state),
|
||||
headers:{
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
},
|
||||
credentials: 'same-origin'
|
||||
}).then(
|
||||
res => res.json()
|
||||
).then(function(res){
|
||||
if (res.error) {
|
||||
this.setState({error: res.error})
|
||||
} else {
|
||||
fetch('/users/me').then(
|
||||
fetch('/users/me', {
|
||||
credentials: 'same-origin'
|
||||
}).then(
|
||||
(res) => res.json()
|
||||
).then(
|
||||
(user) => this.props.login(user)
|
||||
).catch(
|
||||
).then(user => {
|
||||
if (user.error) {
|
||||
this.setState({error: user.error})
|
||||
} else {
|
||||
this.props.login(user)
|
||||
}
|
||||
}).catch(
|
||||
(err) => this.setState({error: err})
|
||||
)
|
||||
}
|
||||
@ -59,7 +66,7 @@ class Login extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.props.user) {
|
||||
if (this.props.user && !this.props.user.error) {
|
||||
return <Redirect to="/my-account.html" />
|
||||
}
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user