I'm a bit further and have partially solved this problem. Before showing the login form, I explicitly request a new CSRF token from the server in the created() method of the component. I then reassign the received token to the axios headers:
created(){
axios.get('/refreshtokens')
.then( response => {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = response.data.csrfToken;
})
.catch( error => {
/** handle error **/
});
}
In the controller function for this endpoint , I simply return the CSRF token using Laravel's helper function:
public function refreshCsrfToken(){
return ['csrfToken' => csrf_token()];
}
This solves the TokenMismatchException and allows the login process to proceed. The user is logged in, but the following API request to api/user to get the user info results in a 401 response:
{"error":"Unauthenticated."}
Directly trying again (by simply clicking the login button once more) does result in a succesful redirect to the user's dashboard (and thus an OK reply from /api/user)
My hunch is that the CSRF token needs to be refreshed again after the user has succesfully logged in, so I'm going to try that and alter this answer if I succeed (and report back if I don't ;) )