The useQuery hook you're trying to use is a React hook and it's not meant to be used in the server-side functions. Instead, you should use the database query methods provided by Convex to fetch the user data.
Here's how you can modify your function to fetch the profile images of allowed users:
export const getAllowedUsersProfileImages = authQuery({
args: { documentId: v.id("documents") },
handler: async (ctx, args) => {
const doc = await ctx.db.get(args.documentId)
let arr:any = doc?.allowedUsers
const allowedUsersProfileImages = await Promise.all(arr.map(async (id:Id<"users">) => {
const user = await ctx.db.get(id)
return user?.profileImage
}))
return allowedUsersProfileImages
},
})
In this modified function, instead of using useQuery, we're using ctx.db.get(id) to fetch each user's data. This is a server-side method provided by Convex for fetching a document from the database by its ID. The profileImage of each user is then returned in the resulting array.
Please note that this assumes that your user documents have a profileImage field. If the field is named differently, you'll need to adjust the code accordingly.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: