javascript – Protect against csrf using go backend and Vue-ThrowExceptions

Exception or error:

I have Vue.js front end which uses a backend json API developed in golang. I want to protect against csrf, I looked at https://github.com/gorilla/csrf and their example. Im not sure how to implement this as it seems that my golang web server needs to serve/render the vue app?

let csrfToken = document.getElementsByName("gorilla.csrf.Token")
  [0].value


  const instance = axios.create({
  baseURL: "https://example.com/api/",
  timeout: 1000,
  headers: { "X-CSRF-Token": csrfToken }
  })


  try {
      let resp = await instance.post(endpoint, formData)

      } catch (err) {
      // Handle the exception
      }
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *