Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise users created in console cannot sign in

I am trying to turn #registerable off in devise and just register users through console and seed data however I am having an issue with sign in.

  1. I created a user via the console: User.create!(email: '[email protected]', password: 'password', username: 'username')
  2. It passes validation and gets saved to the database
  3. I cannot sign in (through the website form) with this user when I provide the email: [email protected] and password: password
  4. This is the password though, in console:

    u = User.find_by_email('[email protected]')
    
    u
     => #<User id: 6, email: "[email protected]", encrypted_password: "$2a$10$xd0PMJ.qDDu6VtFd6i2EM.bQ0h1rvODyzaqFdzo3Uo4C...", username: "user", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-09-30 01:25:16", updated_at: "2013-09-30 01:25:16">
    
    
    u.valid_password? 'password'
     => true
    

I've tried multiple users and I've tried creating it with db/seed.rb. Again, it does get into the database and everything looks fine. It just won't sign in. I've also tried adding the password_confirmation field with a matching password, no dice.

If I turn on :registerable in the user model, goto the sign up page, sign a user up, I can log in with that user (created through the form).

My only thought is that there is some kind of difference in the way the encrypted password is being generated? But that does not hold because I can run the same find_by_email/valid_password check on the web created user.

Any help would be greatly appreciated?

Edit:

I am not using Confirmable, here is my Devise attributes:

     devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatablen

Edit2 Now I can not login with my web created accounts. I need to do more debugging.

like image 565
Mike Avatar asked Dec 02 '25 21:12

Mike


1 Answers

Assuming your are using Confirmable, use the following to create the user:

User.create!(email: '[email protected]', password: 'password', username: 'username', confirmed_at: Time.now)

Otherwise, devise will wait for the user to confirm their email address which never happens

like image 58
Rajesh Kolappakam Avatar answered Dec 05 '25 09:12

Rajesh Kolappakam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!