Skip to content

Commit

Permalink
Fix bug in authentication middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Remchi committed Aug 8, 2016
1 parent d47881c commit b15425c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
32 changes: 16 additions & 16 deletions client/components/signup/SignupForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ class SignupForm extends React.Component {
}

checkUserExists(e) {
// const field = e.target.name;
// const val = e.target.value;
// if (val !== '') {
// this.props.isUserExists(val).then(res => {
// let errors = this.state.errors;
// let invalid;
// if (res.data.user) {
// errors[field] = 'There is user with such ' + field;
// invalid = true;
// } else {
// errors[field] = '';
// invalid = false;
// }
// this.setState({ errors, invalid });
// });
// }
const field = e.target.name;
const val = e.target.value;
if (val !== '') {
this.props.isUserExists(val).then(res => {
let errors = this.state.errors;
let invalid;
if (res.data.user) {
errors[field] = 'There is user with such ' + field;
invalid = true;
} else {
errors[field] = '';
invalid = false;
}
this.setState({ errors, invalid });
});
}
}

onSubmit(e) {
Expand Down
5 changes: 3 additions & 2 deletions server/middlewares/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export default (req, res, next) => {
}).fetch().then(user => {
if (!user) {
res.status(404).json({ error: 'No such user' });
} else {
req.currentUser = user;
next();
}

req.currentUser = user;
next();
});
}
});
Expand Down

0 comments on commit b15425c

Please sign in to comment.