【问题标题】:Strapi session not found on Chrome在 Chrome 上找不到 Strapi 会话
【发布时间】:2022-06-15 15:58:33
【问题描述】:

我用 Nuxt 和 Strapi 建立了一个网站。我使用 ctx.session 添加了一个购物车系统。它在本地运行良好,但在 prod 中,使用 Chrome 或 Safari 时无法恢复会话。但它与 Firefox 相得益彰。

我登录查看发生了什么,似乎从未存储会话。一个动作完成后,什么都没有了。

这是我的 middleware.js :

const isProd = process.env.NODE_ENV === 'production'

module.exports = {
  //...
  settings: {
    cors: {
      enabled: true, 
      // headers: '*', 
      credentials: true,
      origin: isProd 
        ? ['https://xxxxxx.com', 'https://yyyyy.xxxxxx.com']
        : ['http://localhost:3000', 'http://localhost:1337']
  
    },
    logger: {
      level: 'trace'
    }
  },
}

还有我的 server.js :

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  admin: {
    auth: {
      secret: env('ADMIN_JWT_SECRET', 'XXXXXXXXXXXX'),
    },
  },
  cron: { enabled: true }
});

在前面,这是我的 Axios 配置:

const apiClient = axios.create({
  baseURL: `${process.env.baseUrl}/`,
  withCredentials: true,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  timeout: 10000,
})

谢谢

【问题讨论】:

  • 什么是ctx.sessionHere is 如何正确使用 Nuxt 的环境变量。否则,为什么你的 Nuxt 中有一些 CORS?这不应该在服务器上吗?您是否尝试过所有浏览器上的隐身标签?清理了所有cookies/localStorage等?奇怪的是它可以在 Firefox 上运行,我不得不说。
  • ctx.session 由 Strapi 提供,使用 Koa (see here。我尝试隐身,清理一切,其他计算机,没有任何工作...

标签: javascript nuxt.js strapi


【解决方案1】:

我终于找到了解决办法!

我在 middleware.js 配置文件中缺少会话激活。

module.exports = {
  //...
  settings: {
    ...otherSettings,
    session: { enabled: true }
  },
}

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 2021-07-20
    • 2020-05-24
    • 2022-06-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-08
    相关资源
    最近更新 更多