Closed joshbedo closed 9 years ago
What priority did you give it in config.json?
So i just solved this by changing spec.js
to include flash like this. Not sure if this is needed? but it works.
// Used for serializing and deserializing passport users
'use strict';
var express = require('express');
var passport = require('passport');
var flash = require('connect-flash');
var auth = require('../lib/auth');
var userLib = require('./user')();
var db = require('../lib/database');
var crypto = require('../lib/crypto');
module.exports = function spec(app) {
app.on('middleware:after:session', function configPassport(eventargs) {
// 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(userLib.serialize);
passport.deserializeUser(userLib.deserialize);
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());
});
return {
onconfig: function(config, next) {
var dbConfig = config.get('databaseConfig')
var cryptConfig = config.get('bcrypt');
crypto.setCryptLevel(cryptConfig.difficulty);
db.config(dbConfig);
userLib.addUsers();
next(null, config);
}
};
};
Also here is my config.json
{
"express": {
"view engine": "jsx",
"view": "require:react-engine/lib/expressView",
"views": "path:./public/js/views"
}
,"view engines": {
"jsx": {
"module": "react-engine/lib/server",
"renderer": {
"method": "create"
}
}
}
,"databaseConfig": {
"host": "localhost",
"database": "imstillreallybored"
}
,"bcrypt": {
"difficulty":8
}
// flash messaging middleware
,"flash": {
"priority": 91,
"enabled": true,
"module": {
"name": "connect-flash",
"method": "flash"
}
}
// test is user session required and if user has session
,"isAuthenticated": {
"enabled": true,
"priority": 111,
"module": {
"name":"path:./lib/auth",
"method": "isAuthenticated"
}
}
// inject user into the response object
,"injectUser": {
"enabled": true,
"priority": 112,
"module": {
"name":"path:./lib/auth",
"method":"injectUser"
}
}
,"middleware": {
"static": {
"module": {
"arguments": [ "path:./.build" ]
}
}
,"router": {
"module": {
"arguments": [{ "directory": "path:./controllers" }]
}
}
}
}
You'd have to put the flash in the middleware configuration rather than the root of the config.
Within spec.js
? or which file?
Within config.json.
Generally, kraken apps move as much middleware configuration as possible in there.
I do have flash
set within the config.json
though?
// flash messaging middleware
,"flash": {
"priority": 91,
"enabled": true,
"module": {
"name": "connect-flash",
"method": "flash"
}
}
Yeah, outside the middleware configuration section. It won't do anything where you have it.
do'h i feel really dumb now, Thanks for the help!
Sure thing! It takes a bit to get used to the json configs!
I was just going through the repo and recreating the setup for passport-local on one of my projects and when i go to my
/login
route i'm getting the message below. Inside of the cli i also getundefined
forreq.flash
. Wondering if there is anything i'm missing. I did the followingconnect-flash
to theconfig.json
connect-flash
controllers/login/index.js
At this point i've went through most of the files and can't seem to trace why the
req
object wouldn't includeflash
. Let me know if you need to see anything else specifically, Thanks!