I currently have a middleware method setup on certain routes to make sure the user is allowed to modify a specific document. I's using it in conjunction with angular $resource.
exports.hasAuthority = function hasAuthorization(req, res, next) {
if (req.body.creator.toString() !== req.user._id.toString()) {
return res.send(403);
}
next();
};
The above has been working so far when the document is on the request body so i can just grab the creator id and check if it matches.
The problem is the DELETE
method in the Angular $resource
does not post the object to the request body so creator is undefined
. I've done some searching and came across angular $resource delete won't send body
There is a solution to override this behavior but it seems like it should be left as it is.
I have been looking at this example angular-passport and scratching my head as to how he has managed to get req.blog
populated with the blog data which is then used by all methods to modify the data on the server.
I thought maybe in the middleware I could do a quick findOne
query with an id
passed in on the query string and checking it against the creator that way but wasn't sure if this is bad practice..
Any ideas?
Thanks, James