WordPress adds logged-in to the body when a user is logged in, but only in the admin. The following code adds a class on the frontend too. Useful for custom styling or showing different content. For more on WordPress hooks and filters.
add_filter( 'body_class', function( $classes ) {
if ( is_user_logged_in() ) {
$classes[] = 'logged-in-user';
}
return $classes;
} );