Sha256: cfa13d6440edbbb8e61a82829a7a6e59628affb5580efda0c501f11f392c6ad8

Contents?: true

Size: 984 Bytes

Versions: 13

Compression:

Stored size: 984 Bytes

Contents

# 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 splash_page
      splash_page_with_params(
        return_to: request.fullpath,
        shop: current_shopify_domain,
        host: params[:host]
      )
    end

    def splash_page_with_params(params)
      uri = URI(root_path)
      uri.query = params.compact.to_query
      uri.to_s
    end

    def redirect_to_splash_page
      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")
      redirect_to(ShopifyApp.configuration.login_url)
    end

    def missing_expected_jwt?
      jwt_shopify_domain.blank?
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
ruby_shopify_app-1.3.3 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
ruby_shopify_app-1.3.2 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
ruby_shopify_app-1.3.1 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
ruby_shopify_app-1.3.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
ruby_shopify_app-1.2.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
ruby_shopify_app-1.1.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
ruby_shopify_app-1.0.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-18.1.3 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-18.1.2 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-18.1.1 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-18.1.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-18.0.4 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-18.0.3 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb