Sha256: 61df3d25a89ba63cf3738d3cf230e124761c014b886e2786e550287b12737ea2

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

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],
        embedded: params[:embedded],
      )
    end

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

    def base_url
      ShopifyApp.configuration.root_url.presence || root_path
    end

    def redirect_to_splash_page
      redirect_to(splash_page)
    rescue ::ShopifyApp::ShopifyDomainNotFound => error
      ShopifyApp::Logger.warn("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

11 entries across 11 versions & 1 rubygems

Version Path
shopify_app-22.5.2 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.5.1 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.5.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.4.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.3.1 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.3.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.2.1 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.2.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.1.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.0.1 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-22.00.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb