Strapi upgrade to 4.1.12 and get jwtSecret missing issue

System Information
  • Strapi Version: 4.1.12
  • Operating System: Linux
  • Database: postgres
  • Node Version: v14.17.6
  • NPM Version: 6.14.16
  • Yarn Version:

I got this issue while I start the app:
debug: :no_entry: Server wasn’t able to start properly.

[2022-05-26 23:02:17.514] error: Missing jwtSecret. Please, set configuration variable “jwtSecret” for the users-permissions plugin in config/plugins.js (ex: you can generate one using Node with crypto.randomBytes(16).toString('base64')).

For security reasons, prefer storing the secret in an environment variable and read it in config/plugins.js. See Environment configuration and variables - Strapi Developer Docs.

Error: Missing jwtSecret. Please, set configuration variable “jwtSecret” for the users-permissions plugin in config/plugins.js (ex: you can generate one using Node with crypto.randomBytes(16).toString('base64')).

For security reasons, prefer storing the secret in an environment variable and read it in config/plugins.js. See Environment configuration and variables - Strapi Developer Docs.

I was trying to follow the steps in https://docs.strapi.io/developer-docs/latest/update-migration-guides/migration-guides/v4/migration-guide-4.0.6+-to-4.1.8.html#fixing-the-breaking-changes

Here is my plugnin.js, am I doing something wrong? Any help would be appreciated!
module.exports = ({ env }) => ({

‘users-permissions’: {
config: {
jwtSecret: env(‘JWT_SECRET’),
},
},
upload: {
provider: ‘local-custom-path’,
enabled: true,
providerOptions: {
path: env(‘UPLOADS_PATH’) || ‘public/uploads’,
sizeLimit: 100000
},
},
});

1 Like

Check in .env whether u set JWT_SECRET value or not .

1 Like

Thank you! This issue happened when I deployed it on the cloud, even though I think I saved JWT_SECRET on cloud.
I finally solved it by using this, posted here if anyone encounter the same issue.
var jwtSecret = getSecret(“JWT_SECRET.txt”) || crypto.randomBytes(16).toString(‘base64’);

Hello, please explain how exactly you your final code looks like in the plugins.js. I’m facing the sane issue presently.

1 Like

Generate the random secret:

openssl rand -hex 64

Either set is as an environment variable

export JWT_SECRET=<GENERATED>

add it to your .env file:

JWT_SECRET=<GENERATED>

or if you’d like to use custom name, provide it in your config/plugins.js configuration:

module.exports = ({ env }) => ({
  "users-permissions": {
    config: {
      jwtSecret: env('CUSTOM_JWT_SECRET'),
    }
  }
})
2 Likes

Where should this be added? Can you elaborate? I can’t figure out the error.

you have to create a plugin js
module.exports = ({ env }) => ({
“users-permissions”: {
config: {
jwtSecret: env(‘JWT_SECRET’),
}
}
})

put the jwt secret in env

and if you want a key then run this cmd worked in my case
node -e “console.log(require(‘crypto’).randomBytes(256).toString(‘base64’));”

1 Like