shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

Redirects to undefined

Open theahmadzai opened this issue 3 years ago • 4 comments

Issue summary

after shopify app serve I see this Ready on http://localhost:8081 but going here redirects me to http://localhost:8081/auth?shop=undefined and then https://undefined/admin/oauth/authorize?client_id=MY_CLIENT_ID&scope=write_products%2Cwrite_customers%2Cwrite_draft_orders&redirect_uri=https%3A%2F%2Fdd8a-103-170-1731-128.ngrok.io%2Fauth%2Fcallback&state=699792444916697&grant_options%5B%5D=per-user

theahmadzai avatar Feb 13 '22 21:02 theahmadzai

@theahmadzai This will happen if you have an undefined shop name, somewhere in your server.js file there should be the following code

  router.get("(.*)", async (ctx) => {
    const shop = ctx.query.shop;

    if (ACTIVE_SHOPIFY_SHOPS[shop] === undefined) {
      ctx.redirect(`/auth?shop=${shop}`);
    } else {
      await handleRequest(ctx);
    }
  });

If for some reason you are not able to get the shop name from const shop = ctx.query.shop; and need a quick fix, you can hard code in the shopify domain and that will trigger the OAuth process

Michael-Gibbons avatar Feb 14 '22 20:02 Michael-Gibbons

Also I am unsure how you got a local host url, when I run shopify app serve I am presented with the following. The ngrok url is the one you want I think. ngrok basically creates a connection between your local host which is serving the files, and shopify which is displaying them. So its very possible the error you're seeing is because you're not actually hitting the route shown above because you don't have the correct context. Try using the ngrok url.

image

Michael-Gibbons avatar Feb 14 '22 21:02 Michael-Gibbons

Thankyou for replying, When I click on goto localhost:8081 that undefined thing happens with ngrok URL it works fine is it a normal behavior for localhost URL?

theahmadzai avatar Feb 15 '22 12:02 theahmadzai

Yes, I don't believe you are supposed to use the local host url for development. The boilerplate gets the shop name from shopify using your api credentials, then sets it in the context, then uses that context to trigger the OAuth process. By only using the local host url you're never going through shopify, which means you never get the shop name, so its never set and is undefined, causing an error in the OAuth.

Michael-Gibbons avatar Feb 15 '22 16:02 Michael-Gibbons

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

github-actions[bot] avatar Oct 22 '22 02:10 github-actions[bot]