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

353
Visualizações
fetching data through env.local file gives an error "Failed to load resource: the server responded with a status of 401"

I have a problem when i try to fetch data through my env file i get an error "Failed to load resource: the server responded with a status of 401 ()" error msg

:{
    "status_code": 7,
    "status_message": "Invalid API key: You must be granted a valid key.",
    "success": false
}

but when i fetch data without using env.local file and use my api key directly in const variable everything works fine. But i want to make the env local file call to work.

My env.local file

API_KEY=3retkjdkfgjfd95659 (MADE IT UP FOR THE POST)

My utils folder /requests.js

const API_KEY = process.env.API_KEY;
//const API_KEY = "3retkjdkfgjfd95659" the code works only when i use this variable
const requests = {
  fetchTopRated: {
    title: "Top Rated",
    url: `/movie/top_rated?api_key=${API_KEY}&language=en-US`,
  },}

My axios file

const instance = axios.create({
  baseURL: "https://api.themoviedb.org/3/",
});

export default instance;

Banner file

function Banner() {
  const [movie, setMovie] = useState([]);
  useEffect(() => {
    async function fetchData() {
      const request = await axios.get(requests.fetchTopRated.url);
      setMovie(
        request.data.results[
          Math.floor(Math.random() * request.data.results.length - 1)
        ]
      );
      return request;
    }
    fetchData();
  }, []);
about 4 years ago · Juan Pablo Isaza
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