LionC / express-basic-auth

Plug & play basic auth middleware for express
328 stars 57 forks source link

Modify the response #9

Closed apopescu-im closed 6 years ago

apopescu-im commented 6 years ago

Is there a way to modify the response (headers particularly) beyond just setting a custom body?

LionC commented 6 years ago

Sadly, only the response body is modifiable right now - but this is definitely something that I want to implement, although it will probably be a breaking change if done properly.

I will close the issue as the question is answered, but if you have ideas on how to implement it or how you would expect it to work, please post them!

apopescu-im commented 6 years ago

I think it would be ideal if unauthorizedResponse received the response object as its second parameter. If it returned a response object it would be sent out as is, if it returns a string then the current mechanism would create the response, treating the returned string as the body. This would enable both small modifications (eg. add a header) to the default response, or completely crafting a custom one.