add dotenv, start to add signup
This commit is contained in:
parent
675379d1f3
commit
c496f20699
5 changed files with 26 additions and 16 deletions
|
@ -47,6 +47,7 @@
|
||||||
"mongoose": "^4.4.16",
|
"mongoose": "^4.4.16",
|
||||||
"passport": "^0.3.2",
|
"passport": "^0.3.2",
|
||||||
"passport-github": "^1.1.0",
|
"passport-github": "^1.1.0",
|
||||||
|
"passport-jwt": "^2.0.0",
|
||||||
"passport-local": "^1.0.0",
|
"passport-local": "^1.0.0",
|
||||||
"react": "^15.0.2",
|
"react": "^15.0.2",
|
||||||
"react-dom": "^15.0.2",
|
"react-dom": "^15.0.2",
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
const passport = require('passport');
|
const passport = require('passport');
|
||||||
|
const JwtStrategy = require('passport-jwt').Strategy;
|
||||||
|
const ExtractJwt = require('passport-jwt').ExtractJwt;
|
||||||
const GitHubStrategy = require('passport-github').Strategy;
|
const GitHubStrategy = require('passport-github').Strategy;
|
||||||
const LocalStrategy = require('passport-local').Strategy;
|
const LocalStrategy = require('passport-local').Strategy;
|
||||||
|
|
||||||
const User = require('../models/user');
|
const User = require('../models/user');
|
||||||
|
|
||||||
|
// Setup options for JWT Strategy
|
||||||
|
const jwtOptions = {
|
||||||
|
jwtFromRequest: ExtractJwt.fromHeader('authorization'),
|
||||||
|
secretOrKey: "steve brule"
|
||||||
|
};
|
||||||
|
|
||||||
passport.serializeUser((user, done) => {
|
passport.serializeUser((user, done) => {
|
||||||
done(null, user.id);
|
done(null, user.id);
|
||||||
});
|
});
|
||||||
|
@ -31,6 +39,22 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, (email, password, don
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// Create JWT strategy
|
||||||
|
passport.use(new JwtStrategy(jwtOptions, function(payload, done) {
|
||||||
|
// See if the user ID in the payload exists in our database
|
||||||
|
// If it does, call 'done' with that other
|
||||||
|
// otherwise, call done without a user object
|
||||||
|
User.findById(payload.sub, function(err, user) {
|
||||||
|
if (err) { return done(err, false); }
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
done(null, user);
|
||||||
|
} else {
|
||||||
|
done(null, false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign in with GitHub.
|
* Sign in with GitHub.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,6 +9,7 @@ export function newUser(req, res) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createUser(req, res, next) {
|
export function createUser(req, res, next) {
|
||||||
|
console.log("in create user");
|
||||||
const user = new User({
|
const user = new User({
|
||||||
username: req.body.username,
|
username: req.body.username,
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
|
|
|
@ -24,24 +24,11 @@ import serverConfig from './config';
|
||||||
import users from './routes/user.routes';
|
import users from './routes/user.routes';
|
||||||
|
|
||||||
//Body parser, cookie parser, sessions, serve public assets
|
//Body parser, cookie parser, sessions, serve public assets
|
||||||
const MongoStore = require('connect-mongo')(session);
|
|
||||||
|
|
||||||
app.use(Express.static(path.resolve(__dirname, '../static')));
|
app.use(Express.static(path.resolve(__dirname, '../static')));
|
||||||
app.use(bodyParser.urlencoded({extended: true}));
|
app.use(bodyParser.urlencoded({extended: true}));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
app.use(cookieParser());
|
app.use(cookieParser());
|
||||||
app.use(session({
|
|
||||||
//this should be SECRET AND IN A SECRET FILE
|
|
||||||
//TODO add dotenv
|
|
||||||
secret: 'steve brule',
|
|
||||||
resave: true,
|
|
||||||
saveUninitialized: true,
|
|
||||||
store: new MongoStore({
|
|
||||||
// url: process.env.MONGODB_URI || process.env.MONGOLAB_URI,
|
|
||||||
url: serverConfig.mongoURL,
|
|
||||||
autoReconnect: true
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
app.use(passport.initialize());
|
app.use(passport.initialize());
|
||||||
app.use(passport.session());
|
app.use(passport.session());
|
||||||
app.use('/', users);
|
app.use('/', users);
|
||||||
|
@ -56,8 +43,6 @@ mongoose.connection.on('error', () => {
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
const passportConfig = require('./config/passport');
|
|
||||||
|
|
||||||
app.get("/", function(req, res) {
|
app.get("/", function(req, res) {
|
||||||
res.sendFile(path.resolve(__dirname + '/../index.html'));
|
res.sendFile(path.resolve(__dirname + '/../index.html'));
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
<<<<<<< HEAD
|
|
||||||
import { bindActionCreators } from 'redux'
|
import { bindActionCreators } from 'redux'
|
||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import * as UserActions from '../../redux/actions/user'
|
import * as UserActions from '../../redux/actions/user'
|
||||||
|
|
Loading…
Reference in a new issue