Next.js Discord

Discord Forum

hiding requests in network tab

Unanswered
astro posted this in #help-forum
Open in Discord
how do i conceal the data that is being posted on my api routes? on inspecting the payload in network tab the data that im passing to my api route is visible, how do i hide it?

"use client";

export default function PromptForm() {
  const form = useForm<z.infer<typeof promptFormSchema>>({
    resolver: zodResolver(promptFormSchema),
  });
  const [imageSrc, setImageSrc] = useState(null);

  async function createImage(values: z.infer<typeof promptFormSchema>) {
    const res = await fetch("/api/createImage", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(values),
    });

    if (!res.ok) {
      console.log(await res.json());
      return;
    }

    const url = (await res.json()).url;
    console.log(url);
    setImageSrc(url);
    return;
  }

  return (
    <div className="flex justify-between">
      <Form {...form}>
        <form className="space-y-6" onSubmit={form.handleSubmit(createImage)}>
          ...
      </Form>
     </div>
);
}

5 Replies

You can try server actions but a request will still be visible in your network tab, you can't hide things from network tab.
You shouldn't be sending api key as a body from client side but using env var
like the api key?
American Crow
its never save to send any secrets in headers or bodies. Usually you'd use env variables read on the server (in a route handler, server action, server component, middleware)