Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. POST http://localhost:3000/signup 404 (Not Found)
  2. Uncaught (in promise) Error: Request failed with status code 404
  3.  
  4. export const createUser = values => async dispatch => {
  5. const res = await axios.post('/signup', values);
  6.  
  7. dispatch({
  8. type: CREATE_USER,
  9. payload: res
  10. });
  11. };
  12.  
  13. const passport = require('passport');
  14.  
  15. module.exports = app => {
  16. app.post(
  17. '/signup',
  18. passport.authenticate('local-signup', {
  19. successRedirect: '/',
  20. failureRedirect: '/signup',
  21. failureFlash: true
  22. }));
  23. };
  24.  
  25. const passport = require('passport');
  26. const LocalStrategy = require('passport-local').Strategy;
  27. const mongoose = require('mongoose');
  28. const User = mongoose.model('users');
  29.  
  30.  
  31. // Local signup strategy
  32. passport.use('local-signup', new LocalStrategy(
  33. {
  34. usernameField: 'email',
  35. paswordField: 'password',
  36. passReqToCallback: true
  37. },
  38. (req, email, password, done) => {
  39. console.log(req);
  40. User.findOne({ 'local.email': email }, (err, user) => {
  41. if (err) { return done(err); }
  42.  
  43. if (user) {
  44. return done(null, false, { message: 'That email already exists.' });
  45. } else {
  46. const newUser = new User({
  47. 'local.email': email,
  48. 'local.password': password
  49. }).save(err => {
  50. if (err) { throw err };
  51. });
  52. return done(null, newUser);
  53. console.log(newUser);
  54. }
  55. });
  56. }
  57. ));
  58.  
  59. import _ from 'lodash';
  60. import React, { Component } from 'react';
  61. import { connect } from 'react-redux';
  62. import { reduxForm, Field } from 'redux-form';
  63. import validateEmail from '../../utils/validateEmail';
  64. import FormField from './FormField';
  65. import signUpFields from './signUpFields';
  66. import * as actions from '../../actions';
  67.  
  68. class SignUp extends Component {
  69. onSubmit(values) {
  70. values.email = values.email.trim();
  71. this.props.createUser(values);
  72. }
  73.  
  74. renderFields() {
  75. return _.map(signUpFields, ({ label, name, type }) => {
  76. return <Field key={name} type={type} component={FormField} name={name} label={label} />
  77. });
  78. }
  79.  
  80. render() {
  81. return (
  82. <div>
  83. <h2>Sign Up</h2>
  84. <form onSubmit={this.props.handleSubmit(this.onSubmit.bind(this))}>
  85. {this.renderFields()}
  86. <button type='submit' className='teal btn-flat right white-text'>
  87. Sign Up
  88. </button>
  89. </form>
  90. </div>
  91. )
  92. }
  93. }
  94.  
  95. function validate(values) {
  96. const errors = {};
  97.  
  98. errors.username = validateEmail(values.username);
  99.  
  100. if (values.password !== values.confirmPassword) {
  101. errors.confirmPassword = 'Must match password';
  102. }
  103.  
  104. return errors;
  105. }
  106.  
  107. SignUp = reduxForm({
  108. validate,
  109. form: 'signupForm'
  110. })(SignUp);
  111.  
  112. export default connect(null, actions)(SignUp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement