Sha256: 0c64f9f26a8bd359e7e7fc7d1ae93c4f8b16f70f62a09001c0661816042d1db9

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 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::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

2 entries across 2 versions & 1 rubygems

Version Path
shopify_app-21.0.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb
shopify_app-20.2.0 app/controllers/concerns/shopify_app/ensure_authenticated_links.rb