Variable update behavior different between public app and edit mode?

HI,

I am having trouble using the result of a Retool database query in the success handler. It seems that the query result is empty when passed to the success handler. (In the attached image, whether I use "firstload.data.id" or "selt.data.id," the result remains the same. So, it doesn't seem to be an issue with the syntax.)

When I execute the same query again, the success handler works as expected. This issue only occurs in public apps and not during the editing stage.

Why is the query result not immediately passed to the success handler in public apps?

Thank you for your assistance.

use firstload instead of self

Even when using "firstload" instead of "self," the result remains the same.

Sorry but why do you have it when length === 0
Shouldn't it be != ?

I test it in public app, it work correctly.

There are some limitation in public app.

Custom Authentication in Public Apps
Like OAuth 2.0 and other SSO based auth options, custom auth workflows store defined variables using a relation with the authenticating user's Retool account. Because public app viewers do not use a retool account, custom auth is not supported in public apps.

Pls debug your firstload.data is correctly got?

I apologize for the lack of context sharing!

After logging in, the system is designed to retrieve user information using the issued session_id and display the information specific to each user.
However, if the user information cannot be confirmed, the control should display the login popup (modal3) again. So length === 0 condition is used.

While the query itself successfully retrieves user information, it appears that the result is not being passed to the data variable in the success handler (only in public apps).

Thank you! However, I am not using Custom API authentication this time.

Pls debug your firstload.data is correctly got?

Both self.data and firstload.data give the same result. After the query is completed, the firstload.data contains the latest value, but it is not being passed to the success handler.

For example, could you please add utils.showNotification() to the success handler and try displaying {{query8.data.id}} or {{query8.data.id.length}} in public app? If there is valid data, notification should display the data or show a length of 1, but in my environment, it displays 0.

Yes, I test it. The notification show the corrected data of {{query8.data.id}} and {{query8.data.id.length}}.

What is you environment ? self-hosted or cloud, and version?

Could you export your app to json for me to check?

Due to the presence of sensitive information in my project, I cannot share it directly. However, I have provided a sanitized version without any confidential data!(my environment is cloud version

copy.json (45.2 KB)

The basic principle of the login remains the same: If the login information is correct, the session_id is saved in the local storage. Then, the local storage is used to retrieve the results from the "user" table in Retool. If there are results, the message "successfully logged in" is displayed; otherwise, the login modal is opened again. Reloading the page should display the message.

The expected behavior is that the message is displayed correctly after a single login.

I have confirmed that the same issue occurs in this sanitized version as well. I would greatly appreciate it if you could take a look and see if you can help me with the debugging.

test (1)

Hello, here is my solution. The problem is your wrong way to use trigger and event success handler.


Here is code.

const promise = generateUUID.trigger()
  .then(result => {
    
    // session_id.setValue(result);
    localStorage.setValue("session_id", result);
    updateUser.trigger().then(res=>{ 
      firstload.trigger();
    }); 
      
    return result; // Return generateUUID.data from this block
  })
  .catch(error => {
    return error;
  });

return promise; // Return the promise directly

Pls be notice that the firstload must run after the updateUser success, because it need to check the updated database.

This time you don't need to login two time in public app.

Thanks for sharing app.json. I want to create a similar login recent, it offer me many new idea. Have a good day.

Thank you! This code works as expected now!

Is it correct to say that the success handler in the GUI does not wait for the processing in the code to finish before it is triggered?? To ensure synchronous processing, is it necessary to chain the code with "then" as shown above??

No, in the CreateSession query, it will return a promise, in that time, the success handler will run, but the updateUser in it may not run yet. So the firstLoad may get empty value.

To ensure updateUser run before firstLoad, you must add firstLoad to its resolve.

2 Likes