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

Error while trying to pull products #1

Open
ikn-n opened this issue Feb 11, 2022 · 8 comments
Open

Error while trying to pull products #1

ikn-n opened this issue Feb 11, 2022 · 8 comments

Comments

@ikn-n
Copy link

ikn-n commented Feb 11, 2022

On a local env, it runs into trouble when it tries to fetch products. It appears that it's not able to get an online session

event - compiled client and server successfully in 438 ms (1421 modules)
error - (api)/pages/api/products.js (10:53) @ __WEBPACK_DEFAULT_EXPORT__
TypeError: Cannot read properties of undefined (reading 'shop')
   8 | 
   9 |   const session = await Shopify.Utils.loadCurrentSession(req, res);
> 10 |   const client = new Shopify.Clients.Graphql(session.shop, session.accessToken);
@redochka
Copy link
Owner

Can you console.log the session

@ikn-n
Copy link
Author

ikn-n commented Feb 12, 2022

The session is undefined after line 9. I followed it to where It tries to look it up in the store, but the store has only one key for this shop, the offline__shopname_ key so it fails to "load" a session and returns undefined.

If I change line 9 to have Shopify.Utils.loadCurrentSession(req, res, false); then it works, but I want to see it working with online sessions as well

@redochka
Copy link
Owner

In pages/api/auth/[...shopify].js#5, pass 'online' instead of 'offline'

accessMode: 'offline',  //offline vs online

@ikn-n
Copy link
Author

ikn-n commented Feb 16, 2022

Thanks for that. In the example above, it only ever issues an online token, what will happen when it expires? It will try to load it from the DB, probably won't find one and will fail again. How would it handle the reissuing of new online tokens and provide an offline one for API access?

@ikn-n
Copy link
Author

ikn-n commented Feb 22, 2022

It would be great if you add support for both online and offline tokens in the same app. It's unfortunate that the current version of this app always breaks down out of the box on its first load.

Screenshot from 2022-02-22 21-28-27

@seanonthenet
Copy link

Hey guys. Thanks for this boilerplate @redochka - it's awesome and definitely much better than the shopify-cli generated one. 👊

I also have this issue of online and offline sessions. I am building a fully standalone, offline app but would be nice to also be able to deliver content with @shopify/polaris in the store -> app iframe window. Is there a way we can adapt it to have both an online and offline sessions when needed?

@TheApeMachine
Copy link

It seems the trick would be to authorise the user twice?
https://rsirokov.medium.com/shopify-app-online-and-offline-access-modes-8a8c5ecd928b
Based more on the shopify-cli version, but I'm sure it could be done somewhere here too... https://github.com/redochka/nextjs-shopify-app-no-custom-server/blob/main/lib/shopify.js

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

No branches or pull requests

5 participants
@redochka @seanonthenet @TheApeMachine @ikn-n and others