From 1136ac3f16972218a8139d7c06e7e8d9e7533f25 Mon Sep 17 00:00:00 2001 From: catarak Date: Tue, 17 May 2016 15:50:37 -0400 Subject: [PATCH] add a lot of server side libraries, preemptively, still hooking everything up --- package.json | 1 - server/config/passport.js | 24 ------------------------ server/routes/user.routes.js | 2 +- server/server.js | 17 ++++++++++++++++- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 49b3768b..73d34e6b 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,6 @@ "mongoose": "^4.4.16", "passport": "^0.3.2", "passport-github": "^1.1.0", - "passport-jwt": "^2.0.0", "passport-local": "^1.0.0", "react": "^15.0.2", "react-dom": "^15.0.2", diff --git a/server/config/passport.js b/server/config/passport.js index 7ebf173d..fe6c7c2f 100644 --- a/server/config/passport.js +++ b/server/config/passport.js @@ -1,17 +1,9 @@ const passport = require('passport'); -const JwtStrategy = require('passport-jwt').Strategy; -const ExtractJwt = require('passport-jwt').ExtractJwt; const GitHubStrategy = require('passport-github').Strategy; const LocalStrategy = require('passport-local').Strategy; const User = require('../models/user'); -// Setup options for JWT Strategy -const jwtOptions = { - jwtFromRequest: ExtractJwt.fromHeader('authorization'), - secretOrKey: "steve brule" -}; - passport.serializeUser((user, done) => { done(null, user.id); }); @@ -39,22 +31,6 @@ 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. */ diff --git a/server/routes/user.routes.js b/server/routes/user.routes.js index 761b0e04..cbc1c7d5 100644 --- a/server/routes/user.routes.js +++ b/server/routes/user.routes.js @@ -6,4 +6,4 @@ router.route('/signup').get(UserController.newUser); router.route('/signup').post(UserController.createUser); -export default router; \ No newline at end of file +export default router; diff --git a/server/server.js b/server/server.js index ffd60eea..fc2600bf 100644 --- a/server/server.js +++ b/server/server.js @@ -24,11 +24,24 @@ import serverConfig from './config'; import users from './routes/user.routes'; //Body parser, cookie parser, sessions, serve public assets +const MongoStore = require('connect-mongo')(session); + app.use(Express.static(path.resolve(__dirname, '../static'))); app.use(bodyParser.urlencoded({extended: true})); app.use(bodyParser.json()); app.use(cookieParser()); -app.use(session({secret: 'steve brule'})); +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.session()); app.use('/', users); @@ -43,6 +56,8 @@ mongoose.connection.on('error', () => { process.exit(1); }); +const passportConfig = require('./config/passport'); + app.get("/", function(req, res) { res.sendFile(path.resolve(__dirname + '/../index.html')); })