Fixed nasty error in Login
This commit is contained in:
parent
462cad0e53
commit
bad5d04238
4 changed files with 15 additions and 11 deletions
|
@ -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;
|
||||
|
|
|
@ -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}
|
||||
</Label>
|
||||
<Divider />
|
||||
<Button onClick={this.props.logout}>Logout</Button>
|
||||
<Button onClick={this.logout}>Logout</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
|
|
|
@ -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<Undefined, _>} 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<Undefined, RemoteError>} 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) {
|
||||
|
|
|
@ -95,7 +95,7 @@ class Login extends Component {
|
|||
color="blue"
|
||||
fluid
|
||||
size="large"
|
||||
onClick={this.handleLogin.bind(this)}
|
||||
onClick={this.handleLogin}
|
||||
>
|
||||
Login
|
||||
</Button>
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue