Russell Codd wrote:
I have some links in the menu block of my mobile app where I surround them in an IF widget with a condition of GetUserId() <> NullIdentifier() to see if a user is logged in or not.
That way the user does not see links which are not appropriate for them, as the app can be used by both registered and anonymous users.
However, it looks like the GetUserId() must somehow cache the value of the user id, even if that user is not logged in. We can test this as follows:
- Create a link that is only visible to a logged in user with GetUserId() <> NullIdentifier().
- Click that link to a page with the role Registered.
- Page is not loaded, instead you are sent to the login page.
So, after some explanation, my question is as follows:
How can I reliably tell if a user is logged in to the app? Is there a better condition I can use in the IF widget?
Hi Russell Codd,
As you mention, the app has certain features that to be show/hide based on user logged-in or not.
Thus there's an approach to do so:
1- Either make a Local Entity & maintain the respective state's there.
2- Use Android iOS Shared User Preferences Component from Forge.
https://www.outsystems.com/forge/component-overview/5013/android-ios-shared-user-preferences
I would recommend you to go via opton-2, as of Maintaining an aggregate just for the sake of one status is not a good approach.
You can create a Key with name User_Session & set it's Boolean value based on Login & Log-out action. And then use it accordingly to validate throughout the App.
Note : The SharedPreferences will only be clear in two cases;
- Either you manually clear
- App get's Un-Install from device
Cheers,
Assif