Best way to trigger a workflow for setting variables and fetching collections?

Hello everyone,

I’m looking for some advice on the best way to trigger a workflow in my app.

I currently call a Postgres function through Supabase to get the user’s latest course and the current lesson they’re on. Once I have this data, I update two variables: course and lesson. These variables are then used as filters to fetch collections that depend on the user and their current course.

Originally, I was running this workflow on page load, but I realized that’s not ideal. I only want to fetch this information once, not every time the user navigates to a new page. The variables persist across navigation, so repeating the workflow is unnecessary. I also need these variables to be available across the entire app, not just on specific pages.

I considered using “on app load”, but that fires before the user is authenticated, so the workflow runs too early. Triggering it when the user logs in could work, but what happens if the user is already logged in when the app loads?

So my questions are:

  • What’s the recommended place to initialize this workflow?

  • How should I handle cases where the user is already authenticated when the app starts?

  • How long do Weweb variables persist in this context?

Any guidance or best practices would be greatly appreciated!

Mélanie

Hi Melanie :waving_hand:,

Great question! One simple approach is to keep the workflow on app load , but add a quick auth check at the start: only run the Supabase function and set your course / lesson variables if the user is authenticated and those variables are still empty. That way it runs once for users who are already logged in, skips guests, and your variables can then be reused across the whole app without re‑fetching on every page.

Another option is to move this workflow to the first private page after login, so it only runs it once the user is definitely authenticated.

1 Like