Next.js Discord

Discord Forum

Body is unusable

Answered
Hoopoe posted this in #help-forum
Open in Discord
Avatar
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
Answered by joulev & fuma pray for Schneider
You cannot call req.json twice
View full answer

3 Replies

Avatar
joulev & fuma pray for Schneider
You cannot call req.json twice
Answer
Avatar
joulev & fuma pray for Schneider
So call it only once and reuse the returned value any number of times as you want
Avatar
HoopoeOP
ah okay