Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

218
Vistas
Get env variables inside _middleware Next.js

Inside my nextjs project I have variables added in both .env and next.conf.js files. Inside next.conf.js file it looks like this

module.exports = {
  env: {
    NEXT_PUBLIC_JWT_SECRET: "...",
  },
  publicRuntimeConfig: {
    NEXT_PUBLIC_JWT_SECRET: "...",
    API_JWT_SECRET: process.env.API_JWT_SECRET,
  },
  serverRuntimeConfig: {
    // Will only be available on the server side
    NEXT_PUBLIC_JWT_SECRET: "...",
    secondSecret: process.env.JWT_SECRET, // Pass through env variables
  },
};

I have tried all this ways to get the secret ket in my _middleware file, but none of them worked. From this github issue I assume that there is a way to do that. So could you please show me the correct way to get secret ket inside _middleware?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As hugefunwoo says

Next.js will replace process.env.customKey with 'my-value' at build time. Trying to destructure process.env variables won't work due to the nature of webpack DefinePlugin.

const { JWT_SECRET } = process.env 

This will return undefind so I had to replace it by

const JWT_SECRET = process.env.JWT_SECRET
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda