diff --git a/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb b/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb index 26cf32e16..4eb87ff8f 100644 --- a/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb +++ b/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb @@ -10,9 +10,26 @@ module EnsureAuthenticatedLinks private + def splash_page + splash_page_with_params(shop: current_shopify_domain, host: params[:host]) + end + + def base_splash_page + root_path(return_to: request.fullpath) + end + + def splash_page_with_params(params) + uri = URI(base_splash_page) + uri.query = CGI.parse(uri.query.to_s) + .symbolize_keys + .transform_values { |v| v.one? ? v.first : v } + .merge(params) + .to_query + uri.to_s + end + def redirect_to_splash_page - splash_page_path = root_path(return_to: request.fullpath, shop: current_shopify_domain) - redirect_to(splash_page_path) + redirect_to(splash_page) rescue ShopifyApp::LoginProtection::ShopifyDomainNotFound => error Rails.logger.warn("[ShopifyApp::EnsureAuthenticatedLinks] Redirecting to login: [#{error.class}] "\ "Could not determine current shop domain") diff --git a/test/controllers/concerns/ensure_authenticated_links_test.rb b/test/controllers/concerns/ensure_authenticated_links_test.rb index 25cd9ad2a..d7a7bb1c7 100644 --- a/test/controllers/concerns/ensure_authenticated_links_test.rb +++ b/test/controllers/concerns/ensure_authenticated_links_test.rb @@ -36,10 +36,10 @@ def current_shopify_domain end end - test 'redirects to splash page with a return_to and shop param if no session token is present' do - get :some_link, params: { shop: @shop_domain } + test 'redirects to splash page with a return_to, shop and host params if no session token is present' do + get :some_link, params: { shop: @shop_domain, host: 'test-host' } - expected_path = root_path(return_to: request.fullpath, shop: @shop_domain) + expected_path = "/?host=test-host&return_to=#{CGI.escape(request.fullpath)}&shop=#{@shop_domain}" assert_redirected_to expected_path end