I am able to start a session with something along the lines of:
shop = Shop.find_by(user_id: user.id) session = ShopifyApp::SessionRepository.retrieve(shop.id) if session.valid? puts "hello" ShopifyAPI::Base.activate_session(session) end
But it redirects me to the /login page as if I'm needing to reinstall the app by entering the domain.
What is odd is, the session is started because i am able to fulfill orders, etc. but it won't let me visit any pages from controllers where they inherit the Authenticated Controller?
Do I need to manipulate the Authenticated Controller from Shopify or am I missing some extra step for starting the session?
What method and what controller is causing this, is there an extra step I'm missing?
Solved! Go to the solution
I still can't be sure why exactly this won't work but i can only assume it is because of the user login sessions and the store sessions colliding...
If i sign in with a user, and then apply the same before_action method in another controller, it will work.
After seeing it worked from my console i knew it was something with my code so i added this:
include ShopifyApp::Localization include ShopifyApp::LoginProtection # include ShopifyApp::EmbeddedApp after_action :user_shopify_session, only: [:create] protect_from_forgery with: :exception before_action :login_again_if_different_shop around_action :shopify_session, if: :shop_session ... ... ... def user_shopify_session user = User.find(current_user.id) shop = Shop.find_by(user_id: user.id) session = ShopifyAPI::Session.new(domain: shop.shopify_domain, token: shop.shopify_token, api_version: '2019-04') ShopifyAPI::Base.activate_session(session) end
It works with that. This isn't final and complete code so for anyone possibly coming along this, it will take a tiny bit more code before production use