Skip to content

Commit

Permalink
Added feedback when unauthorized user attempts login
Browse files Browse the repository at this point in the history
  • Loading branch information
tortilaman authored and erquhart committed Jul 21, 2017
1 parent 8a49924 commit 02afe17
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/backends/github/AuthenticationPage.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.root {
display: flex;
flex-flow: column nowrap;
align-items: center;
justify-content: center;
height: 100vh;
Expand Down
16 changes: 12 additions & 4 deletions src/backends/github/AuthenticationPage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from 'react';
import Button from 'react-toolbox/lib/button';
import { Toast } from '../../components/UI';
import Authenticator from '../../lib/netlify-auth';
import { Icon } from '../../components/UI';
import styles from './AuthenticationPage.css';

export default class AuthenticationPage extends React.Component {
static propTypes = {
onLogin: React.PropTypes.func.isRequired,
onLogin: React.PropTypes.func.isRequired
};

state = {};
Expand All @@ -16,7 +17,7 @@ export default class AuthenticationPage extends React.Component {
const cfg = {
base_url: this.props.base_url,
site_id: (document.location.host.split(':')[0] === 'localhost') ? 'cms.netlify.com' : this.props.siteId
}
};
const auth = new Authenticator(cfg);

auth.authenticate({ provider: 'github', scope: 'repo' }, (err, data) => {
Expand All @@ -28,12 +29,19 @@ export default class AuthenticationPage extends React.Component {
});
};

handleError = message => (
<Toast kind="warning" message={message} />
);

render() {
const { loginError } = this.state;
let { loginError } = this.state;
if (this.props.error !== null && this.props.error !== undefined) {
loginError = this.props.error;
}

return (
<section className={styles.root}>
{loginError && <p>{loginError}</p>}
{loginError && this.handleError(loginError.replace("Error: ", ""))}
<Button
className={styles.button}
raised
Expand Down
3 changes: 1 addition & 2 deletions src/backends/github/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export default class GitHub {
this.api.collaborator(user.login).then((status) => {
if (status === 404 || status === 403) {
// Unauthorized user
alert("Sorry, but you don't appear to have publisher access. If you think this is incorrect, talk to the site administrator");
throw new Error('Talk to the site administrator to get publishing access.');
throw new Error("Sorry, your user doesn't have CMS access. If you think this is incorrect, talk to the site administrator");
} else if (status === 204) {
// Authorized user
user.token = state.token;
Expand Down

0 comments on commit 02afe17

Please sign in to comment.