Login user after setup (#1200)

This commit is contained in:
Mike Stone
2017-02-13 20:08:48 -05:00
committed by GitHub
parent e0c767bc1e
commit 545961ad5b
4 changed files with 33 additions and 24 deletions
+5 -5
View File
@@ -25,13 +25,12 @@ export class App extends Component {
if (!user && !!authToken()) {
dispatch(fetchCurrentUser())
.catch(() => {
return false;
});
.catch(() => false);
}
if (user) {
dispatch(getConfig());
dispatch(getConfig())
.catch(() => false);
}
return false;
@@ -41,7 +40,8 @@ export class App extends Component {
const { dispatch, user } = nextProps;
if (user && this.props.user !== user) {
dispatch(getConfig());
dispatch(getConfig())
.catch(() => false);
}
}
@@ -54,10 +54,10 @@ export class RegistrationPage extends Component {
onRegistrationFormSubmit = (formData) => {
const { dispatch } = this.props;
const { LOGIN } = paths;
const { MANAGE_HOSTS } = paths;
return dispatch(setup(formData))
.then(() => { return dispatch(push(LOGIN)); })
.then(() => { return dispatch(push(MANAGE_HOSTS)); })
.catch(() => { return false; });
}
@@ -73,25 +73,11 @@ export class ManageHostsPage extends Component {
}
componentWillMount () {
const { dispatch } = this.props;
dispatch(hostActions.loadAll());
dispatch(labelActions.loadAll());
dispatch(getStatusLabelCounts);
return false;
return this.getEntities();
}
componentDidMount () {
const { dispatch } = this.props;
const getEntities = () => {
dispatch(hostActions.silentLoadAll())
.catch(() => false);
dispatch(labelActions.silentLoadAll())
.catch(() => false);
dispatch(silentGetStatusLabelCounts)
.catch(() => false);
};
const { getEntities } = this;
this.interval = global.window.setInterval(getEntities, 5000);
@@ -236,6 +222,21 @@ export class ManageHostsPage extends Component {
};
}
getEntities = () => {
const { dispatch } = this.props;
const promises = [
dispatch(hostActions.silentLoadAll()),
dispatch(labelActions.silentLoadAll()),
dispatch(silentGetStatusLabelCounts),
];
Promise.all(promises)
.catch(() => false);
return false;
}
toggleAddHostModal = () => {
const { showAddHostModal } = this.state;
this.setState({ showAddHostModal: !showAddHostModal });
+9 -1
View File
@@ -1,6 +1,7 @@
import { configSuccess } from 'redux/nodes/app/actions';
import { formatErrorResponse } from 'redux/nodes/entities/base/helpers';
import Kolide from 'kolide';
import local from 'utilities/local';
import userActions from 'redux/nodes/entities/users/actions';
export const CLEAR_AUTH_ERRORS = 'CLEAR_AUTH_ERRORS';
@@ -149,10 +150,17 @@ export const setup = (registrationFormData) => {
return (dispatch) => {
return Kolide.setup(registrationFormData)
.then((response) => {
return dispatch(configSuccess({
const { token } = response;
dispatch(configSuccess({
kolide_server_url: response.kolide_server_url,
...response.org_info,
}));
local.setItem('auth_token', token);
Kolide.setBearerToken(token);
return dispatch(fetchCurrentUser());
});
};
};