Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- POST http://localhost:3000/signup 404 (Not Found)
- Uncaught (in promise) Error: Request failed with status code 404
- export const createUser = values => async dispatch => {
- const res = await axios.post('/signup', values);
- dispatch({
- type: CREATE_USER,
- payload: res
- });
- };
- const passport = require('passport');
- module.exports = app => {
- app.post(
- '/signup',
- passport.authenticate('local-signup', {
- successRedirect: '/',
- failureRedirect: '/signup',
- failureFlash: true
- }));
- };
- const passport = require('passport');
- const LocalStrategy = require('passport-local').Strategy;
- const mongoose = require('mongoose');
- const User = mongoose.model('users');
- // Local signup strategy
- passport.use('local-signup', new LocalStrategy(
- {
- usernameField: 'email',
- paswordField: 'password',
- passReqToCallback: true
- },
- (req, email, password, done) => {
- console.log(req);
- User.findOne({ 'local.email': email }, (err, user) => {
- if (err) { return done(err); }
- if (user) {
- return done(null, false, { message: 'That email already exists.' });
- } else {
- const newUser = new User({
- 'local.email': email,
- 'local.password': password
- }).save(err => {
- if (err) { throw err };
- });
- return done(null, newUser);
- console.log(newUser);
- }
- });
- }
- ));
- import _ from 'lodash';
- import React, { Component } from 'react';
- import { connect } from 'react-redux';
- import { reduxForm, Field } from 'redux-form';
- import validateEmail from '../../utils/validateEmail';
- import FormField from './FormField';
- import signUpFields from './signUpFields';
- import * as actions from '../../actions';
- class SignUp extends Component {
- onSubmit(values) {
- values.email = values.email.trim();
- this.props.createUser(values);
- }
- renderFields() {
- return _.map(signUpFields, ({ label, name, type }) => {
- return <Field key={name} type={type} component={FormField} name={name} label={label} />
- });
- }
- render() {
- return (
- <div>
- <h2>Sign Up</h2>
- <form onSubmit={this.props.handleSubmit(this.onSubmit.bind(this))}>
- {this.renderFields()}
- <button type='submit' className='teal btn-flat right white-text'>
- Sign Up
- </button>
- </form>
- </div>
- )
- }
- }
- function validate(values) {
- const errors = {};
- errors.username = validateEmail(values.username);
- if (values.password !== values.confirmPassword) {
- errors.confirmPassword = 'Must match password';
- }
- return errors;
- }
- SignUp = reduxForm({
- validate,
- form: 'signupForm'
- })(SignUp);
- export default connect(null, actions)(SignUp);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement