diff --git a/app/controllers/console_redirect_controller.rb b/app/controllers/console_redirect_controller.rb index ba3565dc..5dd00789 100644 --- a/app/controllers/console_redirect_controller.rb +++ b/app/controllers/console_redirect_controller.rb @@ -1,11 +1,17 @@ # frozen_string_literal: true class ConsoleRedirectController < ApplicationController + skip_before_action :authenticate_user! + def index + return redirect_to(new_user_session_path({ redir: params[:redir] }.compact)) if current_user.blank? + auth = JsonWebToken.encode(uuid: current_user.uuid, scope: :console, exp: 1.minute.from_now.to_i) - redirect_to("#{Docuseal::CONSOLE_URL}?#{{ auth: }.to_query}", allow_other_host: true) + path = Addressable::URI.parse(params[:redir]).path if params[:redir].to_s.starts_with?(Docuseal::CONSOLE_URL) + + redirect_to("#{Docuseal::CONSOLE_URL}#{path}?#{{ auth: }.to_query}", allow_other_host: true) end end diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index f9579622..d6f4d9b7 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -13,6 +13,16 @@ class RegistrationsController < Devise::RegistrationsController private + def after_sign_up_path_for(...) + if params[:redir].present? + return console_redirect_index_path(redir: params[:redir]) if params[:redir].starts_with?(Docuseal::CONSOLE_URL) + + return params[:redir] + end + + super + end + def require_no_authentication super diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 28878ba5..5085d411 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -12,6 +12,16 @@ class SessionsController < Devise::SessionsController private + def after_sign_in_path_for(...) + if params[:redir].present? + return console_redirect_index_path(redir: params[:redir]) if params[:redir].starts_with?(Docuseal::CONSOLE_URL) + + return params[:redir] + end + + super + end + def require_no_authentication super diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb index 936890bc..9d69b12c 100644 --- a/app/views/devise/registrations/new.html.erb +++ b/app/views/devise/registrations/new.html.erb @@ -1,6 +1,9 @@