Mobile App Redirect when logged/not logged in

Still going with my mobile app questions :slight_smile:

I can’t use the App Connect Page protection since I’m not on a php page in the mobile app. So my reasoning is to check if user is logged in by running a server action when app opens(1st page - login) to check if they are logged in. If server actions runs successfully, redirect using app connect browser. If not successful, stay on current/login page.

But I do not know how to make the server action run unsuccessful when not logged in. Could one use throw errors to get this to work…?

Any other ideas also welcome besides redirect using browser function on success of server action.

use only index.html for login … It will not be necessary for other pages.
maybe other user can share different way

Thanks, but I want to redirect user to another page if already logged in. Do not want them to login everytime. index.html is set as the entry point for the app.

your app will start only index.html …
and you can store user id or etc. in session then redirect to another page

how do I achieve that part :slight_smile: Store is easy. Just the redirect.

you can use "background service" for this.

1 Like

Will check it out - thanks

@pixlapps
You can place the userdetails action (some action getting logged user data) on the first page and run it onload.
Then check its status:

  • onunauthorized - do nothing i.e. stay there on the page. Or show alert that the user needs to log in to proceed.
  • onscuccess - redirect to your inner page
2 Likes

yeap this is easy …

Even easier - you can do this on one page and check the same things and use two conditional regions. If user is not logged in - show form, if he is logged in show the content.

1 Like

I have removed the onboarding, login, register page from the main page since it just becomes too busy and difficult to manage code. So your suggestion suites me best.

You can place the userdetails action (some action getting logged user data) on the first page and run it onload.
Then check its status:

  • onunauthorized - do nothing i.e. stay there on the page. Or show alert that the user needs to log in to proceed.
  • onscuccess - redirect to your inner page

the onsuccess runs everytime, meaning it redirects whether user is logged in or not. My userdetails action has 3 steps. Connect to db, Security Provider and query for details.

I can also only test this on phone and not on my localhost in browser. Get this error when trying to log in from local on my macbook or in emulator:

14

You can preview your HTML files directly in the browser.

yip, that’s not a problem. Problem is when running login action I get the error, but bigger issue is that onsuccess of server action with userdetails runs whether user logged in or not. Would prefer to only have it run when user is logged in as to keep user on login page if not logged in.

Have you added security restrict step to your action? So that it only runs if the user is logged.

Will check - probably my issue. Thanks!!!

Cool, sorted. Was restrict. Appreciate the quick help :smile:

1 Like