Last active
December 31, 2015 18:22
-
-
Save jurre/8026307 to your computer and use it in GitHub Desktop.
After removing all the root elements from our JSON API I ran into an issue with devise expecting the `sign_in` params to be wrapped in their respective scope (`user` in our case), so: ```ruby
{ user: { email: "[email protected]", password: "whatever }
}
``` But with our new JSON API we wanted to get rid of the root element wrapping and wante…
This file contains 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
# config/initializers/devise.rb | |
Devise.setup do |config| | |
# .. snip | |
config.warden do |manager| | |
manager.default_strategies(:scope => :user).unshift :unwrapped_authenticatable | |
end | |
end |
This file contains 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
# config/initializers/unwrapped_authenticatable.rb | |
require 'devise/strategies/database_authenticatable' | |
module Devise | |
module Strategies | |
class UnwrappedAuthenticatable < DatabaseAuthenticatable | |
private | |
def params_auth_hash | |
params.slice(:email, :password) | |
end | |
end | |
end | |
end | |
Warden::Strategies.add(:unwrapped_authenticatable, Devise::Strategies::UnwrappedAuthenticatable) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment