Database not updating correctly on button click

To implement a free trial function, each user has a “Trial Status”, “Subscription Status”, and “Active Status”. The default values are 1, 0, and empty respectively.

Upon clicking the login button several actions occur:

  1. The user is logged in
  2. Their “Trial Status” is set to 0 if their account is older than 30 days
  3. Then their “Active Status” is calculated as “Trial Status” + “Subscription Status”
  4. If their “Active Status” is greater than 0, they are linked to the Home screen
  5. If their “Active Status” is equal to 0, they are linked to the Manage Subscription screen
  6. When the user pays for a subscription, their “Subscription Status” is set to 1

In theory, this allows for a 30-day free trial, and if the user doesn’t subscribe, they are prevented from navigating into the app, and are blocked by the Manage Subscription screen. When they pay, they can login normally and go to the Home screen.

The issue I’m having is this…

In the database, I have manually set the default values for my user as:
“Trial Status” = 0
“Subscription Status” = 1
“Active Status” = empty

When I attempt to login, the login screen just refreshes and deletes the email/password entered, and I am not linked to the Home screen or the Manage Subscription screen.

Upon checking the user database, I see that the “Active Status” field is still empty. If I manually enter a 1 in this field in the database, it reverts to empty after a login attempt.

It seems that the “Trial Status” + “Subscription Status” is not being calculated

Am I trying to use too many actions in the login button?

Since the “Trial Status” is conditionally updated just before the calculation, could this database read/write block the calculation from being performed due to read/write speed?

Any other ideas why this might be happening?

Thank you

I think you should log in first..then run the other actions. I had this issue too when I first started building. You can do this 2 ways

  1. Log in then direct to another screen with a 2 second countdown timer & run the other actions once the countdown finishes
  2. Log in first, direct user to a screen with a button, when user clicks this button you can run the other 4 actions

This should enable all your actions to work correctly for the logged in user

Best Regards

Jay

Thanks Jay, I’ll try this.

This works! Thank you!!

1 Like

Hi @ElectricMike,

It is not recommended to have any actions immediately after log in or sign up action. The best way is to link user to another screen and create all the logic there (could be on-screen-enter actions or countdown timer).

This has been discussed on the forum, there are some useful threads with advices on this subject.

Best regards, Victor.

Thank you Victor, I changed it and it’s working now.

1 Like