I have found the below code. but it's not working and showing define error in frontend if i use this code in phtml file. Like this error shown : require.js:166 Uncaught Error: Mismatched anonymous define() module: function($,customerData){
<script type="text/javascript">
define(['Magento_Customer/js/model/customer'], function (customer) {
if (customer.isLoggedIn()) {
// Do your Logic.
}
});
</script>
Also i have tried the below code in phtml file to get customer data in js but it always return null or ko observer object.
<script type="text/javascript">
require([ 'jquery', 'Magento_Customer/js/customer-data'],function($,customerData){
var customer = customerData.get('customer')();
console.log(customerData.fullname);
if (customer.fullname && customer.firstname)
{
alert(customer.fullname);
}else{
alert(customer.fullname);
}
});
</script>
.phtmlfile will load the data from Block file. Why do you using extra code to validate user in.jsfile instead of check with usersessionin Block file? – Bojjaiah Apr 08 '21 at 05:56cacheable="false"inlayoutfile? – Bojjaiah Apr 08 '21 at 06:06