I followed this question Devise redirect after login fail and it works great, but I am getting a flash notice telling me that I need to login to continue, and the message I need is that the password or email is invalid. So I added the flash notice in the CustomFailure like this:
class CustomFailure < Devise::FailureApp
def redirect_url
root_path
end
def respond
if http_auth?
http_auth
else
flash[:error] = I18n.t(:invalid, :scope => [ :devise, :failure ])
redirect
end
end
end
and now it's showing me both messages, invalid password and unauthenticated, how can I eliminate the unauthenticated message?
Devise does not set flash[:error], but flash[:alert] when the login fails, try to set this in your application.
You could also just overwrite the method Devise::FailureApp#i18n_message and have it return the message of your choosing:
class CustomFailure < Devise::FailureApp
def redirect_url
root_path
end
def i18n_message
"Hello World" # you might go for something more elaborate here
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With