Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. var auth = require('basic-auth');
  2.  
  3. var admins = {
  4. 'admin@mail.no': { password: 'P@$$w0rd!' },
  5. };
  6.  
  7. export function authorize(req, res, next) {
  8.  
  9. var user = auth(req);
  10. if (!user || !admins[user.name] || admins[user.name].password !== user.pass) {
  11. res.set('WWW-Authenticate', 'Basic realm="example"');
  12. return res.status(401).send();
  13. }
  14. return next();
  15. };
  16. /* ...app.js
  17. import {authorize} from'./auth';
  18. var app = express();
  19. app.use(authorize);
  20. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement