Body is unusable
Answered
Hoopoe posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HoopoeOP
export async function PATCH(req: Request) {
const session = await auth();
if (!session || !session.user) return invalid("session");
if (!(await doesUserHaveRole(session.user.id, "Admin"))) return notAdmin;
const {
generatorId,
newGenerator,
}: {
generatorId: number;
newGenerator: {
name: string;
roleName: string;
enabled: boolean;
};
} = await req.json();
console.log(await req.json());
if (!generatorId || typeof generatorId !== "number")
return invalid("generator id");
await editGenerator(generatorId, newGenerator);
return Response.json({ error: false, message: "Edited!" });
}
![Image](https://cdn.discordapp.com/attachments/1195999268243259402/1195999268394242108/image.png?ex=65b6081e&is=65a3931e&hm=a90175cd3e1320fe8755eeb38c979c8acd47f30a66a0396cd59b114276eeb6d9&)
3 Replies
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
You cannot call req.json twice
Answer
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/f386ac21405ce3442e0f3598223e1cb3.webp?size=256)
joulev
So call it only once and reuse the returned value any number of times as you want
![Avatar](https://cdn.discordapp.com/embed/avatars/4.png)
HoopoeOP
ah okay