RTK 查询凭据为 [Object: null prototype]

问题描述 投票:0回答:1

当我向服务器发送请求时,在服务器上我得到一个错误,cookies = [Object: null prototype].

appAPI代码

...
export const appAPI = createApi({
  reducerPath: "appAPI",
  baseQuery  : fetchBaseQuery({
    baseUrl       : process.env.REACT_APP_API_URL,

凭证:“包括”,

    prepareHeaders: (headers) => {
      if (localStorage.getItem("token")) {
        headers.set("authorization", `Bearer ${localStorage.getItem("token")}`);
        // headers.set("Content-Type", "multipart/form-data");
      }
      headers.set("Access-Control-Allow-Origin", "https://localhost:3000");
      headers.set("Access-Control-Allow-Credentials", "true");
      return headers;
    },
  }),
...

在 index.js 文件中,cors 配置如下所示

app.use(cors({credentials: true, origin: ["http://localhost:3000"]}));
cookies credentials rtk-query
1个回答
0
投票

尝试使用 JSON 发送响应。只是 res.json({message: "Everything OK"}) 我解决了同样的问题。

© www.soinside.com 2019 - 2024. All rights reserved.