I’m going really well with Wappler but am struggling with documentation being older than Wappler and some bits not being there at all.
I have a nav menu which is in an include file. I want to only show the ‘Log out’ menu item if the visitor is logged in. I’ve added the Conditional Region component but I just can’t see what needs to go in the ‘Condition’ field.
Please check the documentation section, it’s explained how to create a logout button on your page: Logout - Create a Working User Logout Button
As for the condition value - select the identity binding returned from your user details action. Click your button, select dynamic attributes - show: and bind identity binding.
If it has a value, the button will be displayed.
Thanks for your replies. I’ve already got everything working, including the log out link, that’s not the problem. I want to put in a conditional so that ‘Log out’ in the nav menu is only shown when they are logged in. It’s pointless having it in the menu when they’re not logged in. I just can’t find the info to get this bit finished.
Hmm, I’m really trying to achieve this without asking questions but I’m just not able to.
Can you give me some steps to achieve the ability to hide some output if a user is logged in?
I’ve followed the instructions for using the security enforcer and I have the login page working and have also set other pages to be restricted to logged in users. I haven’t used a user details action (I can’t even find this in Wappler) so am at a loss how to proceed.
Aah, I don’t think so. All I have at the moment is the facility to log someone in and then show a page which requires being logged in. And I’ve made a logout feature. That’s it.
You can check the logged user session in this case.
When your users log in, a session is being created. Its name is security provider step name + Id. If your security provider step (in server action) is called "userSecurity" the session will be called:
userSecurityId
In order to check this, in app connect structure add session manager, and add this session there.
Then use the dynamic attributes - show - and select the session as a condition.
Brilliant, thanks Teodor. I think I’ve been fixated on building the site without touching code so overlooked some simple coding which I would have normally done anyway. I added a simple
Thanks again. Is there a tutorial for that? I’ve added a $_SESSION in the Globals section of the server actions and have added the dynamic attribute for ‘hide’ but can’t see how I put in the expression.
@Teodor Can you explain how I add the session within Session Manager as you describe please?
Everything I enter is forced to lowercase and the binding doesn’t seem to pick up that I’m logged in.
I find this bit a little confusing. If I knew the user id to query by, then wouldn't I already know that the user is logged in, or am I missing something here?
What I did was create a user details query to retrieve the details of the logged in user.
I then put in on my SPA index page, so it is called when the page is loaded.
I then referred to it on the SPA child pages by adding it to the show/hide dynamic attributes or server connect data displayed on the page.
It is important to note that with SPAs, any queries on the index page are not currently available in the data picker, so you would need to manually add it in.
To only show the content on the SPA child page if logged in, you would add a Dynamic Attribute>Show with the {{sc_get_user_details.data.query1[0].webu_firstname}} as the When.