Every time I log in, I get the error msg that the email/password is invalid.
routes:
devise_for :users
devise_scope :users do
get '/users/sign_out' => 'devise/sessions#destroy', :as => :destroy_user_session
post '/users/sign_in' => 'devise/sessions#create', :as => :user_session
end
resources :users
user model:
devise :database_authenticatable, :confirmable, :recoverable, :rememberable, :trackable
attr_accessor :password
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :gender, :remember_me
view:
<% if signed_in?(:user) %>
Hi <%= current_user.first_name %>. | Not you? <%= link_to 'Sign out', destroy_user_session_path, :method => :delete %>
<% else %>
<%= link_to 'Sign up', signup_path %> or <%= link_to 'Sign in', user_session_path, :method => :create %>
<% end %>
I tried changing the routes to:
get '/users/sign_in' => 'devise/sessions#new', :as => :new_user_session
and changing the respective paths, but that didn't change anything.
I even changed the code in the view from:
if signed_in?(:user)
to:
if user_signed_in?
and did a combination of these things and nothing is working.
I did ask devise to handle the confirmation as well, which I did by copying the generated link to the browser and it signs me in as the user the first time. It also allows me to change the password via the email confirmation link, which also signs me in upon changing the password. But once I sign out and sign back in, it tells me that the email/password is invalid again.
Can anyone help?
I am using rails 3.0.7, devise 1.4.5, capybara 1.1.1, cucumber 1.0.6, mysql2 0.2.6 and rake 0.8.7 if that helps anyone.
Thanks
EDIT:
To help future users, there is actually nothing wrong with the gem. It works fine. The issue is with my database. For some reason, it is selecting a NULL email from the database instead of pulling the info of the user I am trying to log in. I am figuring out how to fix this now and will update once I figure it out.
I have been having a similar issue on a fresh install of Devise, but what I found is that if I ran bundle update
then restarted my dev server it works.
At first I wasn't seeing the DB query in the development.log
, but once I updated my Gemfile
(to make sure I am using the latest Devise gem) and restarted the server I now see the db queries in my logfile and it works (magically).
Hope that helps.
Btw, not sure if this will help you...but these are the routes in my Routes.rb
devise_for :users, :path_names => { :sign_up => "register",
:sign_in => "login",
:sign_out => "logout",
:settings => "settings" }
devise_scope :user do
get "login", :to => "devise/sessions#new"
get "register", :to => "devise/registrations#new"
get "settings", :to => "devise/registrations#edit"
get "logout", :to => "devise/sessions#destroy"
end
I ran into this issue when I had both
config.authentication_keys = [ :username ]
and
config.authentication_keys = [ :email ]
enabled simultaneously in config/initializers/devise.rb.
Upon removing the duplicate setting, authentication was successful.
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