Garen
 · trying to learn FlutterFlow

How to correctly request user_data in a non-single query?

Database & APIs

At the top column of the HomePage I'm trying to fetch 'user_data' table from Supabase - specifically the current Authenticated user.
Problem 1: It works, but if you switch off Single Time Query then Anonymous users will get an empty page (the NULL problem)
Problem 2: If you switch on the Single Time Query, then you don't get the benefits of Supabase's Realtime, and in my case it's a functional necessity.


What am I trying to achieve? While a given user is watching an ad, I'm setting a boolean column called "disableAllAds" in his public.user_data table to TRUE (which allows me to disables buttons for all other ads). And once the bottom-sheet containing an ad has closed, I'm setting the boolean to FALSE. This is to prevent fraud and abuse - with an android emulator like LMplayer users can create multiple phones and open multiple tabs in each phone emulator, and set a bot that clicks the ads -- resulting in thousands of watched ads in just few minutes. Using AppState does not solve this problem (because AppState doesn't persist across tabs and phones), so I'm recording into user_data in Supabase, and it works like a charm when the Single Time Query is turned off, but that creates a NULL problem for the anonymous users.

So how do I solve this conundrum that has been driving me up the wall for the past 2 days??? If Auth.user and public.user_data are separate tables, how are we supposed to call the user_data of the current user and keep an eye on its changes???

What have you tried so far?

To avoid the Anonymous problem, I have also tried doing the 'user_data' table query at HomePage level Conditional Actions (if user is logged in), but the query in Actions doesn't give option to turn off Single Time Query. I have also tried to add 'unsubscribe' and "subscribe" actions to the 'user_data' table (same way as subscribing to another table's Realtime, which works fine), but in this case it doesn't update values in Realtime.

Did you check FlutterFlow's Documentation for this topic?
Yes
3 replies