As pointed out in the official documentation, the simpler solution would be to simply add this to your application_controller.rb:

  class ApplicationController < ActionController::Base

  # If your model is called User
  def after_sign_in_path_for(resource)
    session["user_return_to"] || root_path

Important Note (Which I also overlooked) is that for this to work you will need to call authenticate_user! method, available by default in Devise, in your controller’s before_action:. This will call store_location_for available out of the box in Devise, and the rest is handled by the above code in the application_controller.rb, thus eliminating the need to rewrite code to save requesting url.