-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable custom unauthorized handling via middleware (req, res, next) #23
Comments
matmar10
added a commit
to matmar10/express-basic-auth
that referenced
this issue
May 30, 2019
It would be great if this was released. :) |
push push |
matmar10
added a commit
to matmar10/express-basic-auth
that referenced
this issue
Aug 7, 2021
Current behavior supports: - string, rendered as text in response - object, rendered as JSON object in response This enhancement enables passing a normal middleware. It allows full customization of the response handling in the case of unauthorized: ```JavaScript app.use(basicAuth({ unauthorizedResponse: function(req, res, next) { // use an application's existing error handling stack if (req.auth) { next(new UnauthorizedError('Login required')); return; } // or send an html page if (req.accepts('html') { res.render('unauthorized'); return; } // or whatever you like! res.status(403) send({ message: 'That user will NEVER have access. Ever!' }); } })); ``` fixes LionC#23
matmar10
added a commit
to matmar10/express-basic-auth
that referenced
this issue
Aug 7, 2021
Current behavior supports: - string, rendered as text in response - object, rendered as JSON object in response This enhancement enables passing a normal middleware. It allows full customization of the response handling in the case of unauthorized: ```JavaScript app.use(basicAuth({ unauthorizedResponse: function(req, res, next) { // use an application's existing error handling stack if (req.auth) { next(new UnauthorizedError('Login required')); return; } // or send an html page if (req.accepts('html') { res.render('unauthorized'); return; } // or whatever you like! res.status(403) send({ message: 'That user will NEVER have access. Ever!' }); } })); ``` fixes LionC#23
matmar10
added a commit
to matmar10/express-basic-auth
that referenced
this issue
Aug 7, 2021
Bump? |
I will take a look at this the following week - thank you for your patience :-) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Background
Current behavior supports:
Enhancement
Enable passing a normal middleware. This allows full customization of the response handling in the case of unauthorized:
The text was updated successfully, but these errors were encountered: