Following the documentation on Laravel regarding Passport authentication for the API route, i'm currently having some problems when using axois to fetch data from the api.
So far I have installed Passport through Composer, added the hasApiTokens trait, added a call to Passport::routes within the boot method of AuthServiceProvider and set the driver option of api authentication guard to 'passport'.
Since I would like the user to consume the API through Javascript from a Vue based SPA after login, I have added CreateFreshApiToken to the web middleware group.
The problem occurs when I run the following snippet to test everything out:
axios.get('api/users').then( function(response) { console.log(response.data); });
The result is a 'Failed to load resource: the server responded with a status of 401 (Unauthorized)' response.
I have checked the headers from the request sent with axois and the headers contain both
Cookie:laravel_token=eyJpdiI6ImJ5RG1KRk....
and
X-XSRF-TOKEN:eyJpdiI6IlVRRHhxSXp2VDVy...
Am i doing anything wrong?