We have enabled the feature of password protection as a customization using an extension. The extension will help to redirect the domain URL to a login page if the customer is not logged in to the webstore.
Code for solution:
define(
'JJ.PasswordProtectFeature.PasswordProtectFeature'
, [
'Profile.Model'
]
, function (
ProfileModel
) {
'use strict';
return {
mountToApp: function mountToApp(container) {
// using the 'Layout' component we add a new child view inside the 'Header' existing view
// (there will be a DOM element with the HTML attribute data-view="Header.Logo")
// more documentation of the Extensibility API in
// https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/index.html
/** @type {LayoutComponent} */
var profile = ProfileModel.ProfileModel ? ProfileModel.ProfileModel.getInstance() : ProfileModel.getInstance();
setTimeout(function () {
var islogged = profile.attributes.isLoggedIn;
if (islogged == 'F') {
var currenturl = window.location.href;
var currentPage = currenturl.split('/').pop(-1);
currentPage = currentPage.split('.');
var flag = true;
if (currentPage[0] != 'newlogin' && currentPage[0] != 'checkout') {
flag = false;
}
if ((flag == false)) {
var newLandingPageUrl = SC.ENVIRONMENT.siteSettings.touchpoints.register;
console.log(newLandingPageUrl, 'newLandingPageUrl');
Backbone.history.location.href = newLandingPageUrl;
}
}
}, 100);
}
};
});