# Fetch collection based on condition

**URL:** <https://community.weweb.io/t/fetch-collection-based-on-condition/17646>\
**Category:** How do I?\
**Created:** [April 7, 2025, 1:07pm UTC](https://community.weweb.io/t/fetch-collection-based-on-condition/17646 "2025-04-07T13:07:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Popi](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@Popi](https://community.weweb.io/u/Popi)\
**Post date:** [April 7, 2025, 1:07pm UTC](https://community.weweb.io/t/fetch-collection-based-on-condition/17646/1 "2025-04-07T13:07:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [April 7, 2025, 7:15pm UTC](https://community.weweb.io/t/fetch-collection-based-on-condition/17646/2 "2025-04-07T19:15:18Z")

</div>

> [@Popi](#):
>
> Is there a way to avoid fetching this collection for anonymous users, and automatically fetch it once the div is rendered?

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.

---

<div class="post-metadata">

**Author:** ![Popi](https://avatars.discourse-cdn.com/v4/letter/p/f475e1/32.png) [@Popi](https://community.weweb.io/u/Popi)\
**Post date:** [April 8, 2025, 8:36am UTC](https://community.weweb.io/t/fetch-collection-based-on-condition/17646/3 "2025-04-08T08:36:57Z")

</div>

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 😃

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