Warden not accessing the database (Devise)

僤鯓⒐⒋嵵緔 提交于 2019-12-13 02:11:58

问题


Rails 3.2. Hi. Currently out app has an authentication system implemented that we did and we are going to migrate to devise. I am at wits end here trying to get the devise log in to work. Somehow I have drilled down the problem to the part where Devise actually creates a user session.

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

Routes (I have changed the devise controller and literally just pasted the Devise controller code to debug it with pry):

devise_for :users, controllers: { sessions: "sessions" }

The problem here is that warden is not even hitting the database with an authenticate. It just returns nil. I checked my other, simpler application and authenticate's behavior scans the database, regardless if email/password is correct. How do I get Warden/Devise for that matter to actually do a select statement to check the database out?

(If there is anything I can paste to help you guys I'll paste it)


回答1:


In case it may help someone else: I was running into this very same problem. The source of the trouble turned out to be that I had a custom app/views/sessions/new.html.erb view that was not copied from devise.

See https://github.com/plataformatec/devise/issues/3700 for more information.




回答2:


Try look in console the authentication keys of your devise model:

(your_model).authentication_keys

If result is different respect keys you need (i.e email), just add explicity in your model:

:authentication_keys => [:email]

I resolved in this way. Hope this help

Bye



来源:https://stackoverflow.com/questions/22933966/warden-not-accessing-the-database-devise

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!