Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

express-jwt secret does not import process.env.JWT_SECRET

I’m trying to use process.env.JWT_SECRET for the secret but it just trow error:

export const requireSignin = expressjwt({
  secret: `${process.env.JWT_SECRET}`,
  algorithms: ["HS256"],
  userProperty: "auth",
});

This way I don’t have error but the then I get ‘UnauthorizedError: invalid signature’

export const requireSignin = expressjwt({
  secret: process.env.JWT_SECRET,
  algorithms: ["HS256"],
  userProperty: "auth",
});

This way I get "RangeError: express-jwt: secret is a required option"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

export const requireSignin = () =>{

  return expressjwt({
  secret: process.env.JWT_SECRET,
  algorithms: ["HS256"], 
  userProperty: "auth",
  }); 
}

This way just load forever.

export const requireSignin = expressjwt({
  secret: '09f26e402586e2faa8da4c98a35f1b20d6b033c6097befa8be3486a829587fe2f90a832bd3ff9d42710a4da095a2ce285b009f0c3730cd9b8e1af3eb84df6611',
  algorithms: ["HS256"],
  userProperty: "auth",
});

And here is the only way working (which is problematic..)
Any help is welcome, thank you.

>Solution :

1 – Install dotenv

2 – Require it where you need the env variable:

require("dotenv/config");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading