Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var auth = require('basic-auth');
- var admins = {
- 'admin@mail.no': { password: 'P@$$w0rd!' },
- };
- export function authorize(req, res, next) {
- var user = auth(req);
- if (!user || !admins[user.name] || admins[user.name].password !== user.pass) {
- res.set('WWW-Authenticate', 'Basic realm="example"');
- return res.status(401).send();
- }
- return next();
- };
- /* ...app.js
- import {authorize} from'./auth';
- var app = express();
- app.use(authorize);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement