【问题标题】:NestJS API cookies arent working on HerokuNestJS API cookie 不适用于 Heroku
【发布时间】:2021-08-28 13:36:05
【问题描述】:

我的 NEST api 可以在 localhost 上运行,但 cookie 不能在 heroku 上运行。

这是我的配置

  app.enableCors({ origin: process.env.FRONT_END_URL, credentials: true }); // FE_URL == http://localhost:3000 (a react app)
  app.set('trust proxy', 1); // I've seen people using express using this, but isn't working here
  app.use((req, res, next) => {
    req.connection.proxySecure = true; // If i don't do this, it'll throw an error if i'm using secure == true and sameSite == 'none'
    next();
  });

  app.use(
    sessions({
      cookieName: 'FEATSession',
      secret: 'ThisIsMyTopSecretWord',
      duration: 24 * 60 * 60 * 1000,
      activeDuration: 1000 * 60 * 5,

      cookie: {
        path: '/', // Tried '/' and not setting this prop too
        // domain: 'feat-be.herokuapp.com', // I tried using and not using it too
        sameSite: 'none',
        secure: true,
        httpOnly: true, // Tried true and false too
      },
    }),
  );    

其他一切正常,只有 cookie 不行。

【问题讨论】:

    标签: express heroku cookies nestjs


    【解决方案1】:

    我今天刚刚解决了一个非常相似的问题,尝试设置cookie的不同语法: SameSite property invalid Cookies HTTPONLY MERN

    【讨论】:

      猜你喜欢
      • 2022-09-30
      • 2021-06-03
      • 1970-01-01
      • 2023-02-03
      • 2020-02-18
      • 2014-09-01
      • 2023-03-29
      • 2012-12-19
      • 2011-12-13
      相关资源
      最近更新 更多