Devise: Unexpectedly unable to log in

I am using Devise 1.3.4 for authentication for the backend in my application. I have not been able to log in for a couple of days. What's happening:

  • I go to the login page / admin / sign _in
  • Login with good credentials
  • See the log in which the login is running (last_sign_in_at, current_sign_in_at and current_sign_in_ip, sign_in_count increases)
  • Session controller setup is trying to redirect me to the after_sign_in_path_for parameter that I specified in the application controller (Admin :: DashboardsController # show)
  • Then, suddenly, the page with the inscription appears again. No redirection, nothing.

I checked before_filters and it is definitely Devise autorize_admin_user! a filter that causes problems (filters before it is called, filters after they are not called). This means that even after a successful login, it does not recognize me as registered.

I understand that it is difficult to find a solution without seeing most of my code. So my first question is:

How can I debug this error? How can I track exactly where the login does not work? Should I delve into the Guardian? Could this be a session / cookie issue? How can I debug this?

All ideas appreciated!

Here is what the magazine says:

Started GET "/admin/sign_in" for 127.0.0.1 at 2011-05-20 13:49:11 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::SessionsController#new as HTML
Rendered admin/shared/_header.html.haml (3.1ms)
Rendered admin/shared/_menu.html.haml (1.7ms)
Rendered admin/sessions/new.html.haml within layouts/admin (128.7ms)
Completed 200 OK in 171ms (Views: 133.0ms | ActiveRecord: 0.0ms)


Started POST "/admin/sign_in" for 127.0.0.1 at 2011-05-20 13:49:15 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"VLjjo6W+sd7yRH3SRSNpUN3L8a+OaOgCUpJgB5VaGEM=", "admin_user"=>{"email"=>"my@email.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
  AdminUser Load (0.7ms)  SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`email` = 'admin3@gmail.com' LIMIT 1
  SQL (0.2ms)  BEGIN
  AREL (0.3ms)  UPDATE `admin_users` SET `last_sign_in_at` = '2011-05-20 11:49:15', `current_sign_in_at` = '2011-05-20 11:49:15', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 3, `updated_at` = '2011-05-20 11:49:15' WHERE `admin_users`.`id` = 33
  SQL (0.5ms)  COMMIT
Redirected to http://myapp.dev/admin
Completed 302 Found in 160ms


Started GET "/admin" for 127.0.0.1 at 2011-05-20 13:49:15 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::DashboardsController#show as HTML
Completed   in 26ms


Started GET "/admin/sign_in" for 127.0.0.1 at 2011-05-20 13:49:16 +0200
[Barista] Compiling all scripts for barista
[Barista] Compiling all coffeescripts
  Processing by Admin::SessionsController#new as HTML
Rendered admin/shared/_header.html.haml (3.5ms)
Rendered admin/shared/_menu.html.haml (2.0ms)
Rendered admin/sessions/new.html.haml within layouts/admin (134.9ms)
Completed 200 OK in 182ms (Views: 139.2ms | ActiveRecord: 0.0ms)
+5
source share
3 answers

Well, after two days of swaying, I finally found the answer.

, . , , Devise cookie , , cookie. " ", this redis-store . :

MyApp::Application.config.session_store :redis_session_store, AppConfig.redis

AppConfig.redis

{ :port => 123, :namespace => 'foo' }

, AppConfig.redis ActiveSupport::HashWithIndifferentAccess, a Hash. - - symbolize_keys! , , ActiveSupport::HashWithIndifferentAccess .

: AppConfig.redis AppConfig.redis.to_hash, . , , -, , cookie . ( - ?). - , Devise cookie .

+4

, , . : domain = > : all in "initializers/session_store.rb". .

- session_store.rb, , , , . , :

if Rails.env.production?  
  Appname::Application.config.session_store :cookie_store, {:key => '_cookie_name', :domain => :all}  
else  
  Appname::Application.config.session_store :cookie_store, :key => '_cookie_name'  
end
+5

I would start debugging at the exact place where your controller is trying to authenticate the user. He “feels” as if this could have happened wrong.

In our development-based application, this is in the controller:

before_filter :authenticate_user!
+1
source

All Articles