Dec 12, 2019 in Drupal 8, Snippets

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.
}