Antro
Antro

Reputation: 43

Strapi session not found on Chrome

I built a website with Nuxt and Strapi. I added a cart system using the ctx.session. It works well on local, but when in prod, the session can't be retrived when using Chrome or Safari. But it's perdect with Firefox.

I logged to see what's happening and it seems that the sessions is never stored. After an action is done, nothing remains.

Here is my 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'
    }
  },
}

and my 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 }
});

On the front side, here is my Axios config :

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

Thank you

Upvotes: 1

Views: 2331

Answers (1)

Antro
Antro

Reputation: 43

I finally found the solution!

I was missing the session activation in the middleware.js config file.

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

Upvotes: 1

Related Questions