diff --git a/ui/src/auth/Login.js b/ui/src/auth/Login.js index c40e0f394..87a9dd4ba 100644 --- a/ui/src/auth/Login.js +++ b/ui/src/auth/Login.js @@ -4,13 +4,13 @@ import {connect} from 'react-redux' const {array} = PropTypes -const Login = ({auths}) => ( +const Login = ({auth}) => (

Chronograf

{VERSION} / Time-Series Data Visualization

- {auths.map(({name, login, label}) => ( + {auth.map(({name, login, label}) => ( Login with {label} @@ -23,13 +23,11 @@ const Login = ({auths}) => ( ) Login.propTypes = { - auths: array.isRequired, + auth: array.isRequired, } -const mapStateToProps = (state) => { - return { - auths: state.auth, - } -} +const mapStateToProps = (state) => ({ + auth: state.auth, +}) export default connect(mapStateToProps)(Login) diff --git a/ui/src/index.js b/ui/src/index.js index 4872d7694..5ea5ae3c8 100644 --- a/ui/src/index.js +++ b/ui/src/index.js @@ -70,11 +70,15 @@ const Root = React.createClass({ if (store.getState().me.links) { return this.setState({loggedIn: true}); } - getMe().then(({data: {me, auth}}) => { + getMe().then(({data: me, auth}) => { store.dispatch(receiveMe(me)); store.dispatch(receiveAuth(auth)); this.setState({loggedIn: true}); - }).catch(() => { + }).catch((error) => { + if (error.auth) { + store.dispatch(receiveAuth(error.auth)); + } + this.setState({loggedIn: false}); }); }, diff --git a/ui/src/shared/reducers/auth.js b/ui/src/shared/reducers/auth.js index 4f5f37f4c..2a4cc8cc9 100644 --- a/ui/src/shared/reducers/auth.js +++ b/ui/src/shared/reducers/auth.js @@ -1,5 +1,5 @@ function getInitialState() { - return {}; + return []; } const initialState = getInitialState(); diff --git a/ui/src/utils/ajax.js b/ui/src/utils/ajax.js index 1375a0d6e..654e4dbfc 100644 --- a/ui/src/utils/ajax.js +++ b/ui/src/utils/ajax.js @@ -50,6 +50,7 @@ export default async function AJAX({ if (!response.status === UNAUTHORIZED) { console.error(error) // eslint-disable-line no-console } - throw {response} // eslint-disable-line no-throw-literal + const {auth} = links + throw {auth, ...response} // eslint-disable-line no-throw-literal } }