Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var basicAuth = require('basic-auth');
- var auth = function (req, res, next) {
- function unauthorized(res) {
- res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
- return res.send(401);
- };
- var user = basicAuth(req);
- if (!user || !user.name || !user.pass) {
- return unauthorized(res);
- };
- if (user.name === 'foo' && user.pass === 'bar') {
- return next();
- } else {
- return unauthorized(res);
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement