LOGGED_IN_USER data source

I am confused where is data in LOGGED_IN_USER coming from.
For example I have a simple hero text that I modified to include Hello {LOGGED_IN_USER:NAME} and that works. It shows "Hello Mark. But in my users “table” in softr under users page I have entry for Mark that is “Mark Johnson”, and I don’t have a NAME field in my air table.
And when I try to do {LOGGED_IN_USER:FULL_NAME} where FULL_NAME is a field in my air table, it doesn’t work. I see “Hello {LOGGED_IN_USER:FULL_NAME}”

What am I missing?

Hi!

{LOGGED_IN_USER:xxxxx} is the method to get the logged-in user information to be pulled in your app.

The ‘NAME’ from {LOGGED_IN_USER:NAME} comes from what Softr stores once a user is considered as registered in the app.
Basically it’s the information that you can find here (see image below) and that Softr lets you access to (NAME & EMAIL => MAGIC LINK, CREATED DATE, USER GROUPS - for now - and LAST SEEN DATE may not be accessible).

Now, what if you want to access your fields from your users table in Airtable? The format is a bit different. For example, you want to take the FULL_NAME value. FULL_NAME being a field (case sensitive) in your airtable users table.

=> {LOGGED_IN_USER:FIELD:FULL_NAME}. Here I added FIELD: to get the users table in Airtable, not the users table in Softr.

Inside a script, it would be:

if(window['logged_in_user'] && window['logged_in_user']['FULL_NAME']) {

Thanks @matthieu_chateau that makes sense and it is helpful however it’s not working.

Here is a screenshot from my internal users table


As you can see I have a user with name John Smith

Here is a screenshot from the page where I have a “placeholder” set:
Screenshot from 2024-03-20 09-05-12

And when I open this page in preview mode I see this:
Screenshot from 2024-03-20 09-04-54
The last name is missing. Only John is pulled.

When I modify the placeholder to be {LOGGED_IN_USER:FIELD:full_name} where full_name is a filed in my airtable.
Screenshot from 2024-03-20 09-06-40
Nothing is rendered on the page. I see exactly the same place holder like this:
Screenshot from 2024-03-20 09-06-55

here is a screenshot from my airtable

Yes, I can confirm it only takes the first name. I always work with the airtable fields directly so I was not aware of it.

Use ‘full-_name’ instead (It needs to be case sensitive => exactly as it is in your Airtable)

Here is the process:

  1. Place <span class="d-none">{LOGGED_IN_USER:FIELD:full_name}</span> where you want the full name to appear.

  2. You need to add a script in your page settings => custom code => header =>

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

Replace feature-grid1 by the id/name of the block where you want to display the full name.

Thanks again however I can’t get it to work. I’ve tried different variations but no luck. For example I have this simple script:

<script>
window.addEventListener('my-test-list', () => {
	console.log('log 1');
    if(window['logged_in_user'] && window['logged_in_user']['full_name']) {
       console.log("log 2");
    }else{
        console.log("log 3");
    }
    console.log("log 4");
});

  console.log("log 5");
</script>

and when the page is loaded the only log statement I see is log 5

I am attaching the screen shots too:

console
Screenshot from 2024-03-21 19-21-20

Do I need to write different script b/c the text I want to replace is part of the dynamic list element?

This is the not the code I wrote.

You just need to use the one I wrote above and add the span where you want the full name to be displayed.

Correct - not the code you wrote. I was just showing that even the block of code you wrote does’t execute. Your block of code has this statement console.log('Block loaded');
that is not logged in the console window.
Screenshot from 2024-03-21 19-58-05
and the text i have in the <span> like this Here: <span class="d-none">{LOGGED_IN_USER:FIELD:full_name}</span> is not replaces.
So this window.addEventListener for some reason is not working.

You are trying to use <span class="d-none">{LOGGED_IN_USER:FIELD:full_name}</span> inside a heading or inside a subtitle, right? I mean the static heading or the static subtitle of the dynamic block (The option Title and Subtitle of any dynamic block).

I am using it in the subtitle of a dynamic block (list)

So it should work. I can’t debug without any further information, meaning going inside your app to check everything. Or maybe if you could record a video where you would show everyhting in the Softr studio (code + the list block).

Few basic things but we never know: In the preview mode, be sure you are as a logged-in user. Be sure also that you didn’t change the name of the users table in Airtable (it would disconnect everything).

Be sure your dynamic block is named ‘my-test-list’ (Sometimes Softr doesn’t take it in count when it is changed, it’s a small bug).

Also, you may have published your app once.

Be sure you wrote this in the subtitle:
Creative Content for <span class="d-none">{LOGGED_IN_USER:FIELD:full_name}</span>

In other words, double check everything.

In the meantime you should reach out to the customer service within the chat in the Softr studio (The question mark button at the bottom right of the studio)

Here is a video showing code in the header, the span inside the subtitle of the list as well as what the page looks like in the preview mode. Thank you for your time looking into this - https://youtu.be/5V8fWXYtIqU

Hi,

careful you make a mistake => first line => you removed ‘block-loaded-’

Here is the updated code:

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

:slight_smile: wow! I totally missed that the block needs to be prefixed with block-loaded-. Thanks a lot! Is this part of their official documentations somewhere?

:slight_smile: I thought it would work. but it’s not. Something is not right here.
Screenshot from 2024-03-25 11-29-16
You can see in the screenshot above free-subscribers-list block

And then here is the script

it just does not work…

No official docs, no. Not yet at least, Softr still being a no-code tool :sweat_smile:.

It’s just a mandatory thing to make any custom code more robust.

Short story: It is linked to the loading speed of blocks in a page and how to deal with it effictively when adding custom code.

Reference: Event Listener for Dynamic Lists (React Version) - #3 by artur

(It’s not only for dynamic lists => also for static blocks).

Thanks I think we were typing at the same time. Did you see this - LOGGED_IN_USER data source - #14 by earthtome
it’s not working…

I don’t know, I can’t debug without being inside your app :woman_shrugging: => check with the customer service in the Softr studio as I suggested earlier.

Thanks for all your help. Yes, I am talking to them right now. I will update the thread with solution.