Shopify / shopify-frontend-template-react

MIT License
125 stars 58 forks source link

How to Fetch POST or GET API with Shopify Auth After Hooks Folder Removal #299

Open zahid-afridi opened 3 weeks ago

zahid-afridi commented 3 weeks ago

The hooks file has been removed from the repository, and I'm now unsure of the best approach to fetch POST or GET APIs while handling Shopify authentication.

Could you please provide guidance on the following:

Alternative Methods: What are the recommended practices or alternative methods for fetching APIs (both POST and GET) in the current setup? Shopify Authentication: How should we handle Shopify authentication in this new structure? Are there any updated libraries or patterns to follow? Code Examples: If possible, could you provide code examples or references for implementing these changes?

paulomarg commented 3 weeks ago

Hi, thanks for raising this! As part of moving to App Bridge 4, all hooks other than useAppBridge were removed (see App Bridge migration guide), because they're no longer necessary.

In the new version, App Bridge will automatically embed itself, so that regular fetch calls will already include the Authorization header. Similarly, to navigate to a different page you can simply use a link.

For example, see the ProductsCard after the updates - we're just using useQuery with a regular fetch, no need for anything special :)

This is a good callout that we might be missing some documentation on that, but that migration guide is probably the best resource to go from a previous version to v4. I'll track this to see what docs we can improve around this!