After Login , customer data is showing from previously logged-in customers data in dashboard , orders, address etc, even after clearing the cache / trying in new private window
-
I faced this same issue previously, it depends where are you showing cusotmer data. I mean is that page cacheable? Magento2 doesn't refresh cache on all pages.– Narendra VyasFeb 9, 2019 at 7:26
-
Also how to are fetching customer data, you need to use magento way to do that i.e. customerData.js. It will be great if you can show how you are getting data. I mena you need to show some code that you have done till now– Narendra VyasFeb 9, 2019 at 7:28
1 Answer
You need to use Private content in order to see customer information on cachable pages.
For example if you need to show customer name on dashboard after login you will get such issue of showing wrong name becasue that page is been cache already by full page caching.
So there are two ways to do that:
You can put that block to me cacheable = false, but that is not recomended beacuse that will remove that whole page from full page caching.
You can use customerData.js in order to retrieve logged in customer data.
If you need to show order and invoices of logged in customer on dashboard, I would suggest to get data from an ajax response instead of getting data from customer session.
Have a look here: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/cache/page-caching/private-content.html