Skip to content

Instantly share code, notes, and snippets.

@oren
Created November 3, 2013 18:40
Show Gist options
  • Save oren/7293339 to your computer and use it in GitHub Desktop.
Save oren/7293339 to your computer and use it in GitHub Desktop.
auth
var http = require('http');
http.createServer(function (req, res) {
if (!authorized(req, res, ['admin'])) {
res.statusCode = 401;
res.end("You don't have permissions");
}
res.statusCode = 200;
res.end('Welcome back!');
}).listen(3000);
// roles is an array
function authorized(req, res, roles) {
// acces db to find user's permissions
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment