Node.js – How to get express-basic-auth to prompt a popup for user and password

basic-authenticationexpressnode.js

I have a node.js app that used to work when basicAuth was a module of node. Below code would popup a password and username prompt when visiting app.

// start the UI
var app = express();
app.use(express.basicAuth('me', 'openforme'));
app.use(kue.app);
app.listen(3001);

Now that basicAuth was removed as a module, from node, I am using express-basic-auth. When using the below code I get a 401 unauthorized error because it is not giving me a username and password popup prompt like basicAuth did?

// start the UI
var app = express();
var basicAuth = require('express-basic-auth');
app.use(basicAuth({
    users: { 'me': 'openforme' }
}));
app.use(kue.app);
app.listen(3001);

Best Answer

Now there is an out-of-the-box option from express-basic-auth. The Challenge property.

app.use(basicAuth({
    challenge: true,
    users: { 'me': 'openforme' }
}));
Related Topic