I need to get the customer email in homepage in a script.
Googling around I find mentions of
window.customerData variable, but is always undefined (perhaps removed in latest versions?)
So at first I tried this:
require([ 'Magento_Customer/js/model/customer', ...
but it fails with error:
TypeError: can't convert undefined to object somewhere in
Then I tried with:
require([ 'Magento_Customer/js/customer-data', ...
customerData.get('customer') but it gives me only first and last name or an empty object (even when the user is logged).
Is there a way to obtain the logged user email anywhere outside the checkout page?