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

286
Visualizações
how can i send token to backend i n vue js

i'm trying to make payment to my backend, but each time i send the payment i get this message from my backend

{
    "success": false,
    "message": "No token Provided"
}

my backend requires authentication

this is my script tag

 methods: {
    sendTokenToServer(charge, response) {
      const token = localStorage.getItem("token");
      axios
        .post(`http://localhost:5000/api/pay`, {
          headers: {
            Authorization: "Bearer" + token,
            "x-access-token": token
          },
          totalPrice: this.getCartTotalPriceWithShipping,  
        })
        .then(res => {
          console.log(res);
        });
    }
  }
};
</script>

when i check my dev tool i see my token

token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ"

this is my backend headers

 let token = req.headers["x-access-token"] || req.headers["authorization"];

please how can i go about this

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

your code looks fine, just create an object then add it to the url i guess your looking for something like this.. try this

methods: {
    sendTokenToServer(charge, response) {
 var request = {
        totalPrice: this.getCartTotalPriceWithShipping,
      };
      const token = localStorage.getItem("token");
      axios
        .post(`http://localhost:5000/api/pay`,request, {
          headers: {
            Authorization: "Bearer" + token,
            "x-access-token": token
          },
        })
        .then(res => {
          console.log(res);
        });
    }
  }
about 4 years ago · Juan Pablo Isaza Relatório

0

First parameter is your url,

Second parameter is your data,

Third parameters is your config.

You can make a post request like below

axios
  .post(
    `http://localhost:5000/api/pay`, 
    data,
    {
      headers: {
        "Authorization": `Bearer ${token}` //mind the space before your token
        "Content-Type": "application/json",
        "x-access-token": token,
      }
    }
  );

NOTE: data is your request body.

e.x.

{
  "firstname": "Firat",
  "lastname": "Keler"
}
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