https://nextjs.org/docs/app/api-reference/functions/redirect
I'm new to NextJS myself, but maybe something like this could work? Maybe perform the request whenever the request is triggered and await the response and use the function accordingly?