diff --git a/smart-hut/src/App.js b/smart-hut/src/App.js index 820e9ea..d847bd3 100644 --- a/smart-hut/src/App.js +++ b/smart-hut/src/App.js @@ -73,9 +73,6 @@ class App extends Component { } } -const mapStateToProps = (state, _) => { - console.log("malusae react", state); - return { loggedIn: !!(state.login && state.login.loggedIn) }; -}; +const mapStateToProps = (state, _) => ({ loggedIn: state.login.loggedIn }); const AppContainer = connect(mapStateToProps, RemoteService)(App); export default AppContainer; diff --git a/smart-hut/src/components/HeaderController.js b/smart-hut/src/components/HeaderController.js index e0adbf4..08dc3af 100644 --- a/smart-hut/src/components/HeaderController.js +++ b/smart-hut/src/components/HeaderController.js @@ -25,6 +25,11 @@ export class MyHeader extends React.Component { }; this.getInfo(); + this.logout = this.logout.bind(this); + } + + logout() { + this.props.logout().then(() => this.props.history.push("/")); } getInfo() { @@ -55,7 +60,7 @@ export class MyHeader extends React.Component { {this.state.username} - + diff --git a/smart-hut/src/remote.js b/smart-hut/src/remote.js index e070415..48de388 100644 --- a/smart-hut/src/remote.js +++ b/smart-hut/src/remote.js @@ -85,7 +85,6 @@ const Endpoint = { .then((res) => { localStorage.setItem("token", res.data.jwttoken); localStorage.setItem("exp", new Date().getTime() + 5 * 60 * 60 * 1000); - Endpoint.socket = new ServiceSocket(res.data.jwttoken); return res.data.jwttoken; }); }, @@ -95,6 +94,8 @@ const Endpoint = { * @return {Promise} An always-resolved promise */ logout: () => { + localStorage.removeItem("token"); + localStorage.removeItem("exp"); return Promise.resolve(void 0); }, @@ -285,7 +286,7 @@ export const RemoteService = { * @returns {Promise} promise that resolves to void and rejects * with user-fiendly errors as a RemoteError */ - updateDevice: (data) => { + saveDevice: (data) => { return (dispatch) => { let url = "/device"; if ((data.id && data.flowType === "OUTPUT") || !data.id) { diff --git a/smart-hut/src/views/Login.js b/smart-hut/src/views/Login.js index 4d80aad..375d1a5 100644 --- a/smart-hut/src/views/Login.js +++ b/smart-hut/src/views/Login.js @@ -95,7 +95,7 @@ class Login extends Component { color="blue" fluid size="large" - onClick={this.handleLogin.bind(this)} + onClick={this.handleLogin} > Login @@ -116,7 +116,8 @@ class Login extends Component { } const mapStateToProps = (state, _) => ({ loggedIn: state.login.loggedIn }); -const LoginContainer = withRouter(connect(mapStateToProps, RemoteService))( - Login -); +const LoginContainer = connect( + mapStateToProps, + RemoteService +)(withRouter(Login)); export default LoginContainer;