Fetch collection based on condition

Hello

One my the page I’m building can be browsed by authenticated and anonymous users.
Auth users do have some specific div hidden to the anonymous ones, thanks to the “Conditional rendering” feature.

To fill this div, I must fetch a collection from Supabase with some filters like the user_id.

When the user browsing my page is anonymous, even if the div is not rendered, Weweb is fetching the collection and it returns an error “22P02”, because the user_id cannot be provided to the collection filter.

Is there a way to avoid fetching this collection for anonymous users, and automatically fetch it once the div is rendered?

So far, I think I can only remove the “fetch automatically” flag from the collection. And fetch the collection in the “on page load” workflow. Meaning, I have always to fetch this collection manually.

Any other smart/automatic way I’m not aware of?

Thanks for your help

You could use the On mounted workflow trigger of the div with a pass through condition that checks for whether the user is anon or authenticated. Only then fetch.

1 Like

Hello Broberto,
But I need to remove the “fetch automatically” from the collection, and always fetch this collection manually.

I would love to be able to manage it automatically. Like a “conditional fetch” at collection level :smiley:

But thanks for the tip of using the “on mounted” workflow. It will help to call the workflow only when needed