• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

172
Views
¿Cómo puedo enviar un token al backend en vue js?

Estoy tratando de hacer un pago a mi backend, pero cada vez que envío el pago recibo este mensaje de mi backend

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

mi backend requiere autenticación

esta es mi etiqueta de script

 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>

cuando reviso mi herramienta de desarrollo, veo mi token

 token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ"

estos son mis encabezados backend

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

por favor como puedo hacer esto

over 2 years ago · Juan Pablo Isaza
2 answers
Answer question

0

su código se ve bien, simplemente cree un objeto y luego agréguelo a la URL. Supongo que está buscando algo como esto ... intente esto

 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); }); } }
over 2 years ago · Juan Pablo Isaza Report

0

El primer parámetro es tu URL,

El segundo parámetro son sus datos,

El tercer parámetro es su configuración.

Puede hacer una solicitud de publicación como a continuación

 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, } } );

NOTA: los datos son el cuerpo de su solicitud.

ex

 { "firstname": "Firat", "lastname": "Keler" }
over 2 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error