diff --git a/lib/index.js b/lib/index.js index db5fbf752..6e25387b9 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,9 +22,14 @@ module.exports = function(config_hash) { next() } else { if (!req.remoteUser) { + if (req.remoteUserError) { + var msg = "can't "+action+" restricted package, " + req.remoteUserError + } else { + var msg = "can't "+action+" restricted package without auth, did you forget 'npm set always-auth true'?" + } next(new UError({ status: 403, - msg: "can't "+action+" restricted package without auth, did you forget 'npm set always-auth true'?", + msg: msg, })) } else { next(new UError({ diff --git a/lib/middleware.js b/lib/middleware.js index 99e3e8382..22ee4ded5 100644 --- a/lib/middleware.js +++ b/lib/middleware.js @@ -44,6 +44,8 @@ module.exports.basic_auth = function basic_auth(callback) { //return _next.apply(null, arguments) // swallow error, user remains unauthorized + // set remoteUserError to indicate that user was attempting authentication + if (err) req.remoteUserError = err.msg return _next() }