I want to show the customers details and bought products in frontend page

how can i show the my custom module's page only if the user is logged in.

  • Is your frontend page is CMS page or your custom module's page? Commented Nov 6, 2017 at 9:26
  • its my custom module's page bro Commented Nov 6, 2017 at 9:42

1 Answer 1


You can add an if condition in the controller of your custom page.

protected $_customerSession;

public function __construct(
    \Magento\Customer\Model\SessionFactory $customerSession
    $this->_customerSession = $customerSession;

public function execute(){
    $customer = $this->_customerSession->create();
        your controller's code
  • Be sure to render the content via ajax, else if FPC is enabled, content may either be of logged-in or logged-out case.
    – MagePsycho
    Commented Nov 6, 2017 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.