Why is Warden/Devise appending resource name upon sign_in authentication failure?

1.3k Views Asked by At

I've been googling around for this like crazy and no luck so far.

So far sign_in and sign_out work fine. They redirect to the right action. My problem is when sign_in fails. I get sent to what looks like a blank html page displaying "Invalid login or password." rendered by the create action or text rendered by the create action . AFAIK create should only redirect or render upon failure. I have a custom controller and the only reason I have the devise code listed here is to see where the behavior is occurring. I really only need to inherit the behavior at this point because I'm not trying to redirect to a custom path after authentication.

the log reads as follows:

Started POST "/login.user" for 127.0.0.1 at 2012-05-14 15:50:02 -0700
Processing by Users::SessionsController#create as 
Parameters: {"utf8"=>"✓",   "authenticity_token"=>"Pf2+YBqmb5+231nbuD/MeDlz6H7/qOjV4N50WnlJ0rc=", "user"=>{"login"=>"qwdwqqd", "password"=>"[FILTERED]", "remember_me"=>"0"}, "x"=>"40", "y"=>"8"}
Completed 401 Unauthorized in 32ms

Here is my controller:

Users::SessionsController < ::Devise::SessionsController

def create
  resource = warden.authenticate!(auth_options)
  set_flash_message(:notice, :signed_in) if is_navigational_format?
  sign_in(resource_name, resource)
  respond_with resource, :location => after_sign_in_path_for(resource)
end

My routes ar as follows:

devise_for :users, :controllers => {:sessions => "users/sessions", :registrations => "users/registrations"}, :path => '', :path_names => { :sign_in => 'login', :sign_out => 'logout' }
.
.
root :to => 'root#index'

I determined it is not getting past the

resource = warden.authenticate!(auth_options)

line upon authentication failure

The resource name is somehow being appended to the login path upon failure by warden it seems. e.g. /login.user instead of just /login

Any help would be appreciated, thanks in advance.

Rails 3.2, Devise 2.0.4, rack (1.4.1), ruby 1.9.3

1

There are 1 best solutions below

0
On

Just in case anyone else was still wondering. I removed the resource argument in the create_user_session form. In other words I went from this:

<%= form_for(resource, :as => resource_name, :url => user_session_path(resource)) do |f| %>

to this:

<%= form_for(resource, :as => resource_name, :url => user_session_path) do |f| %>

that did the trick. I feel pretty dumb for not looking here earlier.