Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!