小编Mus*_*Opu的帖子

类型错误:主体不可用 - NextJS 服务器操作 POST

我在客户端组件中使用 NextJS v14.1.0 和服务器操作。我收到了正确的消息,但也收到了一个 TypeError 消息,表明 body 不可用。

src/app/auth/account-verification/page.tsx

const onSubmit = async (e: FormEvent<HTMLFormElement>) => {
    e.preventDefault();
    const data = { requestId: token, otp: parseInt(otp) };
    const response = await AccountVeficationAction(data);
    ActionResponseHandler(response, "Account Verification");
    if (response.success) {
      Router.push("/auth/login");
    }
  };
Run Code Online (Sandbox Code Playgroud)

/src/app/auth/_utils/actions/action.ts

export const AccountVeficationAction = async (body: any) => {
  try {
    const response = await fetch(`${BASEURL}/auth/confirm-account`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        // Add other necessary headers (e.g., authorization)
      },
      body: JSON.stringify(body), // Access data from the …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs next.js

2
推荐指数
1
解决办法
364
查看次数

标签 统计

next.js ×1

reactjs ×1

typescript ×1