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

User is being logged out after config.queues.maxNetworkTaskAttempts successful refreshToken requests #229

Closed bloodf closed 3 years ago

bloodf commented 3 years ago

From vue-storefront created by xkekli: vuestorefront/vue-storefront#5713

Current behavior

We have connected vuestorefront with a backend that has a small accessToken lifetime(e.g. 5 minutes. The small accessToken lifetime does not affect the situation but makes easier for the bug to be shown). In the configuration config.queues.maxNetworkTaskAttempts has the value of 1. This leads to the following scenario:

After 5 minutes a successful refreshToken is being made(after a 401 request). After 10 minutes and after getting a 401, user is being logged out. This happens because in core/lib/sync/task.ts: if (rootStore.state.userTokenInvalidateAttemptsCount >= config.queues.maxNetworkTaskAttempts) { ... rootStore.dispatch('user/logout', { silent: true }) .... }

Expected behavior

As I understand, config.queues.maxNetworkTaskAttempts is used for limiting how many consecutive times vsf will try to refresh the token. I think that on the first successful(e.g request with response code 200) request, after refreshing the token, userTokenInvalidateAttemptsCount must be set to 0 again.

Version of Vue Storefront