[Vuejs]-EBADCSRFTOKEN: Invalid CSRF token in adonis js

0๐Ÿ‘

I can not guess the context from your call to you controller. But my headers are correctly sent using AJAX in the following format:

headers: {'x-csrf-token': $('[name=_csrf]').val()},

Alternatively, you can disable CSRF auth in the config/shield.js file, at the bottom just turn to false the enable variable, like this:

 csrf: {
    enable: false,
    methods: ['POST', 'PUT', 'DELETE'],
    filterUris: [],
    cookieOptions: {
      httpOnly: false,
      sameSite: true,
      path: '/',
      maxAge: 7200
    }
  }

0๐Ÿ‘

you can add your route path in filterUris like this

csrf: {
enable: true,
methods: ['POST', 'PUT', 'DELETE'],
filterUris: ['/firstroute','*',],
cookieOptions: {
  httpOnly: false,
  sameSite: true,
  path: '/',
  maxAge: 7200
}

}

more info about this check link

Leave a comment