最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

next.js - Why my cookies aren't stored in cookie storage in Google Chrome (or anywhere) - Stack Overflow

programmeradmin5浏览0评论

I have deployed my front-end on Vercel and back-end on railway. Localy it works fine, but in production I have a problem with non-storing cookies.

Here is my axios config for front-end (Next.js):

export const api = axios.create({
    baseURL: process.env.NEXT_PUBLIC_SERVER_URL,
    headers: {
        'Content-Type': 'application/json'
    },
    withCredentials: true
})

Here is my config for back-end (Nest.js):

app.use(cookieParser());

    app.enableCors({
        origin: config.getOrThrow<string>('ALLOWED_ORIGIN'),
        credentials: true,
        exposedHeaders: ['set-cookie'],
    });

app.use((req: Request, res: Response, next: NextFunction) => {
    res.setCookie = (name: string, value: string, options = {}) => {
        res.cookie(name, value, {
            httpOnly: true,
            secure: config.getOrThrow<string>('NODE_ENV') === 'production', //(it's true on production)
            sameSite: 'none',
            ...options,
            });
        };
      next();
  });
发布评论

评论列表(0)

  1. 暂无评论