-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
Hi,
I followed your tutorial, but somehow when i try to login with the correct data my node.js server stops and i get the following error:
Error: passport.initialize() middleware not in use
at IncomingMessage.req.login.req.logIn (/Users/db/Documents/Projects/osm/node_modules/passport/lib/http/request.js:44:34)
at Strategy.strategy.success (/Users/db/Documents/Projects/osm/node_modules/passport/lib/middleware/authenticate.js:228:13)
at verified (/Users/db/Documents/Projects/osm/node_modules/passport-local/lib/strategy.js:83:10)
at Promise. (/Users/db/Documents/Projects/osm/lib/auth.js:29:13)
at Promise. (/Users/db/Documents/Projects/osm/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
at Promise.emit (events.js:95:17)
at Promise.emit (/Users/db/Documents/Projects/osm/node_modules/mongoose/node_modules/mpromise/lib/promise.js:84:38)
at Promise.fulfill (/Users/db/Documents/Projects/osm/node_modules/mongoose/node_modules/mpromise/lib/promise.js:97:20)
at /Users/db/Documents/Projects/osm/node_modules/mongoose/lib/query.js:1400:13
at model.Document.init (/Users/db/Documents/Projects/osm/node_modules/mongoose/lib/document.js:254:11)
npm ERR! osm@0.1.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the osm@0.1.0 start script.
npm ERR! This is most likely a problem with the osm package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node server.js
npm ERR! You can get their info via:
npm ERR! npm owner ls osm
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 13.4.0
npm ERR! command "node" "/usr/local/bin/npm" "start"
npm ERR! cwd /Users/db/Documents/Projects/osm
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/db/Documents/Projects/osm/npm-debug.log
npm ERR! not ok code 0
I searched the web and found that it must be an error in my ./index.js but i can't figure out what it is :/
Here is my index.js file:
'use strict';
var express = require('express');
var kraken = require('kraken-js');
var db = require('./lib/database');
var passport = require('passport');
var auth = require('./lib/auth');
var flash = require('connect-flash');
var User = require('./models/user');
var options, app;
/*
* Create and configure application. Also exports application instance for use by tests.
* See https://github.com/krakenjs/kraken-js#options for additional configuration options.
*/
options = {
onconfig: function (config, next) {
/*
* Add any additional config setup or overrides here. `config` is an initialized
* `confit` (https://github.com/krakenjs/confit/) configuration object.
*/
//Setup connection to Mongodb
db.config(config.get('databaseConfig'));
//Tell passport to use our newly created local strategy for authentication
passport.use(auth.localStrategy());
//Give passport a way to serialize and deserialize a user. In this case, by the user's id.
passport.serializeUser(function (user, done) {
done(null, user.id);
});
passport.deserializeUser(function (id, done) {
User.findOne({_id: id}, function (err, user) {
done(null, user);
});
});
//Add two users to the system.
var u1 = new User({
name: 'Kraken McSquid',
login: 'kraken',
password: 'releaseMe',
role: 'admin'
});
var u2 = new User({
name: 'Ash Williams',
login: 'awilliams',
password: 'boomstick',
role: 'user'
});
//Ignore errors. In this case, the errors will be for duplicate keys as we run this app more than once.
u1.save();
u2.save();
next(null, config);
}
};
app = module.exports = express();
app.use(kraken(options));
app.requestBeforeRoute = function requestBeforeRoute(server) {
// Run before any routes have been added.
server.use(passport.initialize());
server.use(passport.session());
server.use(flash());
server.use(auth.injectUser);
};
app.on('start', function () {
console.log('Application ready to serve requests.');
console.log('Environment: %s', app.kraken.get('env:env'));
});
I'm new to the node.js.
I hope you can help me :)
Metadata
Metadata
Assignees
Labels
No labels