-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth.js
26 lines (19 loc) · 652 Bytes
/
auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const auth = require('basic-auth');
// Temporary authentication/form setup for recording noises
module.exports = function(req, res, next) {
// basic credentials
let admin = {
name: 'admin',
pass: process.env.SITE_PASSWORD
}
// what user enters
let user = auth(req);
// console.log(user.name);
// If username and password don't match, don't allow user access
if (user.name !== admin.name && user.pass !== admin.pass) {
res.set('WWW-Authenticate', 'Basic realm="zach-noise-api"');
return res.status(403).send('Not allowed.');
}
// otherwise proceed to app
return next()
}