Skip to content

Commit 80bbca5

Browse files
committed
Show error message when autentication fails
1 parent 3adfe1e commit 80bbca5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/components/Login/LoginComponent.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ class LoginComponent extends React.Component{
77
constructor(props, context) {
88
super(props, context);
99
this.handleSubmit = this.handleSubmit.bind(this);
10+
this.state = {
11+
error: ''
12+
};
1013
}
1114

1215
handleSubmit(e) {
@@ -20,10 +23,22 @@ class LoginComponent extends React.Component{
2023
localStorage.token = response.data.token;
2124
this.context.router.push("/");
2225
}
26+
}).catch((error) => {
27+
this.setState({error: 'Authentication failed'});
28+
if (error.response.data) {
29+
this.setState({error: error.response.data.error});
30+
}
2331
});
2432
}
2533

2634
render() {
35+
let error = <span></span>;
36+
if (this.state.error) {
37+
error = <div className="notification is-danger">
38+
<button className="delete"></button>
39+
{this.state.error}
40+
</div>;
41+
}
2742
return (
2843
<section className="hero is-fullheight is-primary">
2944
<div className="hero-body">
@@ -35,6 +50,7 @@ class LoginComponent extends React.Component{
3550
</h1>
3651
<form onSubmit={this.handleSubmit}>
3752
<div className="box">
53+
{error}
3854
<label className="label">Username</label>
3955
<p className="control">
4056
<input

0 commit comments

Comments
 (0)