Files
roboto-promoto/lib/middleware.js
Fergal Moran d49dc8b3bf Initial Commit
2014-03-20 11:32:56 +00:00

26 lines
499 B
JavaScript

'use strict';
/**
* Custom middleware used by the application
*/
module.exports = {
/**
* Protect routes on your api from unauthenticated access
*/
auth: function auth(req, res, next) {
if (req.isAuthenticated()) return next();
res.send(401);
},
/**
* Set a cookie for angular so it knows we have an http session
*/
setUserCookie: function(req, res, next) {
if(req.user) {
res.cookie('user', JSON.stringify(req.user.userInfo));
}
next();
}
};