Last active
February 21, 2024 14:55
-
-
Save scharfie/15174b535af12fae058b to your computer and use it in GitHub Desktop.
Autologin in development strategy for devise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference(s): | |
# - http://kyan.com/blog/2013/10/11/devise-authentication-strategies | |
# - https://github.com/plataformatec/devise/blob/master/lib/devise/strategies/database_authenticatable.rb | |
module Devise | |
module Strategies | |
class Autologin < Authenticatable | |
def authenticate! | |
user = User.first | |
user ? success!(user) : fail!("No administrator account available") | |
end | |
def valid? | |
Rails.env.development? | |
end | |
end | |
end | |
end | |
# config/initializers/devise.rb | |
Devise.setup do |config| | |
# ... | |
config.warden do |manager| | |
manager.strategies.add(:autologin, Devise::Strategies::Autologin) | |
manager.default_strategies(:scope => :user).unshift :autologin | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment