If I want to do certain things in a Joomla template depending on whether a user is logged in (e. g. load bootstrap CSS and -JS for the frontend editor), then I can do this in different ways.

The examples are entries in the upper part of the index. php of the current template.

Old method (sometimes it worked out unreliable for me):

<?php
defined('_JEXEC') or die('Restricted access'); 
/**
* my cool template
**/
$user = JFactory::getUser();
if ($user->authorise('core.edit', 'com_content'))
{
   do something
}

?>

Reliable method:

<?php
defined('_JEXEC') or die('Restricted access');
/**
* my cool template
**/

$user = JFactory::getUser();


if (!$user->guest) {

   do something...
   for example:
			$doc->addScript('templates/' . $this->template . '/js/template.js');
			JHtml::_('stylesheet', 'frontendediting.css', array('version' => 'v1', 'relative' => true));
} 
?>