Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuring the script tags is causing errors #1128

Closed
yehiasalam opened this issue Dec 21, 2020 · 7 comments · Fixed by #1151
Closed

Configuring the script tags is causing errors #1128

yehiasalam opened this issue Dec 21, 2020 · 7 comments · Fixed by #1151
Assignees

Comments

@yehiasalam
Copy link

Hi,

I ran my custom app using the shopify-cli and shopify_app, and everything was working fine. I'm trying right now to add an external js file to the frontstore, using the config.scripttags as instructed in the docs:

ShopifyApp.configure do |config|
  config.application_name = "My Shopify App"
  config.api_key = ENV.fetch('SHOPIFY_API_KEY', '').presence || raise('Missing SHOPIFY_API_KEY')
  config.secret = ENV.fetch('SHOPIFY_API_SECRET', '').presence || raise('Missing SHOPIFY_API_SECRET')
  config.old_secret = ""
  config.scope = "write_script_tags" # Consult this page for more scope options:
                                 # https://help.shopify.com/en/api/getting-started/authentication/oauth/scopes
  config.embedded_app = true
  config.after_authenticate_job = false
  config.api_version = "2020-10"
  config.shop_session_repository = 'Shop'
  config.allow_jwt_authentication = true
  config.allow_cookie_authentication = false

  config.scripttags = [
    {event:'onload', src: 'https://x.x.com/widget/widget.js'}
  ]

end

However, whenever I install the app i keep getting the following error, and this happens after adding:

  config.scripttags = [
    {event:'onload', src: 'https://x.x.com/widget/widget.js'}
  ]

Screenshot 2020-12-21 235958

Not sure what might the problem might be. It shouldn't be related to Auth i guess since it was working fine before adding the scripttags config.

@paulomarg
Copy link
Contributor

Hey @yehiasalam, thank you for reporting this. We'll look into it!

@tanema
Copy link
Contributor

tanema commented Jan 5, 2021

Does this happen in all browsers? Was authentication seemingly successful before this error?

@m0n9oose
Copy link

m0n9oose commented Jan 12, 2021

Just got pretty much the same exception:

Screenshot 2021-01-12 at 13 35 48

I'm using JWT authentication (in process of migration from OAuth), Rails 6.1, shopify_app 16.1.0.

We use webhooks setting, but not scripttags. Problem happened when I uninstalled my dev app and tried to install it again.

Here's my initialiser:

ShopifyApp.configure do |config|
  config.application_name = 'App name'
  config.api_key = ENV['SHOPIFY_CLIENT_API_KEY'].presence || Rails.application.credentials.shopify_client_api_key
  config.secret = ENV['SHOPIFY_CLIENT_API_SECRET'].presence || Rails.application.credentials.shopify_client_api_secret
  config.scope = 'read_themes, write_themes, read_products, write_products, read_content, write_content'
  config.embedded_app = true
  config.shop_session_repository = Shop
  config.api_version = '2020-01'
  config.allow_jwt_authentication = true
  config.allow_cookie_authentication = false

  config.webhooks = [
    { format: 'json', topic: 'app/uninstalled', address: "https://#{ ENV['SHOPIFY_DOMAIN'].presence || Rails.application.secrets.domain }/uninstall" },
  ]
end

@yehiasalam
Copy link
Author

@tanema Hi Tim, yes i check on Chrome/Firefox/Edge, authentication was happening successfully right before I added the script tag.

@anquinn
Copy link

anquinn commented Jan 18, 2021

I'm having the same issue when trying to add webhooks to the initializer. Referenced in #1145.

@resistorsoftware
Copy link

resistorsoftware commented Jan 19, 2021

I am having this same issue. Rails 6.0.3.4, Shopify App 17.0.1

NoMethodError (undefined method `token' for nil:NilClass):
shopify_app (17.0.1) app/controllers/shopify_app/callback_controller.rb:135:in `install_webhooks'
shopify_app (17.0.1) app/controllers/shopify_app/callback_controller.rb:54:in `perform_post_authenticate_jobs'
shopify_app (17.0.1) app/controllers/shopify_app/callback_controller.rb:17:in `callback'

Error in code block:

  WebhooksManager.queue(
    shop_name,
    shop_session&.token || user_session.token,
    ShopifyApp.configuration.webhooks
  )

@resistorsoftware
Copy link

Seems pretty clear this has to do with JWT and oAuth. The JWT Shopify domain object is nil all the time coming from no value at request.env['jwt.shopify_domain']

So what's up with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants