How do I check if customer is logged in or not in knockout template?
my template
<!-- ko if: customer().firstname -->
<!-- /ko -->
my js
define(
[
'ko',
'jquery',
'Magento_Ui/js/form/element/abstract',
'mage/url',
'Magento_Customer/js/customer-data',
'mage/translate'
],
function (Component,storage,ko,jquery,Abstract, url, customerData, $t) {
'use strict';
return Component.extend({
message: function() {
loggedMessage : $t('Welcome, %1!')
},
htmlLoggedMessage: ko.observable(),
isLoggedIn: ko.observable(),
customer: ko.observable({}),
initialize: function() {
this._super();
if(this.isCustomerLogged != 0) {
this.isLoggedIn(true);
}
this.checkCustomerLocalStorage();
},
/**
* Check customer localstorage
*/
checkCustomerLocalStorage: function () {
var self = this;
var time = setInterval(function () {
self.customer = customerData.get('customer');
if (localStorage["mage-cache-storage"] != '{}') {
clearInterval(time);
}
if (self.customer().fullname) {
var name = self.customer().fullname;
var message = self.message.loggedMessage.replace('%1', name);
self.htmlLoggedMessage(message);
}
}, 1000);
}
});
}
);
I followed this link but its still entering in to if condition: