javascript - Express 4 HTTP requests: user._id undefined -
i'm writing simple express app handle image uploads , searches. upload works fine same req.user._id invalid in request. idea why?
//standard express-generator server.js requires //passport.js implementation var session = require('express-session'); app.use(session({ secret: '*****', proxy: true, resave: true, saveuninitialized: true }));
the post function works fine using multer middleware. uses req.user._id no issues - i've checked it's being uploaded database.
app.post('/upload/photodata', upload.single('photo'), function(req, res) { //retrieve data request using multer middleware objects var title = req.body.title; var description = req.body.description; var photourl = req.file.filename; var date = new date(); var user_id = req.user._id; //code create mongoose photo model instance using variables above , save });
immediately after i'm testing function returns following error: typeerror: cannot read property '_id' of undefined
app.get('/file/newcalendar', function(req, res) { var selecteddate = moment(req.query.m)//moment(req.query.m); var selectedmonth = selecteddate.month()//selecteddate.month(); var user_idlookup = req.query.v; if(!user_idlookup){ user_idlookup = req.user._id; }; jsontest = { 'selecteddate': selecteddate, 'selectedmonth': selectedmonth, 'user': user_idlookup }; })
well feel stupid now. req.user not defined because manually submitting request before signing in/serializing user!
Comments
Post a Comment