Skip to content
Advertisement

Middleware “strapi::session”: App keys are required. Please set app.keys in config/server.js (ex: keys: [‘myKeyA’, ‘myKeyB’])

Trying to set up strapi and cloudinary I watched two videos and they are all OK, but I have an error, tell me why?

Middleware “strapi::session”: App keys are required. Please set app.keys in config/server.js (ex: keys: [‘myKeyA’, ‘myKeyB’])

enter image description here

plugins.js

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'cloudinary',
      providerOptions: {
        cloud_name: env('CLOUDINARY_NAME'),
        api_key: env('CLOUDINARY_KEY'),
        api_secret: env('CLOUDINARY_SECRET'),
      },
      actionOptions: {
        upload: {},
        delete: {},
      },
    },
  },
  // ...
});

.env

HOST=0.0.0.0
PORT=1337
CLOUDINARY_NAME="my data"
CLOUDINARY_KEY="my data"
CLOUDINARY_SECRET="my data"
JWT_SECRET=my data

server.js

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  app: {
    keys: env.array('APP_KEYS'),
  },
});

middlewares.js

module.exports = [
  'strapi::errors',
  'strapi::security',
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::session',
  'strapi::favicon',
  'strapi::public',
];

admin.js

module.exports = ({ env }) => ({
  auth: {
    secret: env('ADMIN_JWT_SECRET'),
  },
  apiToken: {
    salt: env('API_TOKEN_SALT'),
  },
});

Advertisement

Answer

It looks like you don’t have APP_KEYS defined in your .env file (assuming you’re sharing the full file), as well as some other env variables you’re accessing using strapi’s built in env utility.

In your .env you should have a value for the following that should follow this format:

APP_KEYS=['key1','key2']

You can read more about environment config from Strapi’s development docs: https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.html#strapi-s-environment-variables

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement