Check if a user is logged in in drupal 8. Snippet:
if (\Drupal::currentUser()->isAuthenticated()) { // This user is logged in. } else { // This user is not logged in. }