diff --git a/app/controllers/passwordless/sessions_controller.rb b/app/controllers/passwordless/sessions_controller.rb index 60ce042..c5c728c 100644 --- a/app/controllers/passwordless/sessions_controller.rb +++ b/app/controllers/passwordless/sessions_controller.rb @@ -14,6 +14,9 @@ class SessionsController < Passwordless.config.parent_controller.constantize # renders sessions/new.html.erb. def new @session = Session.new + unless params[:redirect_to].nil? + save_passwordless_redirect_location! authenticatable_class, params[:redirect_to] + end end # post '/:resource/sign_in' diff --git a/lib/passwordless/controller_helpers.rb b/lib/passwordless/controller_helpers.rb index 71a50d0..7c0e600 100644 --- a/lib/passwordless/controller_helpers.rb +++ b/lib/passwordless/controller_helpers.rb @@ -87,9 +87,11 @@ def sign_out(authenticatable_class) # Saves request.original_url as the redirect location for a # passwordless Model. # @param (see #authenticate_by_session) + # @param url [String] the url to redirect to # @return [String] the redirect url that was just saved. - def save_passwordless_redirect_location!(authenticatable_class) - session[redirect_session_key(authenticatable_class)] = request.original_url + def save_passwordless_redirect_location!(authenticatable_class, url=nil) + url = request.original_url if url.nil? + session[redirect_session_key(authenticatable_class)] = url end # Resets the redirect_location to root_path by deleting the redirect_url