How to hide login button server-side? (once logged in)

Hi,

I’m building a user dashboard and would like to hide the login button in the navbar.

I have created a Server Action that returns the current user identity:

I have set the master page to call such Server Action, through a Server Connect element:

And, finally, I’m hiding the Login button when an identity is present:

<div class="navbar-nav ms-auto" dmx-hide="serverconnect1.data.identity">
    <a class="nav-item nav-link" href="login">Login</a>
</div>

This works, it hides the element after an API call to obtain the user identity.

However, during page load, there’s a moment where the server connect API call hasn’t performed yet, and therefore the user could see such element for a few milliseconds before being hidden.

Is it possible to hide this element server-side? I understand we can use EJS conditions, but I’m unsure what condition I should input to verify if the user is logged in already. Certainly I can’t use “serverconnect1.data.identity” because this is a client-side variable.

Has anyone attempted this scenario server-side?

This should help you achieve what you want.
The Server Side Server Action could return the security identity instead of a server connect.

Just add an if condition with EJS and check the server variable that holds the identity. I can’t remember which one it is but it’s there :slight_smile:

You can check the Local web server log to find out how to read it.

image