mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 17:28:54 +00:00
ee3d96eb53
* Updates eslint packages * Expected parentheses around arrow function argument having a body with curly braces * Prop type `object` is forbidden * Visible, non-interactive elements should not have mouse or keyboard event listeners * Prop type is defined but not used * Unexpected use of file extension "jsx" * Expected 'this' to be used by class method * HTML entities must be escaped * Prevent default behavior on more options button click
33 lines
783 B
JavaScript
33 lines
783 B
JavaScript
/* eslint-disable no-unused-vars */
|
|
import { push } from 'react-router-redux';
|
|
|
|
import kolide from '../../kolide';
|
|
import { LOGIN_FAILURE, LOGIN_SUCCESS, LOGOUT_SUCCESS } from '../nodes/auth/actions';
|
|
import local from '../../utilities/local';
|
|
import paths from '../../router/paths';
|
|
|
|
const authMiddleware = store => next => (action) => {
|
|
const { type, payload } = action;
|
|
|
|
if (type === LOGIN_SUCCESS) {
|
|
const { token } = payload;
|
|
|
|
if (token) {
|
|
local.setItem('auth_token', token);
|
|
kolide.setBearerToken(token);
|
|
}
|
|
}
|
|
|
|
if (type === LOGOUT_SUCCESS || type === LOGIN_FAILURE) {
|
|
const { LOGIN } = paths;
|
|
|
|
local.clear();
|
|
kolide.setBearerToken(null);
|
|
store.dispatch(push(LOGIN));
|
|
}
|
|
|
|
return next(action);
|
|
};
|
|
|
|
export default authMiddleware;
|