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:

  1. Create a link that is only visible to a logged in user with GetUserId() <> NullIdentifier().
  2. Click that link to a page with the role Registered.
  3. 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?


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:

  1. Create a link that is only visible to a logged in user with GetUserId() <> NullIdentifier().
  2. Click that link to a page with the role Registered.
  3. 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

Hello Russel 

I think what you are doing is perfectly correct. 

Check the below documentation link to get a better understanding of Mobile Authentication. 

Also there are some settings that can be configured 

https://success.outsystems.com/Documentation/11/Managing_the_Applications_Lifecycle/Secure_the_Applications/Configure_Mobile_App_Authentication

Look at the sections Authentication Cookies & Authentication Cache. This should give you clarity on this. 

Hope this helps !!!

Solution

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:

  1. Create a link that is only visible to a logged in user with GetUserId() <> NullIdentifier().
  2. Click that link to a page with the role Registered.
  3. 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 Russel,

I am having same scenario in my application. I am explaining what i did, may be it will help you:

I have create one boolean parameter with false value.

Assigned it to the Visible property of that link.

By default all links will be hidden.

OnReady of my page i am checking if the user is logged in then i am updating the value of boolean variable.

It is not giving me any issue.

Regards, 


Solution

mohammad hasib wrote:

Hi Russel,

I am having same scenario in my application. I am explaining what i did, may be it will help you:

I have create one boolean parameter with false value.

Assigned it to the Visible property of that link.

By default all links will be hidden.

OnReady of my page i am checking if the user is logged in then i am updating the value of boolean variable.

It is not giving me any issue.

Regards, 



Hi Mohammad,

This sounds promising... how are you checking if the user is logged in OnReady?

Russell Codd wrote:

mohammad hasib wrote:

Hi Russel,

I am having same scenario in my application. I am explaining what i did, may be it will help you:

I have create one boolean parameter with false value.

Assigned it to the Visible property of that link.

By default all links will be hidden.

OnReady of my page i am checking if the user is logged in then i am updating the value of boolean variable.

It is not giving me any issue.

Regards, 



Hi Mohammad,

This sounds promising... how are you checking if the user is logged in OnReady?

Hi Russel,

I am checking with the same getuserid() method. I am checking it onready of my screen, not on application ready.

Regards,


mohammad hasib wrote:

Russell Codd wrote:

mohammad hasib wrote:

Hi Russel,

I am having same scenario in my application. I am explaining what i did, may be it will help you:

I have create one boolean parameter with false value.

Assigned it to the Visible property of that link.

By default all links will be hidden.

OnReady of my page i am checking if the user is logged in then i am updating the value of boolean variable.

It is not giving me any issue.

Regards, 



Hi Mohammad,

This sounds promising... how are you checking if the user is logged in OnReady?

Hi Russel,

I am checking with the same getuserid() method. I am checking it onready of my screen, not on application ready.

Regards,


I will give that a go, thank you. I have added a local variable (LoggedIn) to my menu block, and added the Assign: LoggedIn = GetUserId<> NullIdentifier() to the Onready of the menu block.

I will let you know if it survives our testers, thank you!


Default value of loogedin variable should be false and assign that variable to the Visible property of your button or link.

This seems to have worked, so thank you :D

Russell Codd wrote:

This seems to have worked, so thank you :D

Good to hear that it works for you.