I'm trying to add a custom header to my sessions controller:
class SessionsController < Devise::SessionsController
after_filter :allow_origin_header
def create
...
sign_in(resource_name.to_s, resource)
respond_with...
end
private
def allow_origin_header
...
response.headers['some_header'] = 'some_value'
...
end
end
This works correctly when user is signed in successfully. But if not, the header isn't added. I guess that it's because of "sign_in"; it interrupts execution flow and returns custom message from Devise (email or password is invalid).
Then I've created middleware that adds my header to the response, but it's not working for me either. Looks like devise goes around all middlewares.
So, how can I add custom header for devise's response?