问题
I am trying to use devise for user authentication of my website. It uses an existing User table.
The table has username and password, however when I try to log in, I get the following error:
Completed 401 Unauthorized in 90ms.
Logs:
Started POST "/users/sign_in" for 127.0.0.1 at 2013-06-06 15:50:01 +0530
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"+uKE28LrkWW71EHeasDSDCENQogAGODfBc3ZJJLyi9U=", "user"=>{"email"=>"admin@abc.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'admin@abc.com' LIMIT 1
Completed 401 Unauthorized in 90ms
Processing by Devise::SessionsController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"+uKE28LrkWW71EHeasDSDCENQogAGODfBc3ZJJLyi9U=", "user"=>{"email"=>"admin@abc.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}
回答1:
Its solved! I changed the encryption key of the rails project in configs/initializers/devise.rb.
Rails version: 3.2.13 Devise version: 2.04
回答2:
I just had this exact problem but only in production (using rails 4 and devise 3).
The solution was to add a domain declaration to the config/initializers/session_store.rb file like this:
YourAppName::Application.config.session_store :cookie_store, key: '_your_session', domain: {
production: 'prpoduction_domain',
development: 'development_domain'
}.fetch(Rails.env.to_sym, :all)
Though it is important that this was changed initially due to adding sub-domains to the application.
来源:https://stackoverflow.com/questions/16960041/devise-with-existing-database-401-unauthorized-using-valid-password