I used this at the beginning :
var app = express.createServer(
express.cookieParser(),
express.session({ secret: 'somesecretword' })
);
Below code is a sample code to get user details with uname as the key.
I call this code from backbone model's url, by calling model.fetch().
app.get('/user/:uname/', function (req, res) {
var uname=req.params.uname;
if(!req.session.user) // check if logged in
res.send("Not Logged In");
return UserModel.find({uname : uname},function(err, user) {
if (!err) {
return res.send(user);
} else {
return res.send(err);
}
});
});
So, here I wrote the code for validating session directly in the above get method.
What if I have many such methods? Do I have to write the same thing in every method, or is there any controller in Node that does this work?
For example, show me a controller that validates for the paths "/user" , means "/user/anythinghere/" should be validated automatically or show me some other better way.