2016-06-05 01:52:18 -07:00
|
|
|
import React from 'react';
|
|
|
|
import Authenticator from '../../lib/netlify-auth';
|
|
|
|
|
|
|
|
export default class AuthenticationPage extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
onLogin: React.PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {};
|
|
|
|
this.handleLogin = this.handleLogin.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLogin(e) {
|
|
|
|
e.preventDefault();
|
2016-07-20 13:46:52 -03:00
|
|
|
let auth;
|
|
|
|
if (document.location.host.split(':')[0] === 'localhost') {
|
|
|
|
auth = new Authenticator({ site_id: 'cms.netlify.com' });
|
|
|
|
} else {
|
|
|
|
auth = new Authenticator();
|
|
|
|
}
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { loginError } = this.state;
|
|
|
|
|
|
|
|
return <div>
|
|
|
|
{loginError && <p>{loginError}</p>}
|
|
|
|
<p><a href="#" onClick={this.handleLogin}>Login with GitHub</a></p>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|