Devise does not currently handle JSON responses - see the issue on github . Therefore, you will need to create a custom session_controller to handle your response. Take a look at the implementation on github to get an idea. I put together some rough pseudo codes that hopefully get you started:
class Users::SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message :notice, :signed_in
sign_in(resource_name, resource)
respond_to do |format|
format.json { render :json => hash_of_things_to_return.to_json }
end
end
end
Then in the routes.rb file you will need to specify a new controller - devise_for :users, :controllers => { :sessions => "users/sessions" }
Hope this helps!
source
share