How to check if user is logged in on mobile app project and send to login page if not?

On a mobile app project, how do I check if the user is logged in. If they are not, then direct to login page?

I’m not sure if this should work, because I’m am always redirected to the login page. Could someone confirm it this should work?

I have two Wappler projects (Server and mobile) and I created a simple API/Server Action on the Server.

It has one step under Execute. The step I added is the Security Identify action. I’m expecting this to return a true/false value based on if the user is logged in.
image

Then on the mobile app project, I added a Server Connect component that links to the Security Identify action I created on the server.
image

Next, I added a Browser component
image

Finally I added a Page Flow
image

Set it to Auto Run
image

In the flow I added a condition to check if the Server Connect value is false. Under THEN I added a Run action and then add the Browser.goto. I set it to my login page.
image

This works to direct the user to the login page, but I then login and am taken back to the index page and I’m immediately sent back to the login page. It’s like the Security Identify Server Connect is always returning a false value.

This is called a race condition :slight_smile:

The way you did this, there’s no guarantee the page flow will run AFTER the server connect runs, you cannot make any assumptions regarding the order the operations run. What’s most likely happening is the page flow is running BEFORE the server connect has a chance to complete the request

The only way you can guarantee the page flow runs after the server connect loads, is you setup a Dynamic Event “On Success” on your server connect isLoggedIn to run page flow flow1, and you untick the “Auto Run” checkbox on the flow properties

Thanks Ivan. Sadly that did not work. I’m guessing the steps I’m taking won’t work on a mobile app.

I only read Apple’s comment and wanted to chime in.
Don’t have space right now to read the entire thread, so sorry if this doesn’t help at all.

I’m struggling often with the timing of some on page javascript/page flows/ and server connects.
What might help:

  1. Adding a small delay with a ‘wait’. Usually wait 1 will work, but I had to up mine to wait 10 because it was ‘losing the race’ often.

Somewhere on the forum you can find Patrick recommending this.

  1. This might help: How to run a JS function after DOM is complete && server connect is done?

Theres a great video on youtube. Talks through this from around 17 mins

https://www.youtube.com/watch?v=3YwGbN81Qws