I'm currently utilizing middleware.ts
to intercept and authenticate user requests. However, I want to include data from our database in these authenticated requests.
Within my server action code, the structure is as follows:
export async function getProjectsByUser(): Promise<PrismaProject[]> {
const user = await getUser()
const projects = await prisma.project.findMany({
where: {
user_id: user.id,
},
include: {
Document: true,
Conversation: {
include: {
Message: true,
},
},
},
});
return projects
}
The initial line within this function fetches the user. Although, ideally, I would prefer to retrieve this information from the middleware instead. Unfortunately, I am uncertain how to achieve this. Are there any recommended best practices for referencing user information in middleware?