Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda