Hi Liam,
Sorry I’m new here, so please be patient with my noob questions: I don’t
know what you mean by “DM me on here” - I cannot find a Direct Message
button anywhere on the Shopify Community forums. So, I’m going to try
replying to this notification by clicking Reply.
Perhaps you’re not using the versions that I provided because it seems
you’re still referring to deprecated methods.
Also, you provided two code snippets but I don’t understand which one you
propose to use in production code and which one to use in my tests. You
refer to the first snippet as “test setup” but I think what you mean by
“create a session explicitly” is not to rely on the shopify_api gem to do
it. Is this correct?
Please clarify and point to the Shopify.dev docs as to where I can find
these code samples.
I do see in
shopify_app/lib/shopify_app/controller_concerns/login_protection.rb the
methods
activate_shopify_session
current_shopify_session
There’s also a private method load_current_session but I don’t think I
should use this.
I tried your suggestion, so I got:
Failures:
- account collections creating first account collection
Failure/Error:
session = ShopifyAPI::Session.new(
domain: account.shopify_domain,
token: account.shopify_token,
api_version: ‘2023-04’
)
NameError:
uninitialized constant ShopifyAPI::Session
So, I’m guessing you mean Shopify::Auth::Session
trying again:
Failures:
- account collections creating first account collection
Failure/Error:
session = ShopifyAPI::*Auth::*Session.new(
domain: account.shopify_domain,
token: account.shopify_token,
api_version: ‘2023-04’
)
ArgumentError:
missing keyword: :shop
trying again:
Failures:
- account collections creating first account collection
Failure/Error:
session = ShopifyAPI::Auth::Session.new(
shop: account.shopify_domain,
domain: account.shopify_domain,
token: account.shopify_token,
api_version: ‘2023-04’
)
ArgumentError:
unknown keywords: :domain, :token, :api_version
removing the unknown keywords:
Failures:
- account collections creating first account collection
Failure/Error: ShopifyAPI::Base.activate_session(session)
NameError:
uninitialized constant ShopifyAPI::Base
Did you mean? Base64
Removing the call to ShopifyAPI::Base.activate_session(session)
I get:
Failures:
- account collections creating first account collection
Failure/Error: expect(current_path).to eq(‘/settings’)
expected: “/settings”
got: “/login”
(compared using ==)
So, I’m. guessing I’m still not authenticated and I’m being redirected to
the /login page.
Please help.
I also tried the following:
session = ShopifyAPI::Auth::Session.new(
shop: account.shopify_domain,
scope: ShopifyApp.configuration.scope
)
allow_any_instance_of(ShopifyApp::LoginProtection).to(
receive(:current_shopify_session).and_return(session)
)
but I also get redirected to the /login page.
Thanks!