IF function: Clicking an option reroutes the user to two pages depending if they are logged in or not

Previously, I’ve been using airtable, however, we’ve just shifted to Xano.

We’ve successfully made a sign up and login page, however, now that we have the log in and sign up page, we’re aiming to enable one button to either: 1) redirect the user to the login page (if they haven’t logged in yet) or 2) redirect the user to the subscription page where they can subscribe or avail to our products.

I’ve been trying to use the IF function, however, I don’t know how I should go about it…Please help?

When will they go to the login page and when will they be directed to the signup page?

The button is “Subscribe” (this is for a product/services).

What I’m trying to do is if they click subscribe and they haven’t logged in yet, then they will be redirected to the LOG IN page. However, if they’ve already logged in, then they will be redirected to the SUBSCRIPTION page.

Great. So what you need to do is, everytime they are logged in, you need to update an appvariable which can be a boolean to true.

Then in the logic for the button,

  1. Add an if else block.
  2. In the formula for if just give appVars.logged_in
  3. connect the first output to open page(Subscribe)
  4. Connect the second output to open page(login page)
  5. If you are using authentication , then instead of open page use go to intialview flow function.

How do I update an appvariable? The steps for the logic for the button are clear to me, however how do I update the boolean appvariable?

Like do I just go to variable views > App variable > Add property (true/false) rename “Log in”

Yes you add an app variable from the variables section. Set it to false. Then wherever you have your flow function for logging in you add a set app variable node and set it to true

Thank you! I did as you said and set it up, it works. Thanks a lot!

Good to hear. Great Work there! :smiley:

Can you help me with another problem? I’m having trouble trying to understand how I can upload images and submit it to the backend. Whenever I click the image where the camera toggles to take picture, It just shows “source” and “repeat with”. I don’t know where I can bind the page variable to contain the image and to submit it to the backend.

I’m still using xano and it has a separate API key for posting images.

I haven’t used xano but you have to uplod a file with request to the server. Let me check and get back to you.

Okay, I’ll try to find some other sources and see how it goes too. Thank you!

I’m having some problem…I didn’t really change anything from the logic flow and the initial result that worked should be working right now but that’s not the case.

The SUBSCRIBE button has the two functionality of redirecting users if 1) They are logged in to Subscribe page, and 2) They aren’t logged in to Log in page.

I’ve tried directly going to the log in page and logging in before clicking the Subscribe button and the functionality works, it directs me to the Subscribe page.

However, whenever I try clicking the Subscribe button first without being logged in, it redirects me to the log in page, runs my credentials and returns me back to the log in page after I’m logged in instead of redirecting me to the Subscribe page.

I was thinking that my authentication failed but since I was able to open the Subscribe page (can only be opened when authenticated), that’s not the case.

The LOGIC for the SUBSCRIBE button goes like this:

Component Tap > IF appVariable.login >

  1. Open Subscribe page;
  2. Open Login

The LOGIC for the LOGIN button goes like this:

Component Tap > Create Record >

  1. SetAppVar (a.) auth, (b.) login > Dismiss Initial View;
  2. Toast text

EDIT

Also, In the button Subscribe, I tried putting “Return to initial view” after the “Open Login” and whenever I click the Subscribe button, it automatically brings me back to the initial view and I can’t even put my credentials on cause it automates me back to initial view.

The LOGIC should look like this:

Component Tap > IF appVariable.login >

  1. Open Subscribe page;
  2. Open Login > Return to initial View.