Search code examples
jwttoken

Verify JWT Token error 'secretOrPrivateKey must have a value'


return failure(new Error('secretOrPrivateKey must have a value'));enter image description here


Solution

  • I think your application is not able to read the environnement variables.

    I advice you to use the package dotenv : https://github.com/motdotla/dotenv

    After installing it you have to import it at the top of your application like this:

    require("dotenv").config();
    

    Specify a file .env at the root of your application and add your variables

    JWT_SECRET=12bob12ou2b1ob
    NODE_ENV=development
    

    After, you can use the variables like you did in your linked image:

    const jwtSecret = process.env.JWT_SECRET