Override Magento_Theme::view/frontend/templates/html/topmenu.phtml and use this code in the file:
<?php $columnsLimit = $block->getColumnsLimit() ?: 0; ?>
<?php $_menu = $block->getHtml('level-top', 'submenu', $columnsLimit) ?>
<nav class="navigation" data-action="navigation">
<ul data-mage-init='{"menu":{"responsive":true, "expanded":true, "position":{"my":"left top","at":"left bottom"}}}'>
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if($customerSession->isLoggedIn()) {
// customer login action
echo $_menu;
}
?>
<?php /* @escapeNotVerified */ echo $block->getChildHtml(); ?>
</ul>
</nav>
Though, using objectmanager is not a good practice, so you may override block file too.
to override topmenu.phtml, follow this:
In your module the template needs to be placed here:
app/code/VENDORNAME/MODULENAME/view/frontend/templates/html/topmenu.phtml
Additionally, a layout definition is required:
app/code/VENDORNAME/MODULENAME/view/frontend/layout/default.xml
and put this in default.xml:
<?xml version="1.0"?>
<page layout="1columns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="VENDORNAME_MODULENAME::html/topmenu.phtml" ttl="false"/>
</body>
</page>