53 lines
1.4 KiB
JavaScript
53 lines
1.4 KiB
JavaScript
|
import React from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import styled from 'react-emotion';
|
||
|
import { NetlifyAuthenticator } from 'netlify-cms-lib-auth';
|
||
|
import { AuthenticationPage, Icon } from 'netlify-cms-ui-default';
|
||
|
|
||
|
const LoginButtonIcon = styled(Icon)`
|
||
|
margin-right: 18px;
|
||
|
`
|
||
|
|
||
|
export default class BitbucketAuthenticationPage extends React.Component {
|
||
|
static propTypes = {
|
||
|
onLogin: PropTypes.func.isRequired,
|
||
|
inProgress: PropTypes.bool,
|
||
|
};
|
||
|
|
||
|
state = {};
|
||
|
|
||
|
handleLogin = (e) => {
|
||
|
e.preventDefault();
|
||
|
const cfg = {
|
||
|
base_url: this.props.base_url,
|
||
|
site_id: (document.location.host.split(':')[0] === 'localhost') ? 'cms.netlify.com' : this.props.site_id,
|
||
|
auth_endpoint: this.props.authEndpoint,
|
||
|
};
|
||
|
const auth = new NetlifyAuthenticator(cfg);
|
||
|
|
||
|
auth.authenticate({ provider: 'bitbucket', scope: 'repo' }, (err, data) => {
|
||
|
if (err) {
|
||
|
this.setState({ loginError: err.toString() });
|
||
|
return;
|
||
|
}
|
||
|
this.props.onLogin(data);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
|
<AuthenticationPage
|
||
|
onLogin={this.handleLogin}
|
||
|
loginDisabled={this.props.inProgress}
|
||
|
loginErrorMessage={this.state.loginError}
|
||
|
renderButtonContent={() => (
|
||
|
<React.Fragment>
|
||
|
<LoginButtonIcon type="bitbucket"/>
|
||
|
{inProgress ? "Logging in..." : "Login with Bitbucket"}
|
||
|
</React.Fragment>
|
||
|
)}
|
||
|
/>
|
||
|
);
|
||
|
}
|
||
|
}
|