• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

173
Vistas
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

almost 3 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

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);
        });
    }
  }
almost 3 years ago · Juan Pablo Isaza Denunciar

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"
}
almost 3 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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda