Is javascript enabled.
Nov 16, 2018
6
Level 7
CSRF problem with mobile only!
Hi there,
I have a weird issue that I'm getting nowhere with. I have a Vue2/Laravel 5.7 SPA that works perfectly in development and production whether it's using Chrome, Firefox or Safari.
However when I go to the app on a smartphone, whether the phone browser is Chrome or Firefox, when I try to POST data, the TokenMismatchException is thrown.
My bootstrap.js looks like this:
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
window.axios.defaults.headers.common={
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-TOKEN' : document.querySelector('meta[name="csrf-token"]').getAttribute('content')
}
Again, in a desktop environment, everything runs perfectly - this just happens with a mobile browser.
Any ideas?
Please or to participate in this conversation.