OAuth frontend fixes and cleanup.

pull/922/head
Hunter Trujillo 2017-02-15 13:47:18 -07:00
parent 7e28642e8c
commit 4f89e7c4a0
4 changed files with 15 additions and 12 deletions

View File

@ -4,13 +4,13 @@ import {connect} from 'react-redux'
const {array} = PropTypes
const Login = ({auths}) => (
const Login = ({auth}) => (
<div className="auth-page">
<div className="auth-box">
<div className="auth-logo"></div>
<h1 className="auth-text-logo">Chronograf</h1>
<p><strong>{VERSION}</strong> / Time-Series Data Visualization</p>
{auths.map(({name, login, label}) => (
{auth.map(({name, login, label}) => (
<a key={name} className="btn btn-primary" href={login}>
<span className={`icon ${name}`}></span>
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)

View File

@ -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});
});
},

View File

@ -1,5 +1,5 @@
function getInitialState() {
return {};
return [];
}
const initialState = getInitialState();

View File

@ -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
}
}