Execute complex logics before starting the app

Hello RW community,

I would like to run a bunch of queries and run a bunch of algorithms before showing the frontend content to the user. What would be the best practices for this aside from useEffect?

Thanks in advance.

Would this run synchronously for each user before they could use the app? Might that cause a long delay and not be a great user experience?

Have you considered doing this as part of an event-driven onboarding flow with Inngest?

1 Like

Yes this would run synchronously for the user before they could use the app, the delay is about 1-2 seconds. Basically when the user hits the URL, I’ll call some APIs, fetch the latest data and once I have the data I’ll show the content to the user. I am not familiar with Inngest, do you think that fits this use case?

If you are using dbAuth, then consider adding logic to the loginHandler or signUpHandler

This won’t trigger every time the visit the app (and are already logged in) but would on login and signup.

You could put your work there.

If you are using “some other auth” then I would look into their hook features.

It might. See: Inngest - Patterns: Async + Event-Driven

You could trigger a user login event and then on that even run all the “algorithms” in a background job.

Thanks @dthyresson
Thanks for the suggestions. Let start working on it and report back here.