diff --git a/lib/security.js b/lib/security.js index 144e39b1..dc5ac2b6 100644 --- a/lib/security.js +++ b/lib/security.js @@ -39,6 +39,7 @@ var security = { }, sendCurrentUser: function(req, res, next) { res.json(200, filterUser(req.user)); + res.end(); }, login: function(req, res, next) { function authenticationFailed(err, user, info){ diff --git a/server.js b/server.js index c08e4f6d..92e04236 100644 --- a/server.js +++ b/server.js @@ -67,6 +67,16 @@ app.post('/logout', security.logout); // Retrieve the current user app.get('/current-user', security.sendCurrentUser); +// Retrieve the current user only if they are authenticated +app.get('/authenticated-user', function(req, res) { + security.authenticationRequired(req, res, function() { security.sendCurrentUser(req, res); }); +}); + +// Retrieve the current user only if they are admin +app.get('/admin-user', function(req, res) { + security.adminRequired(req, res, function() { security.sendCurrentUser(req, res); }); +}); + // This route deals enables HTML5Mode by forwarding missing files to the index.html app.all('/*', function(req, res) { // Just send the index.html for other files to support HTML5Mode