Heylo,
I'm building a (semi) REST API with Nodejs/Express as back and Phonegap/Cordova as front.
For backend i'm using express
with connect-mongo
and mongoose
as following :
express.cookieParser(),
express.session({
secret: nconf.get('session:salt'),
store: new mongoStore({url: nconf.get('database').url})
}),
for session validation on node i've create the following function inside my route.js
file
var authenticate = function (req, res, next) {
if (req.session.user)
next();
else
res.error('access is not authentication');
}
Unfortunately PhoneGap and Cordova do not support cookies out of the box so i use localStorage
to store session_id and wrap every server call to aggregate it to the url params.
Is there any elegant way to pre-load the session from mongoDB inside my authenticate
function by the 'session_id' param without creating a Schema
for the session collection and try querying it with mongoose?
Cheers,
-PK.