From d8a990af71bbd9231a56c9c06509660801be6fc0 Mon Sep 17 00:00:00 2001 From: Francesco Esposito <33671357+frsposito@users.noreply.github.com> Date: Thu, 25 Jul 2019 09:50:22 +0200 Subject: [PATCH] improvement: various --- src/containers/Administration/Login.js | 41 +++++++------------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/src/containers/Administration/Login.js b/src/containers/Administration/Login.js index 5b701f5..08e5f5b 100644 --- a/src/containers/Administration/Login.js +++ b/src/containers/Administration/Login.js @@ -9,7 +9,7 @@ import { Input } from 'reactstrap'; -import { config } from '../../config'; +import { login } from '../../api/authentication'; import Card from '../../components/Card'; import Button from '../../components/Button'; @@ -44,46 +44,24 @@ class Login extends Component { const { email, password } = this.state; - const body = { - email, - password - } - - fetch(`${config.baseURL}users/login`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(body) - }) - .then(res => { - return res.json(); - }) + login(email, password) .then((json) => { if (!json.success) { this.setState({ error: json.message }); - } else { - localStorage.setItem('token', json.token); + localStorage.setItem('user', JSON.stringify(json.data)); this.setState({ success: true }); } - }) .catch((err) => { - if (err === 'AuthErr'){ - this.setState({ - err: 'auth error' - }); - } else { - this.setState({ - err: err.message - }); - } - + this.setState({ + error: err.message + }); }); - } resetLogin(event) { @@ -97,10 +75,11 @@ class Login extends Component { } render() { - if (this.state.error) { return ( - +

{this.state.error}

Back to login
@@ -112,7 +91,7 @@ class Login extends Component { ) } - + return (