2016-06-05 01:52:18 -07:00
|
|
|
import React from 'react';
|
2016-11-01 14:35:20 +01:00
|
|
|
import Button from 'react-toolbox/lib/button';
|
2016-06-05 01:52:18 -07:00
|
|
|
import Authenticator from '../../lib/netlify-auth';
|
2016-11-01 14:35:20 +01:00
|
|
|
import { Icon } from '../../components/UI';
|
2017-08-01 20:28:03 -07:00
|
|
|
import { Notifs } from 'redux-notifications';
|
|
|
|
import { Toast } from '../../components/UI/index';
|
2016-11-01 14:35:20 +01:00
|
|
|
import styles from './AuthenticationPage.css';
|
2016-06-05 01:52:18 -07:00
|
|
|
|
|
|
|
export default class AuthenticationPage extends React.Component {
|
|
|
|
static propTypes = {
|
2016-11-01 14:35:20 +01:00
|
|
|
onLogin: React.PropTypes.func.isRequired,
|
2016-06-05 01:52:18 -07:00
|
|
|
};
|
|
|
|
|
2016-10-03 14:25:27 +02:00
|
|
|
state = {};
|
2016-06-05 01:52:18 -07:00
|
|
|
|
2016-11-01 14:35:20 +01:00
|
|
|
handleLogin = (e) => {
|
2016-06-05 01:52:18 -07:00
|
|
|
e.preventDefault();
|
2017-05-07 06:38:33 +02:00
|
|
|
const cfg = {
|
|
|
|
base_url: this.props.base_url,
|
|
|
|
site_id: (document.location.host.split(':')[0] === 'localhost') ? 'cms.netlify.com' : this.props.siteId
|
2017-08-01 20:28:03 -07:00
|
|
|
};
|
2017-05-07 06:38:33 +02:00
|
|
|
const auth = new Authenticator(cfg);
|
2016-06-05 01:52:18 -07:00
|
|
|
|
2016-09-13 15:30:58 +02:00
|
|
|
auth.authenticate({ provider: 'github', scope: 'repo' }, (err, data) => {
|
2016-06-05 01:52:18 -07:00
|
|
|
if (err) {
|
2016-09-13 15:30:58 +02:00
|
|
|
this.setState({ loginError: err.toString() });
|
2016-06-05 01:52:18 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.props.onLogin(data);
|
|
|
|
});
|
2016-10-03 14:25:27 +02:00
|
|
|
};
|
2016-06-05 01:52:18 -07:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const { loginError } = this.state;
|
|
|
|
|
2016-11-01 14:35:20 +01:00
|
|
|
return (
|
|
|
|
<section className={styles.root}>
|
2017-08-01 20:28:03 -07:00
|
|
|
<Notifs CustomComponent={Toast} />
|
2016-11-01 14:35:20 +01:00
|
|
|
{loginError && <p>{loginError}</p>}
|
|
|
|
<Button
|
|
|
|
className={styles.button}
|
|
|
|
raised
|
|
|
|
onClick={this.handleLogin}
|
|
|
|
>
|
|
|
|
<Icon type="github" /> Login with GitHub
|
|
|
|
</Button>
|
|
|
|
</section>
|
|
|
|
);
|
2016-06-05 01:52:18 -07:00
|
|
|
}
|
|
|
|
}
|