Shopify / shopify_app

A Rails Engine for building Shopify Apps
MIT License
1.76k stars 683 forks source link

Redirect loop after approving billing charge #1862

Closed elioncho closed 3 months ago

elioncho commented 3 months ago

Issue summary

Before opening this issue, I have:

I am using the latest version of the gem with authentication done via TokenExchange. After approving the billing charge, my app gets into an infinite loop.

routes.rb:

  root to: "home#index"
  get '/home', to: 'home#index'

home_controller.rb

class HomeController < AuthenticatedController
  def index; end
end

authenticated_controller.rb

class AuthenticatedController < ApplicationController
  include ShopifyApp::EnsureAuthenticatedLinks
  include ShopifyApp::EnsureHasSession

  before_action :set_shop_origin

  helper_method :current_shop

  def current_shop
    @current_shop ||= Shop.find_by(shopify_domain: current_shopify_domain)
  end

  def default_url_options
    { shop: @shop_origin }
  end

  private

  def set_shop_origin
    @shop_origin = current_shopify_domain
  end
end

In the image you can see the redirects. It looks like the id_token is not present.

CleanShot 2024-06-12 at 23 13 08@2x

Expected behavior

My app should show the home view.

Actual behavior

Infinite loop since id_token is not found. The ShopifyApp::EnsureAuthenticatedLinks redirects to the splash screen, which in my app is the same home controller.

elioncho commented 3 months ago

I changed the order of the include statements and it worked.

class AuthenticatedController < ApplicationController
  include ShopifyApp::EnsureHasSession
  include ShopifyApp::EnsureAuthenticatedLinks
...
..
.