Show logged in user’s name in the website (updated code)

Insert this in a text field on static block <span id="user-name"></span>
and this to Page Settings>Custom Code>Header field and replace BLOCKID with your block id(name)

<script>
window.addEventListener('block-loaded-BLOCKID', () => {
        if(window.logged_in_user) {
            let helloUser = document.createElement('span').innerTex = "Hello " + window.logged_in_user.softr_user_full_name;
            document.getElementById('user-name').append(helloUser);
        }   
    
});
</script>
3 Likes

If you have a first name field in your database (users table), yes =>

Put: <span class="d-none">{LOGGED_IN_USER:FIELD:First Name}</span> wherever you want to display the first name.

Then in the header custom code (page settings) add this:

<script>
window.addEventListener('block-loaded-list1', () => {
	console.log('Block loaded');
    if(window['logged_in_user'] && window['logged_in_user']['First Name']) {
        const nameData = window['logged_in_user']['First Name'];
        $("span:contains('{LOGGED_IN_USER:FIELD:First Name}')").removeClass('d-none');
        $("span:contains('{LOGGED_IN_USER:FIELD:First Name}')").html(nameData);
    }
});

</script>

You need to change ‘First Name’ by your actual first name field (case sensitive)
Replace ‘list1’ in window.addEventListener(‘block-loaded-list1’, () => { by the block ID where the name should be displayed.