Devise - remember me not working? LocalHost Issue?

后端 未结 4 723
青春惊慌失措
青春惊慌失措 2020-12-17 22:11

I\'m using devise with my rails 3 app. For some reason the sign in with Remember Me is not working.

Could this be due to testing on localhost:3000 ?

in devis

相关标签:
4条回答
  • 2020-12-17 22:52

    Do you have the sessions set aswell with config.timeout_in = 10.minutes?

    If so see this contribution on stackoverflow which solves it solution

    0 讨论(0)
  • 2020-12-17 22:56

    The Devise remember_user_token cookie could be set to 'secure only', in which case it doesn't work with the development rails server on http (browser never sends it back to the server).

    Check initializers/devise.rb for rememberable_options = {:secure => true}

    0 讨论(0)
  • 2020-12-17 23:00

    This happens because remember_me comes in params as "on", but is compared to Devise::TRUE_VALUES, which are [true, 1, '1', 't', 'T', 'true', 'TRUE'].

    The easiest way is to make it work is to insure your remember_me comes as one of that values. Example of check-box(notice value="1"):

    <input type="checkbox" name="user[remember_me]" value="1" checked="checked" />
    

    Another way if you want to make it work with "on" value you can add "on" to Devise::TRUE_VALUES. So in your config/initializers/devise.rb just add as the first line:

    Devise::TRUE_VALUES << ["on"]
    
    0 讨论(0)
  • 2020-12-17 23:06

    My problem with this was this single line in User.rb (I updated from Michael Hartl login mechanism to devise)

    before_save :create_remember_token
    

    I commented it out and it worked.

    I also have :

    User.rb

    class User < ActiveRecord::Base
      # Include default devise modules. Others available are:
      # :token_authenticatable, :confirmable,
      # :lockable, :timeoutable and :omniauthable
      devise :database_authenticatable, :registerable,:token_authenticatable,
             :recoverable, :rememberable, :trackable, :validatable
    

    On devise.rb, I only added Devise::TRUE_VALUES << ["on"] and uncommented config.remember_for = 2.weeks

    0 讨论(0)
提交回复
热议问题