Saturday, May 20, 2017

How To Generate Auth Token on Request Vue.js with Laravel API CSRF Token

How do I get the Auth token from a Laravel API and immediately use that token in an http/ajax/axios request?

JS / Client

Vue.axios.post('http://laravelApi:8000/here', {someData}).then(response->{ 
  console.log(response.data); 
});

PHP / API

route::post('/here', function(){
  response...
});

Is there a favoured pattern for returning & re-posting the csrf-token? Can I define the headers differently between an initial request and subsequent requests that include the cors token?

Thanks!

( I kind of already know the answer, but if someone has code-examples / insight it could save me a lot of debugging. )



via admcfadn

Advertisement