I find myself doing something along the lines of the following on almost all mutations:
const currentUser = context.currentUser
if (!currentUser) throw new AuthenticationError('You are not logged in!')
const recipeBasicInfo = await db.recipe.findUnique({
where: { id },
include: {
chef: true,
},
})
if (currentUser.id !== recipeBasicInfo!.chefId) {
throw new AuthenticationError('You can only delete your own recipes!')
}
Is there a better way of doing this and having less code repeated? Note that this logic is not just for recipes, but for any model with mutations.
Thanks!