You can redefine the sign_in_and_redirect and sign_out_and_redirect devise helpers, to render json instead of redirecting the user.
I couldn't redefine them in an initializer, so the closest solution I found is adding this to application_controller.rb :
private
# Override the default devise signin/signout process
def sign_in_and_redirect(resource_or_scope, resource=nil)
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource ||= resource_or_scope
sign_in(scope, resource) unless warden.user(scope) == resource
# redirect_to stored_location_for(scope) || after_sign_in_path_for(resource)
render :json => {:status => :signed_in}
end
def sign_out_and_redirect(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
if Devise.sign_out_all_scopes
sign_out_all_scopes
else
sign_out(scope)
end
#redirect_to after_sign_out_path_for(scope)
render :json => {:status => :signed_out}
end
If anyone has a cleaner solution, I'm also interested