How to authorize viewing and clicking a function only logged users?

If you want to hide the output of this shortcode from users who aren’t logged in, I’d make use of the is_user_logged_in() function built right into WordPress.

The issue you’ll run into, however, as Tom pointed out in the comments, is that you will need to check if users are logged in as part of the action that runs to favorite the post. Hiding the button doesn’t actually prevent users from using the action unless you protect the action itself as well.