I\'m trying to add Authentication via json in my project using devise configuration :token_authenticatable.
I have the working sessions_controller#create code which was
You want your SessionsController#create
method to look something like this:
class Users::SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(scope: resource_name, recall: "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_to do |format|
format.html do
respond_with resource, location: redirect_location(resource_name, resource)
end
format.json do
render json: { response: 'ok', auth_token: current_user.authentication_token }.to_json, status: :ok
end
end
end
end
...and make sure you've configured devise to use the token authentication key your clients will pass along.