everyauth
everyauth copied to clipboard
res.locals.user always undefined (express3 branch)
After updating to Express3 and using everyauth's express3 branch, the user variable in my templates was always undefined. I noticed that the middleware function to assign req.user to res.locals.user was being executed before the middleware that actually retrieved the user from the session and assigned it to req.user. Therefore, by the time it did res.locals.user = req.user, req.user would always be undefined.
So a fix to that was to re-add the middleware that assigns res.locals.user AFTER using everyauth middleware:
//Init calls..
app = express()
//Use everyauth
app.use(everyauth.middleware(app));
//And the fix:
app.use( function (req, res, next) {
res.locals[everyauth.expressHelperUserAlias || 'user'] = req.user;
next();
});
Am I the only one getting this?
Same here, +1
Same thing here... Oddly helpers like everyauth.loggedIn work fine.
I had to modify the fix above to this to work. I'm a total newbie so maybe I'm missing the obvious above, but this worked for knuckle draggers like me:
app.use( function (req, res, next) {
res.locals.everyauth.user = req.user;
res.locals.user = req.user;
next();
});
the same. I think a merge from master can fix the problem?
res.locas({user:req.user,everyauth:{user:req.user}});