Skip to content

Active cart is not reloaded upon changing the language when the authorization code flow is used #19269

Open
@relsayed8205

Description

@relsayed8205

Description
Active cart is not reloaded upon changing the language when the authorization code flow is used (keycloak integration)

Version

  • Library version: [22.11.19.0]
  • Integrated with keycloak latest version by having a new AuthConfig

ConfigModule.withConfig(<AuthConfig>{ authentication: { client_id: eto client_secret: '', loginUrl: 'auth', tokenEndpoint: 'token', userinfoEndpoint: 'userinfo', revokeEndpoint: 'revoke', logoutUrl: 'logout', baseUrl: 'http://localhost:8080/realms/eto/protocol/openid-connect', OAuthLibConfig: { responseType: 'code', scope: 'openid', postLogoutRedirectUri: 'https://localhost:4200', redirectUri: 'https://localhost:4200', issuer: 'http://localhost:8080/realms/eto', disablePKCE: false, strictDiscoveryDocumentValidation: true, skipIssuerCheck: false, } } }),

To Reproduce
Steps to reproduce the behavior:

  1. Call the shop, it is an open shop.
  2. Click login, it redirects to keycloak login page and returns to the shop home page after success
  3. The user has an active cart e.g. 3 items
  4. Logout, and login again
  5. On the home page, change the language using the standard language selector

The mini cart show 0 items. Open the cart page, it is empty. Active cart is not loaded.

Expected behavior
The mini cart show 3 items.

The language selector causes the following snippet to be called in the ActiveCartService
const loading = cartValue$.pipe( withLatestFrom(this.activeCartId$, this.userIdService.getUserId()), tap(([{ cart, loaded, isStable }, cartId, userId]) => { if ( isStable && isEmpty(cart) && !loaded && !isTempCartId(cartId) && this.shouldLoadCartOnCodeFlow ) { this.load(cartId, userId); } }) );
When the problem happens the shouldLoadCartOnCodeFlow value is false. It is set to false in the detectUserChange() method
if (this.isLoggedInWithCodeFlow()) { // only when code flow // Prevent loading cart while merging. this.shouldLoadCartOnCodeFlow = false; .... // call loadOrMerge }

So what happens is:
After login the detectUserChange is called setting the boolean to false, but it loads the cart. Changing the language will not reload the cart as shouldLoadCartOnCodeFlow remains false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions