shopware / frontends

Shopware Frontends is a framework for building custom, headless storefronts with Shopware 6.
https://frontends.shopware.com
MIT License
176 stars 49 forks source link

[BUG] useUserContextInSSR not working anymore #1189

Closed maximilian-schwarz closed 3 months ago

maximilian-schwarz commented 3 months ago

Is there an existing issue for this?

Current Behavior

I remove the from the account menu because I want to render the menu on the server side. I have also activated "useUserContextInSSR". When I log out, isLoggedIn is wrong on the client and server side. When I log in with a customer account, isLoggedIn is true on the client side and false on the server side.

And because the values are different on client-side and server-side, you also get a hydration warning. And I know that you can easily fix it with the tag. But in this case, if you want to render it on the server side, that's not the point.

Expected Behavior

When I enabled the "useUserContextInSSR" option, I expected the UserContext to be available for client-side requests and server-side requests. Currently we got wrong responses with useUser() composable

Steps To Reproduce

  1. Go to the stackblitz reproduction
  2. And click on the top right corner "Open preview in new tab" and click "Connect to project".
  3. Look in the Browser console (Client side) from the new tab. No user is logged in so you get "User is logged in: false". If you look in the Stackblitz console (Server side) there is the same: "User is logged in: false".
  4. Click on the top right corner sign in in the preview tab from Step 2.
  5. Sign in (If you have any account) or Sign up (if you not have a account).
  6. After the registration is complete try to login. After login reload the Tab from Step 2. Now you can see in the browser console (CLient side) "User is logged in: true", but if you look in the stackblitz console (Server side) there is: "User is logged in: false"

Environment

No response

Anything else?

Reproduction link vue-demo-store: https://stackblitz.com/edit/github-5gcazj?file=components%2Faccount%2FAccountMenu.vue

mkucmus commented 3 months ago

hey, thanks for reporting it. It will be fixed together with https://github.com/shopware/frontends/pull/1192 I'm working rn. the problem was that cookie with a context token couldn't be read in the SSR. The PR will help to solve that.

maximilian-schwarz commented 3 months ago

@mkucmus Thank you :)

BrocksiNet commented 3 months ago

The current draft is here. :raised_hands: