Skip to content

Instantly share code, notes, and snippets.

@jurre
Last active December 31, 2015 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jurre/8026307 to your computer and use it in GitHub Desktop.
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: "whatever@whatever.com", password: "whatever } } ``` But with our new JSON API we wanted to get rid of the root element wrapping and wante…
# config/initializers/devise.rb
Devise.setup do |config|
# .. snip
config.warden do |manager|
manager.default_strategies(:scope => :user).unshift :unwrapped_authenticatable
end
end
# 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