var JwtStrategy = require('passport-jwt').Strategy;
var ExtractJwt = require('passport-jwt').ExtractJwt;

// load up the user model
var User = require('../models/user');
var config = require('../config/database'); // get db config file

var FacebookStrategy = require('passport-facebook').Strategy;

module.exports = function(passport) {
    var opts = {};
    opts.jwtFromRequest = ExtractJwt.fromAuthHeaderWithScheme("jwt");
    opts.secretOrKey = config.secret;

    passport.use(new JwtStrategy(opts, function(jwt_payload, done) {

        User.findOne({id: jwt_payload.id, username: jwt_payload.username}, function(err, user) {
            if (err) {
                return done(err, false);
            }
            if (user) {
                console.log('jwt_payloadddd : ' + JSON.stringify(jwt_payload));

                console.log('useruseruser : ' + JSON.stringify(user));
                done(null, user);
            } else {
                done(null, false);
            }
        });
    }));
};
