SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
740 stars 386 forks source link

blank screen issue when basesites API call fails due to expired token #15771

Closed wangzixi-diablo closed 2 years ago

wangzixi-diablo commented 2 years ago

Describe the bug

When user re-open the storefront after access token expires, the basesites API call will fail due to expired access token. And blank screen will be displayed instead of the expected login page.

Tell us the version of Spartacus

To Reproduce Steps to reproduce the behavior:

  1. create a Storefront using schematics based on version 4.2.1:

ng add @spartacus/schematics@4.2.1 --baseUrl https://localhost:9002/

  1. yarn start to launch the storefront. Log in storefront as usual.

  2. close the browser, wait until the access token expires. In order to make this issue easier to reproduce, you can change the property oauth2.accessTokenValiditySeconds in local.properties of your local hybris instance to a smaller value.

  3. After the access token expires, open the browser again, access Spartacus storefront.

This time you can observe a blank screen with some error requests found in Chrome dev tools:

clipboard1

  1. the basesites API calls fails with 401:

https://localhost:9002/occ/v2/basesites?fields=baseSites(uid,defaultLanguage(isocode),urlEncodingAttributes,urlPatterns,stores(currencies(isocode),defaultCurrency(isocode),languages(isocode),defaultLanguage(isocode)),theme,defaultPreviewCatalogId,defaultPreviewCategoryCode,defaultPreviewProductCode)&lang=en&curr=USD

error message: Access token expired: ZHjV7wYfDUtWxUa5ePewZDsL-9Q

clipboard2

  1. the token revoke request fails with 401 error:

https://localhost:9002/authorizationserver/oauth/revoke

error message: Invalid access token: ZHjV7wYfDUtWxUa5ePewZDsL-9Q

clipboard3

  1. the CMS page request fails with 400 error:

https://localhost:9002/occ/v2/cms/pages?pageType=ContentPage&pageLabelOrId=%2Flogin&lang=en&curr=USD

"Base site cms doesn't exist", type: "InvalidResourceError"

clipboard4

Expected behavior

User will be redirected to log in page.

wangzixi-diablo commented 2 years ago

seems to duplicate with https://github.com/SAP/spartacus/issues/13721, I close this one, please track 13721 instead.