vuestorefront / vue-storefront-1

The open-source frontend for any eCommerce. Built with a PWA and headless approach, using a modern JS stack. We have custom integrations with Magento, commercetools, Shopware and Shopify and total coverage is just a matter of time. The API approach also allows you to merge VSF with any third-party tool like CMS, payment gateways or analytics. Newest updates: https://blog.vuestorefront.io. Always Open Source, MIT license.
https://www.vuestorefront.io
MIT License
18 stars 13 forks source link

Issue with guest quotes with TokenInHeader=true #200

Closed bloodf closed 3 years ago

bloodf commented 3 years ago

From vue-storefront created by teuma86: vuestorefront/vue-storefront#5317

Current behavior

Setting users.tokenInHeader = true on both the API and VSF instance, with Magento 2 as a backend fails to create a quote if the customer is not logged in. Thus failing to load shipping methods / payment methods. The error returned from magento is {"code":500,"result":"The consumer isn't authorized to access self."}

This appears to work fine for a logged in customer

This appears to work fine when setting users.tokenInHeader=false in both instances. (VSF AND API)

Expected behavior

Steps to reproduce the issue

have users.tokenInHeader = true, Magento backend (M2.3 and M2.4), VSF 1.12, VSF-API 1.12

Try adding to basket when not logged in Note the network calls / console logs.

Version of Vue Storefront

Can you handle fixing this bug by yourself?

Which Release Cycle state this refers to? Info for developer. (doesn't apply to Next)

Pick one option.

Environment details

Additional information

bloodf commented 3 years ago

definitely a bug

this is the fix, in core/lib/sync/task.ts

image

This prevents a headers Bearer to be set at all if token doesn't exist (guest user) Otherwise the header is set only partially Bearer {empty token} and VSF-API getToken fails