set-cookie not stored ..error msg about Domain

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

access-control-allow-origin: http://localhost:3000
content-length: 299
content-type: application/json; charset=utf-8
date: Mon, 01 May 2023 11:35:51 GMT
etag: W/"12b-8efK5dxnadj10qqm+FsB8wLDLFE"
set-cookie: refreshToken=eyJhbGci0iJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW
IiOiI1YTk3NzgxZC05ZWQ4LTQxZTItOThhNi03ZmMzNTg0MTNjNTUiLCJpYXQiOjE20 DI5NDA5NTESIMV4CCI6MTY4NDE1MDU1MX0.avIPao2AXowDOKHYG0Ft2WiSg@cASgxZ
ePqaP5xF0sw; Domain=localhost; Path=/; HttpOnly; SameSite=Lax
vary: Origin
x-powered-by: Express

Set-Cookie 被阻止,因为它的域属性对于当前主机 url 无效

服务器网址:https://abcd.site

前端网址:http://localhost:3000

  • SameSite=None & 安全选项需要“https”。但是我们的战线还没有部署。

  • 我尝试了 Next.js 配置设置

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  compiler: { emotion: true },
  async rewrites() {
    return [
      {
        source: "/:path*",
        destination: "https://need-romance.site/:path*",
      },
    ];
  },
};

module.exports = nextConfig;
export const login = async (email: string, password: string) => {
  try {
    const response = await axios({
      method: "post",
      url: URL + "/auth/login",
      data: {
        email,
        password,
      },
      withCredentials: true,
      headers: {
        "Cache-Control": "no-cache",
      },
    });

    return response.data;
  } catch (error) {
    console.log(error);
  }
};

从来源“http://localhost:3000”访问位于“https://need-romance.site/auth/login”的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:“Access-Control-Allow-Origin”标头的值“localhost:3000”不等于提供的来源。

通过 Set-Cookie 标头设置 cookie 的尝试被阻止,因为它具有“SameSite=Lax”属性,但来自跨站点响应,这不是对顶级导航的响应。

也有这样的错误

让他们在网上搜索,错误只是改了,并没有解决

我尝试去掉credential选项,但是黄色三角的错误消失了,但是cookie没有设置进去

之前是http的时候肯定是

帮助我...

http cookies https cors cross-domain
© www.soinside.com 2019 - 2024. All rights reserved.