How to replace the button when the user is not authenticated?
You can use predefined logged_in variable.

{% if logged_in %}
  &lt;div class="bs-field-like-link"&gt;
    {{ content.flag_like_group }}
  &lt;/div&gt;
{% else %}
  &lt;div class="bs-field-like-link"&gt;
    &lt;a class="btn btn-success" href="/user/login"&gt;&lt;i class="far fa-heart fa-1x"&gt;&lt;/i&gt; J'aime&lt;/a&gt;
  &lt;/div&gt;
{% endif %}