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?
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.
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.
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
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.
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.