diff --git a/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb b/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb new file mode 100644 index 000000000..acddeb537 --- /dev/null +++ b/app/controllers/concerns/shopify_app/ensure_authenticated_links.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module ShopifyApp + module EnsureAuthenticatedLinks + extend ActiveSupport::Concern + + included do + before_action :redirect_to_splash_page, if: :missing_expected_jwt? + end + + private + + def redirect_to_splash_page + splash_page_path = root_path(return_to: request.fullpath, shop: current_shopify_domain) + redirect_to(splash_page_path) + end + + def missing_expected_jwt? + jwt_shopify_domain.blank? + end + end +end diff --git a/test/controllers/concerns/ensure_authenticated_links_test.rb b/test/controllers/concerns/ensure_authenticated_links_test.rb new file mode 100644 index 000000000..f6f6231b2 --- /dev/null +++ b/test/controllers/concerns/ensure_authenticated_links_test.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'test_helper' + +class EnsureAuthenticatedLinksTest < ActionController::TestCase + class TurbolinksTestController < ActionController::Base + include ShopifyApp::EnsureAuthenticatedLinks + + def root + render(html: '