vuestorefront / shopware-pwa

Shopware PWA for eCommerce. Headless storefront solution for Shopware 6, which communicates through the SalesChannel-API. Always Open Source, MIT license. Made with :blue_heart: by shopware AG & Vue Storefront.
https://frontends.shopware.com
MIT License
345 stars 103 forks source link

[Bug] misleading 403 error is thrown on initial pageload on every Route #1858

Closed LouisEiermann closed 1 week ago

LouisEiermann commented 2 years ago

What happened?

api-client.js calls refreshUser() method when initially loading the page or switching tabs. This seems to happen on every route.

https://github.com/vuestorefront/shopware-pwa/blob/master/packages/nuxt-module/plugins/api-client.js#L120

That leads to a 403 response in the console. The error message says "Customer is not logged in." which may be misleading. For example: it happens even when a new user that opens the page for the first time can not possibly be logged in.

Steps To Reproduce

Open the front page for the first time or reload it, open the console and look for a /store-api/account/customer request 403

Is there an existing issue for this?

Version

Latest stable (generated by CLI)

Which element is affected?

plugins, nuxt-module

Environment

should be in all environments

Relevant log output

errors  [ {…} ]
0   Object { status: "403", code: "CHECKOUT__CUSTOMER_NOT_LOGGED_IN", title: "Forbidden", … }
status  "403"
code    "CHECKOUT__CUSTOMER_NOT_LOGGED_IN"
title   "Forbidden"
detail  "Customer is not logged in."
meta    Object { parameters: [] }
niklaswolf commented 2 years ago

To add to this: Right now the PWA doesn't have any other way to detect if the customer/user is logged in, so this API call is done every time. If there was something to detect if the user is logged in beforehand (e.g. a seperate cookie), the API call could only be done when necessary (= customer is logged in). This would accumulated save tons of API requests, expecially on sites with bigger traffic numbers and therefore relieve the load on the shopware backend.

LouisEiermann commented 2 years ago

@elkmod is there possibly any news on this issue?