How to show logged in user's name in the website

In case one wants to show only the first name.

<script>
    document.addEventListener("DOMContentLoaded", function () {
        if(window.logged_in_user) {
            const name = window.logged_in_user.softr_user_full_name;
            const firstName = name.split(' ').slice(0, -1).join(' ');
            $("span:contains('{LOGGED_IN_USER:NAME}')").removeClass('d-none');
            $("span:contains('{LOGGED_IN_USER:NAME}')").html(firstName);
        }
    });
</script>