plataformatec/devise — Issue #1682: impossible to access cookie in custom failure app
Author: JohnMerlino1
Created: 2012-02-27 19:38:03+00:00
State: open

I'm trying to access a cookie in custom failure app, because when the user enters the wrong password, I want to delete a cookie called tracker_for_external_clients. However, when you add a class in lib directory, there's no way to access the cookie hash. So I tried adding a class method to CustomFailureApp:

class CustomFailureApp < Devise::FailureApp
class << self
attr_accessor :cookie
end

and tried adding this to application controller:

def initialize
CustomFailureApp.cookie cookies
super
end

So that I could then modify the cookie in CustomFailureApp:

def respond
unless request.format.to_sym == :html
http_auth
else
store_location!
flash[:alert] = i18n_message

if request.subdomain == 'abc' && i18n_message.includes?('Invalid login or password')
CustomFailureApp.cookie.delete :tracker_for_external_clients
uri = URI('http://abc.com/?page_id=425')
params = { 'message' => i18n_message }
uri.query = URI.encode_www_form(params)

res = Net::HTTP.get_response(uri)

if res.is_a?(Net::HTTPSuccess)
Rails.logger.info "The response is #{res.body}"
else
Rails.logger.info "Something went wrong"
end

redirect_to redirect_url
end
end

But I get this error:
undefined method `cookie_jar' for nil:NilClass

I need to be able to delete the cookie after devise has determined the user has entered the wrong password, so that i could kill the proxy i am using between two servers.

thanks for response