I solved this by adding an await to the top level getNext()
aka
const next = await getNext({
page,
value,
name,
id,
});
which is inside an async router.post
call. So the answer is: make sure all functions are async all the way to the top so that they wait for eachother.